Page MenuHomeDevCentral

D1654.diff
No OneTemporary

D1654.diff

diff --git a/roles/devserver/userland-home/files/dereckson/bin/http2pls b/roles/devserver/userland-home/files/dereckson/bin/http2pls
new file mode 100755
--- /dev/null
+++ b/roles/devserver/userland-home/files/dereckson/bin/http2pls
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+
+from bs4 import BeautifulSoup
+from urllib import request, parse
+from os import path
+from sys import argv, exit, stderr
+
+
+def get_url(base_url, tag):
+ relative_url = tag.get('href')
+ return parse.urljoin(base_url, relative_url)
+
+
+def is_media_extension(extension):
+ valid_extensions = [
+ # Videos
+ ".avi", ".flv", ".mp4", ".wmv"
+ ]
+ return extension in valid_extensions
+
+
+def is_media_link(url):
+ extension = path.splitext(url)[1]
+ return is_media_extension(extension)
+
+
+def print_pls(url):
+ links = get_media_links(url)
+
+ if not links:
+ return
+
+ print("[playlist]")
+
+ i = 0
+ for link in links:
+ i += 1
+ print('File{:d}={:s}'.format(i, link))
+
+ print("")
+ print("NumberOfEntries={:d}".format(i))
+ print("Version=2")
+
+
+def get_media_links(url):
+ return [link for link in get_links(url) if is_media_link(link)]
+
+
+def get_links(url):
+ try:
+ with request.urlopen(url) as response:
+ body = response.read()
+
+ soup = BeautifulSoup(body, 'html.parser')
+ return [get_url(url, link) for link in soup.find_all('a')]
+ except ValueError:
+ print("No valid URL: " + url, file=stderr)
+ return []
+
+
+def run():
+ if len(argv) < 2:
+ exit(1)
+
+ print_pls(argv[1])
+
+
+if __name__ == "__main__":
+ run()
diff --git a/roles/devserver/userland-software/dev.sls b/roles/devserver/userland-software/dev.sls
--- a/roles/devserver/userland-software/dev.sls
+++ b/roles/devserver/userland-software/dev.sls
@@ -83,6 +83,10 @@
pkg:
- installed
- pkgs:
+ # Modern Python 3 packages
+ - {{ packages_prefixes.python3 }}beautifulsoup
+
+ # Legacy packages
- {{ packages_prefixes.python2 }}nltk
- {{ packages_prefixes.python2 }}numpy
- {{ packages_prefixes.python2 }}virtualenv

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 2, 15:49 (13 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2275971
Default Alt Text
D1654.diff (2 KB)

Event Timeline