Initial commit
This commit is contained in:
commit
8657760b53
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# youtube-dl-subscriptions
|
||||
Downloads all new videos from your YouTube subscription feeds.
|
||||
|
||||
I recommend to create a new folder and place the dl.py inside. You will also need a OPML file named subs.xml containing all your YouTube's subscriptions in the same folder. You can download it from https://www.youtube.com/subscription_manager?action_takeout=1 when you're logged in your YouTube account. The script will create a last.txt file inside the folder in order to remember when it was last run and not re-download the same videos again.
|
||||
|
||||
Dependencies:
|
||||
* opml
|
||||
* feedparser
|
||||
* youtube-dl
|
53
dl.py
Normal file
53
dl.py
Normal file
@ -0,0 +1,53 @@
|
||||
import opml
|
||||
import feedparser
|
||||
import youtube_dl
|
||||
from glob import glob
|
||||
from pprint import pprint
|
||||
|
||||
from time import time, mktime, strptime
|
||||
from datetime import datetime
|
||||
|
||||
if len(glob('last.txt')) == 0:
|
||||
f = open('last.txt', 'w')
|
||||
f.write(str(time()))
|
||||
print('Initialized a last.txt file with current timestamp.')
|
||||
f.close()
|
||||
|
||||
else:
|
||||
f = open('last.txt', 'r')
|
||||
content = f.read()
|
||||
f.close()
|
||||
|
||||
outline = opml.parse('subs.xml')
|
||||
|
||||
ptime = datetime.utcfromtimestamp(float(content))
|
||||
ftime = time()
|
||||
|
||||
urls = []
|
||||
|
||||
for i in range(0,len(outline[0])):
|
||||
urls.append(outline[0][i].xmlUrl)
|
||||
|
||||
videos = []
|
||||
for i in range(0,len(urls)):
|
||||
print('Parsing through channel '+str(i+1)+' out of '+str(len(urls)), end='\r')
|
||||
feed = feedparser.parse(urls[i])
|
||||
for j in range(0,len(feed['items'])):
|
||||
timef = feed['items'][j]['published_parsed']
|
||||
dt = datetime.fromtimestamp(mktime(timef))
|
||||
if dt > ptime:
|
||||
videos.append(feed['items'][j]['link'])
|
||||
|
||||
if len(videos) == 0:
|
||||
print('Sorry, no new video found')
|
||||
else:
|
||||
print(str(len(videos))+' new videos found')
|
||||
|
||||
ydl_opts = {}
|
||||
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download(videos)
|
||||
|
||||
f = open('last.txt', 'w')
|
||||
f.write(str(ftime))
|
||||
f.close()
|
Reference in New Issue
Block a user