-
Notifications
You must be signed in to change notification settings - Fork 0
/
vidData.py
77 lines (65 loc) · 2.5 KB
/
vidData.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from pytube import Playlist
from pytube import YouTube
from datetime import date
import json
def populateData(list: list, playlist: Playlist):
videos = playlist.videos
for vid in videos:
title = "unknown"
version = "unknown"
epNum = -1
epDate = vid.publish_date.strftime("%m/%d/%y")
print(epDate)
duration = vid.length
url = vid.embed_url
#Used a lot
vidName = vid.title.lower()
# Find our title:
#If we find a [, save the index of it and find the title that way
if (idx := vidName.find("[")) != -1:
title = vid.title[idx+1:vidName.find("]", idx)]
# Find our version:
if("repentance" in vidName):
#repentance
version = "repentance"
elif("afterbirth" in vidName):
if("afterbirth+" in vidName):
version = "afterbirth+"
#AB+
else:
version = "afterbirth"
#AB
elif("antibirth" in vidName):
#antibirth
version = "antibirth"
else:
#rebirth
version = "rebirth"
# Find our episode number:
vidName = vidName.replace(":", "")
vidName = vidName.replace("-", "")
if(len(numbers := [s for s in vidName.split() if s.isdigit()]) != 1):
#Could occur if there is no episode number in title, or if a number is somewhere else
print("Problem Reading Ep # of Episode: " + vidName)
else:
epNum = numbers[0]
tempData = {"title": title, "version": version, "epNum": epNum, "date": epDate, "duration": duration, "urL":url}
list.append(tempData)
rebirthPlaylist = Playlist("https://www.youtube.com/playlist?list=PL1O4GjhJgk43b5B8zyOykepr6PCWo6xBq")
antibirthPlaylist = Playlist("https://www.youtube.com/playlist?list=PL1O4GjhJgk43m7oAkq8kDyVIenUwPohc4")
afterbirthPlaylist = Playlist("https://www.youtube.com/playlist?list=PL1bauNEiHIgxMmZpra5SAuzqr0yyPwNI2")
abplusRepentancePlaylist = Playlist("https://www.youtube.com/playlist?list=PL1bauNEiHIgwWzA2cOTeTW-nZeWsH7JPH")
vidData = []
with open('json/vid_data.json', 'r') as file:
vidData = json.load(file)
file.close()
try:
populateData(vidData, abplusRepentancePlaylist)
except:
print("Failure!")
with open('json/vid_data.json', 'w') as file:
json.dump(vidData, file)
file.close()
with open('json/vid_data.json', 'w') as file:
json.dump(vidData, file)
file.close()