-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_broken.py
161 lines (149 loc) · 7.1 KB
/
delete_broken.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import requests
import sqlite3
import time
import datetime
from requests.exceptions import SSLError, ConnectionError
from json.decoder import JSONDecodeError
from settings import token, nickname
def get_all_my_video(conn, pg):
c = conn.cursor()
req = 'http://shikimori.org/api/users/4193/anime_video_reports?limit=500&page={pg}'.format(pg=pg)
headers = {'X-User-Nickname': nickname,
'X-User-Api-Access-Token': token,
'content-type': 'application/json'}
response = requests.get(req, headers=headers).json()
for x in response:
c.execute('INSERT INTO all_my_videos (anime_id, \
video_id, \
url) \
VALUES (?, ?, ?)',
(x['anime_video']['anime_id'],
x['anime_video']['id'],
x['anime_video']['url']))
conn.commit()
def get_all_anime(conn):
c = conn.cursor()
anime = []
c.execute("SELECT anime_id FROM all_my_videos",)
db = c.fetchall()
for x in db:
anime.append(x[0])
for x in set(anime):
c.execute('INSERT INTO all_anime(anime_id) VALUES (?)', (x,))
conn.commit()
return set(anime)
def get_duration(conn):
c = conn.cursor()
headers = {'X-User-Nickname': nickname,
'X-User-Api-Access-Token': token,
'content-type': 'application/json'}
c.execute("SELECT anime_id FROM all_anime",)
db = c.fetchall()
for x in db:
req = 'https://shikimori.org/api/animes/{anime_id}'.format(anime_id=x[0])
response = requests.get(req, headers=headers).json()
c.execute('UPDATE all_my_videos SET ep_duration=? WHERE anime_id=?', (response['duration'], x[0]))
print(x[0])
conn.commit()
c.execute('DELETE FROM all_anime WHERE anime_id=?', (x[0],))
time.sleep(0.7)
def get_kind(conn):
c = conn.cursor()
headers = {'X-User-Nickname': nickname,
'X-User-Api-Access-Token': token,
'content-type': 'application/json'}
c.execute("SELECT anime_id FROM all_my_videos WHERE check_anime='FALSE'",)
x = c.fetchone()
req = 'https://shikimori.org/api/animes/{anime_id}'.format(anime_id=x[0])
response = requests.get(req, headers=headers).json()
c.execute("UPDATE all_my_videos SET kind=?, check_anime='TRUE' WHERE anime_id=?", (response['kind'], x[0]))
print(x[0])
conn.commit()
def delete_video(conn):
c = conn.cursor()
headers = {'X-User-Nickname': nickname,
'X-User-Api-Access-Token': token,
'content-type': 'application/json'}
c.execute("SELECT url, anime_id, video_id, ep_duration, kind FROM all_my_videos WHERE check_anime='FALSE'")
db = c.fetchall()
for x in db:
try:
req = x[0].replace('smotret-anime.ru/translations/embed/', 'smotret-anime.ru/api/translations/')
resp = requests.get(req).json()
r = 'ok'
allow_type = ['tv', 'ova', 'ona', 'movie', 'special']
if 'error' in resp:
time.sleep(0.7)
r = requests.delete('http://shikimori.org/api/animes/{anime_id}/anime_videos/{video_id}'
.format(anime_id=x[1], video_id=x[2]), headers=headers).text
c.execute('INSERT INTO delete_broken (anime_id, \
video_id, \
url) \
VALUES (?, ?, ?)',
(x[1],
x[2],
x[0]))
elif resp['data']['episode'] is None:
time.sleep(0.7)
r = requests.delete('http://shikimori.org/api/animes/{anime_id}/anime_videos/{video_id}'
.format(anime_id=x[1], video_id=x[2]), headers=headers).text
c.execute('INSERT INTO delete_broken (anime_id, \
video_id, \
url) \
VALUES (?, ?, ?)',
(x[1],
x[2],
x[0]))
elif resp['data']['episode']['episodeType'] not in allow_type:
time.sleep(0.7)
r = requests.delete('http://shikimori.org/api/animes/{anime_id}/anime_videos/{video_id}'
.format(anime_id=x[1], video_id=x[2]), headers=headers).text
c.execute('INSERT INTO delete_broken (anime_id, \
video_id, \
url) \
VALUES (?, ?, ?)',
(x[1],
x[2],
x[0]))
elif resp['data']['duration'] != '0' and x[3] != 0:
if float(resp['data']['duration']) < ((x[3]*60)-((x[3]*60)/3)):
time.sleep(0.7)
r = requests.delete('http://shikimori.org/api/animes/{anime_id}/anime_videos/{video_id}'
.format(anime_id=x[1], video_id=x[2]), headers=headers).text
c.execute('INSERT INTO delete_broken (anime_id, \
video_id, \
url) \
VALUES (?, ?, ?)',
(x[1],
x[2],
x[0]))
elif resp['data']['isActive'] != 1:
time.sleep(0.7)
r = requests.delete('http://shikimori.org/api/animes/{anime_id}/anime_videos/{video_id}'
.format(anime_id=x[1], video_id=x[2]), headers=headers).text
c.execute('INSERT INTO delete_broken (anime_id, \
video_id, \
url) \
VALUES (?, ?, ?)',
(x[1],
x[2],
x[0]))
elif resp['data']['episode']['episodeType'] != x[4]:
time.sleep(0.7)
r = requests.delete('http://shikimori.org/api/animes/{anime_id}/anime_videos/{video_id}'
.format(anime_id=x[1], video_id=x[2]), headers=headers).text
c.execute('INSERT INTO delete_broken (anime_id, \
video_id, \
url) \
VALUES (?, ?, ?)',
(x[1],
x[2],
x[0]))
c.execute("UPDATE all_my_videos SET check_anime='TRUE' WHERE video_id=?", (x[2],))
conn.commit()
print(r, datetime.datetime.now())
except (SSLError, ConnectionError, JSONDecodeError):
delete_video(conn)
if __name__ == '__main__':
con = sqlite3.connect('anime365.db')
delete_video(con)