Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3815395
D1654.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D1654.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 02:39 (18 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2275971
Default Alt Text
D1654.diff (2 KB)
Attached To
Mode
D1654: Deploy for dereckson a playlist generator script on devserver
Attached
Detach File
Event Timeline
Log In to Comment