-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel_processor.py
55 lines (45 loc) · 1.54 KB
/
channel_processor.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
import os
import googleapiclient.discovery
import googleapiclient.errors
# Parses the channels list and prints an env var containing all the upload playlists from youtube
API_KEY = os.environ["YOUTUBE_API_KEY"]
def main():
channels_text = open("utils/youtube_channels_list.txt").read()
channels = []
playlists = []
i = 0
for line in channels_text.splitlines():
if line.endswith("?"):
continue
if line == "==playlists==":
i = 1
try:
id = line.split("#")[1].strip()
if i == 0:
channels.append(id)
elif i == 1:
playlists.append(id)
except:
pass
youtube = googleapiclient.discovery.build(
"youtube", "v3", developerKey=API_KEY)
upload_playlists = []
for channel in channels[1:]:
try:
request = youtube.channels().list(part="contentDetails", id=channel)
response = request.execute()
uploads_id = response["items"][0]["contentDetails"]["relatedPlaylists"][
"uploads"
]
except:
request = youtube.channels().list(
part="contentDetails", forUsername=channel
)
response = request.execute()
uploads_id = response["items"][0]["contentDetails"]["relatedPlaylists"][
"uploads"
]
upload_playlists.append(uploads_id)
print("YOUTUBE_CHANNEL_IDS=" + ";".join(upload_playlists + playlists))
if __name__ == "__main__":
main()