-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcheck-episodes.py
executable file
·68 lines (43 loc) · 1.63 KB
/
check-episodes.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
#!/usr/bin/env python3
import requests
import json
from time import sleep
from pprint import pprint
from alive_progress import alive_bar
ENDPOINT = 'https://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v='
def pull_episode(video_id):
""" Pull the json detials of a specific episode """
path = ENDPOINT + video_id
return requests.get(path)
def load_seasons_file():
""" Load the episodes file """
handle = open('static/episodes.json', 'r')
contents = handle.read()
handle.close()
return json.loads(contents)
def count_episodes(seasons):
""" Return the total number of episodes """
count = 0
for season in seasons:
count += len(season['episodes'])
return count
def check_episodes(seasons):
""" Check for broken episodes within each season """
ep_count = count_episodes(seasons)
# Run the visual bar chart
with alive_bar(ep_count, spinner='dots_reverse') as bar:
for season in seasons:
for episode in season['episodes']:
# Skip if no youtube video defined
if not episode['vid']:
continue
# Load json
video_details = pull_episode(episode['vid'])
if video_details.status_code != 200:
print(f"{episode['title']}\t\t{episode['date']}\t\t{episode['vid']}")
bar()
sleep(1)
if __name__ == '__main__':
print('Checking for broken episodes...')
seasons = load_seasons_file()
check_episodes(seasons)