Skip to content

Instantly share code, notes, and snippets.

@leafhy
Forked from EnigmaCurry/archive_podcast.py
Last active December 12, 2019 23:17
Show Gist options
  • Save leafhy/b68475d931f556dd07751719fd98d341 to your computer and use it in GitHub Desktop.
Save leafhy/b68475d931f556dd07751719fd98d341 to your computer and use it in GitHub Desktop.
Basic podcast archiving script
"""Convert podcast feeds into an aria2 download script
- Setup feed output directories and URLS
- Run: python archive_podcast.py > aria2.txt
- Run: aria2c -i aria2.txt
Aria2 will download all the episodes and supports resuming of partial downloads
"""
import feedparser
import dateutil.parser
import os
def feed_to_aria(feed, output_dir, filename_format="{date}_{entry.title}.mp3"):
print("# Aria2 download script")
print("# download via: ")
print("# aria2c -i {name of this file}")
try:
os.makedirs(output_dir)
except:
pass
rss = feedparser.parse(feed)
for entry in reversed(rss.entries):
date = dateutil.parser.parse(entry.published).strftime("%Y-%m-%d")
path = os.path.join(output_dir, filename_format.format(date=date, entry=entry))
try:
enclosure = [l for l in entry.links if l['rel'] == 'enclosure'][0]['href']
except:
print("Could not find enclosure link for: {}".format(path))
raise
print(enclosure)
print(" out={}".format(path))
print(" continue")
if __name__ == "__main__":
feeds = [
("path/to/feed1","http://example.com/feed/1"),
("path/to/feed2","http://example.com/feed/2"),
("path/to/feed3","http://example.com/feed/3")
]
for name, feed_url in feeds:
feed_to_aria(feed_url, name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment