-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
99 lines (78 loc) · 2.35 KB
/
code.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import requests, time, json
import webbrowser
from selenium import webdriver
URL = {
'M_URL' : "https://www.youtube.com/playlist?list=PLqLu_Fx0uieHjlT21DeCjlL_YMnFVKOsC",
'T_URL' : "https://www.youtube.com/playlist?list=PLqLu_Fx0uieGh66chFLg-_exltlbjC-c7",
'E_URL' : "https://www.youtube.com/playlist?list=PLqLu_Fx0uieEGpsqV5B5Bcinm_Bhvh3aI",
'H_URL' : "https://www.youtube.com/playlist?list=PLqLu_Fx0uieG3ZflewYgXb2x2VoE28aVm"
}
'''tracks = {
'M' : {
'tracks' :[],
'deleted' :[]
},
'T' : {
'tracks' :[],
'deleted' :[]
},
'E' : {
'tracks' :[],
'deleted' :[]
},
'H' : {
'tracks' :[],
'deleted' :[]
}
}
'''
def update(deleted_langs):
HTML = """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>List of Deleted Videos</title>
</head>
<body>"""
for lang in deleted_langs:
HTML+=time.ctime()
HTML+="<h1>"+lang+"</h1>"
for title in tracks[lang[0]]['deleted']:
HTML+= title+"<br>"
HTML+="""</body>
</html>"""
ht = open("deleted list.html", "w")
ht.write(HTML)
ht.close()
webbrowser.open("deleted list.html")
browser = webdriver.Firefox()
in_file = open('data.json', 'r', encoding='UTF-8')
tracks = json.load(in_file)
flag = 0
for lang,url in URL.items():
browser.get(url)
vids = browser.find_elements_by_id('video-title')
del_list = tracks[lang[0]]['deleted']
deleted_langs = []
for vid in vids:
d={}
d['name'] = vid.text
d['link'] = vid.get_attribute('href').split('&')[0]
if d['name'] == '[Deleted video]':
for item in tracks[lang[0]]['tracks']:
if item['link'] == d['link']:
del_name = item['name']
break
if del_name not in tracks[lang[0]]['deleted']:
tracks[lang[0]]['deleted'].append(del_name)
# flag = 1
deleted_langs.append(lang[0])
update(deleted_langs)
continue
if d not in tracks[lang[0]]['tracks']:
tracks[lang[:1]]['tracks'].append(d)
browser.close()
out_file = open('data.json', 'w')
json.dump(tracks, out_file, indent=5)
out_file.close()