Created
June 14, 2023 19:16
-
-
Save line72/ceef5402881d6d3ae732e7b7c9cbf01b to your computer and use it in GitHub Desktop.
This file contains 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/env python3 | |
# | |
# Download the latest feeds using youtube-dl | |
# | |
import os | |
import subprocess | |
import feedparser | |
FEED = 'https://www.youtube.com/feeds/videos.xml?channel_id=UCzCWehBejA23yEz3zp7jlcg' | |
CONFIG = os.path.join(os.path.expanduser('~'), '.config', 'youtube-feed.conf') | |
def go(): | |
last_entry = None | |
try: | |
with open(CONFIG, 'r') as f: | |
last_entry = f.read().strip() | |
except IOError: | |
pass | |
download_list = [] | |
found = False | |
most_recent = None | |
d = feedparser.parse(FEED) | |
for e in d.entries: | |
if most_recent is None: | |
most_recent = e.id | |
if e.id == last_entry: | |
found = True | |
break | |
else: | |
download_list.append({'name': e.title, 'id': e.title, 'link': e.link, 'published': e.published}) | |
# start downloading | |
for download in download_list: | |
try: | |
subprocess.run(['yt-dlp', '-f', '251', '-x', download['link'], | |
'--add-metadata', | |
'--metadata-from-title', '(?P<artist>.+?) - (?P<title>.+)', | |
'-o', '~/Music2/%(title)s.%(ext)s'], check = True) | |
except subprocess.CalledProcessError as e: | |
print('Error downloading', download['name'], ':', e) | |
# save our state | |
with open(CONFIG, 'w') as f: | |
f.write(most_recent) | |
if __name__ == '__main__': | |
go() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment