-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorrent_verification.py
79 lines (74 loc) · 2.56 KB
/
torrent_verification.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
import re, time
from pynyaasi.nyaasi import NyaaSiClient
import alfetcher
import requests
from spscraper import load_cache
missing_entries = []
unknown_errors = []
def verify_torrent(anime, torrents_local):
def append_prefix(epNumber):
if epNumber < 10:
return '0' + str(epNumber)
else:
return str(epNumber)
global missing_entries
client = NyaaSiClient()
exceptions = {
'[-KS-] My Hero Academia (Boku no Hero Academia) S5 - 01 [1080p] [Dual Audio] [CC] [FUNimation] [D822D670]': 89
}
default_timeout = 60
while True:
try:
init_resource = client.get_resource(int(torrents_local[0][len('https://nyaa.si/view/'):])).title
break
except:
time.sleep(default_timeout)
default_timeout += 5
try:
init_ep = int(re.search(r"- (\d\d\d\d|\d\d\d|\d\d)", init_resource).group(1))
except Exception as e:
return # Skip when an anime has a first episode unconventional (SP, OVA...) or if its a movie, we dont need to check those
if init_resource in exceptions:
init_ep = exceptions[init_resource]
expected_ep = init_ep + 1
for x in range(1, len(torrents_local)):
torrent = torrents_local[x]
while True:
try:
resource = client.get_resource(int(torrent[len('https://nyaa.si/view/'):])).title
break
except requests.exceptions.HTTPError as e:
time.sleep(default_timeout)
default_timeout += 5
print(e)
except Exception as e:
unknown_errors.append(torrent)
print(e)
return
if not ('- ' + append_prefix(expected_ep)) in resource:
missing_entries.append(f'missing ep: {expected_ep}, {anime}')
expected_ep += 1
def verify_torrents():
# Load cache
cache = load_cache()
# List of IDs to skip
skip_list_ids = [
'132096',
'135939',
'122148'
]
for anime in cache:
anime_info = alfetcher.get_anime_info(anime)[anime]
if anime not in skip_list_ids and anime_info['status'] == 'RELEASING':
print(f'verifying {anime}')
anime_links = cache[anime]['nyaasi_links']
verify_torrent(anime, anime_links)
verify_torrents()
if missing_entries or unknown_errors:
if missing_entries:
for entry in missing_entries:
print(entry+'\n')
if unknown_errors:
for error in unknown_errors:
print(error+'\n')
exit(1)