-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanime365.py
206 lines (190 loc) · 7.36 KB
/
anime365.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import urllib.request
import urllib.parse
import urllib
import json
import time
import requests
from settings import token, nickname
USER_AGENT = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
def get_recent_translations_json():
print('get_recent_translations_json')
req = "https://smotret-anime.ru/api/translations/?"
data = urllib.parse.urlencode({
'feed': 'recent',
'pretty': '1',
# 'limit': '1000'
})
binary_data = data.encode('utf8')
req2 = urllib.request.Request(req, headers=USER_AGENT)
param = urllib.request.urlopen(req2, binary_data)
return json.loads(param.read().decode())['data']
def add_to_db(translations, conn):
c = conn.cursor()
c.execute('INSERT INTO recent_translations (mal_id, \
typeKind, \
typeLang,\
authorsSummary,\
url,\
episodeInt, \
anime365_id, \
uploaded, \
qualityType) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
(translations['series']['myAnimeListId'],
translations['typeKind'],
translations['typeLang'],
translations['authorsSummary'],
translations['url'],
translations['episode']['episodeInt'],
translations['id'],
0,
translations['qualityType']))
conn.commit()
def get_recent_translations(conn):
print('get_recent_translations')
c = conn.cursor()
allow_type = ['tv', 'ova', 'ona', 'movie', 'special']
headers = {'X-User-Nickname': nickname,
'X-User-Api-Access-Token': token,
'content-type': 'application/json'}
for translations in get_recent_translations_json():
c.execute("SELECT * \
FROM recent_translations \
WHERE (anime365_id LIKE ?)", (translations['id'],))
db = c.fetchall()
if len(db) > 0:
pass
else:
time.sleep(1)
print('test')
req = 'https://shikimori.org/api/animes/{anime_id}'.format(anime_id=translations['series']['myAnimeListId'])
response = requests.get(req, headers=headers).json()
# print(translations['id'])
# print(int(float(translations['episode']['episodeInt'])))
if response.get('code', 200) == 404:
print('error 404')
# continue
elif translations['isActive'] == -1:
print('isActive -1')
elif translations['isActive'] == 0:
print('isActive 0')
elif translations['isActive'] == '0':
print('isActive 0')
elif translations['episode']['episodeInt'] == '':
print('episode')
elif translations['episode']['episodeInt'] == '0':
print('episode #0')
elif float(translations['episode']['episodeInt']) / int(float(translations['episode']['episodeInt'])) != 1:
print('дробный эпизод')
elif translations['series']['myAnimeListId'] == 0:
print('MAL id')
elif translations['typeKind'] == '':
print('Typekind')
elif translations['typeLang'] == '':
print('typelang')
elif translations['episode']['episodeType'] not in allow_type:
print('allow_type')
elif response['anons']:
print('anons')
elif response['episodes'] != 0 and response['episodes'] < int(float(translations['episode']['episodeInt'])):
print('episodes')
print(response['episodes'], int(float(translations['episode']['episodeInt'])))
elif response['episodes_aired'] + 4 < int(translations['episode']['episodeInt']) \
and response['episodes_aired'] != 0:
print('episodes_aired')
print(response['episodes_aired'], int(translations['episode']['episodeInt']))
print(translations['series']['myAnimeListId'])
elif response['kind'] != translations['episode']['episodeType']:
print('kind')
else:
if translations['duration'] != '0' and response['duration'] != 0:
if float(translations['duration']) < (
(response['duration'] * 60) - ((response['duration'] * 60) / 3)):
print('duration')
else:
add_to_db(translations, conn)
else:
add_to_db(translations, conn)
def post_video_shiki(anime_id,
author_name,
episode,
kind,
language,
source,
url,
conn,
quality_type):
print('post_video_shiki')
if kind == 'sub':
kind = 'subtitles'
elif kind == 'raw':
kind = 'raw'
elif kind == 'voice':
kind = 'fandub'
elif kind == '':
kind = 'unknown'
if language == 'ru':
language = 'russian'
elif language == 'en':
language = 'english'
elif language == 'jp':
language = 'original'
elif language == '':
language = 'unknown'
else:
language = 'unknown'
if quality_type == 'tv':
quality_type = 'tv'
elif quality_type == 'bd':
quality_type = 'bd'
elif quality_type == 'dvd':
quality_type = 'dvd'
else:
quality_type = 'unknown'
c = conn.cursor()
link = 'https://shikimori.org/api/animes/{id}/anime_videos'
req = link.format(id=anime_id)
# req = 'https://httpbin.org/post'
anime_video = {'anime_id': int(anime_id),
"state": "uploaded",
'author_name': str(author_name),
'episode': int(episode),
'kind': str(kind),
'language': str(language),
'source': str(source),
'url': str(url),
'quality': str(quality_type)}
data = {'anime_video': anime_video}
headers = {'X-User-Nickname': nickname,
'X-User-Api-Access-Token': token,
'content-type': 'application/json'}
param = requests.post(req, data=json.dumps(data), headers=headers)
c.execute('UPDATE recent_translations \
SET uploaded=? WHERE url=?', (1, url))
conn.commit()
print(param.text)
return param.text
def prepare_video_shiki(conn):
print('prepare_video_shiki')
c = conn.cursor()
db = []
c.execute("SELECT * FROM recent_translations \
WHERE (uploaded \
LIKE {upl})".format(upl=0))
for dbd in c.fetchall():
db.append(dbd)
for x in db:
post_video_shiki(x[1],
x[4],
x[6],
x[2],
x[3],
x[5],
x[5],
conn,
x[9])
time.sleep(1)
return db
def run(conn):
get_recent_translations(conn)
prepare_video_shiki(conn)