-
Notifications
You must be signed in to change notification settings - Fork 23
/
dl.py
59 lines (45 loc) · 1.43 KB
/
dl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import opml
import feedparser
import youtube_dl
import sys
from glob import glob
from pprint import pprint
if sys.version_info[0] < 3:
raise Exception('Must be using Python 3')
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 = {'ignoreerrors': True}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(videos)
f = open('last.txt', 'w')
f.write(str(ftime))
f.close()