Created
August 24, 2016 19:49
-
-
Save clonejo/80e75a8a5758ebd2ed71deea608cdf31 to your computer and use it in GitHub Desktop.
Generates an XML feed file for a directory of media files. Next you could serve the directory with a web server, subscribe to the feed in your podcatcher and download episodes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from pathlib import Path | |
import urllib.parse | |
def walk_tree(path): | |
for f in path.iterdir(): | |
if f.is_dir(): | |
yield from walk_tree(f) | |
else: | |
yield f | |
suffixes = ['.mp3', '.mp4', '.mkv', '.m4a', '.m4b', '.ogg', '.opus', '.wmv', '.avi'] | |
p = Path('.') | |
out = open('feed.xml', 'w') | |
feed_name = 'Your Feed Name' | |
base_url = 'http://192.168.0.123:8000/' | |
out.write('''\ | |
<?xml version="1.0" encoding="UTF-8" ?> | |
<rss version="2.0"> | |
<channel> | |
''') | |
out.write('<title>' + feed_name + '</title>\n') | |
for f in sorted(walk_tree(p), key=lambda x: str(x)): | |
if f.suffix in suffixes: | |
print(f) | |
out.write('<item><title>' + str(f) + '</title>') | |
# TODO: add guid to not have double entries | |
out.write('<enclosure url="' + base_url + urllib.parse.quote(str(f)) + '" /></item>\n') | |
out.write('''\ | |
</channel> | |
</rss> | |
''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment