-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
67 lines (59 loc) · 1.84 KB
/
server.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
from flask import Flask, render_template, request
from anilist.client import AniListClient
from json import dumps
import datetime
client = AniListClient()
app = Flask(__name__, static_folder='assets')
def get_season():
month = datetime.datetime.now().month
if month < 4:
return "winter"
if month < 7:
return "spring"
if month < 10:
return "summer"
return "fall"
@app.route('/')
def home():
return render_template('index.html')
@app.route('/airing')
def get_airing():
status, res = client.browse({
"status": "Currently Airing",
"full_page": "true",
"airing_data": "true",
"season": get_season()
})
if status == 200:
return dumps(res)
return None
from nyaaclient import NyaaClient
nyaac = NyaaClient()
@app.route('/anime/<id>')
def anime(id):
res, anime = client.anime_page({ "id": id })
if res != 200:
return dumps([])
return dumps(anime)
@app.route('/anime/<id>/torrents')
def torrents(id):
res, anime = client.anime_page({ "id": id })
if res != 200:
return dumps([])
titles = [anime.get('title_' + lang, None) for lang in ['romaji', 'japanese', 'english']]
titles = [title for title in titles if title != None] + anime.get('synonyms', [])
torrents = {}
for title in titles:
try:
results = [nf.__dict__ for nf in nyaac.search(title)]
for i, r in enumerate(results):
results[i]['published'] = results[i]['published'].isoformat()
torrents[results[i]['link']] = results[i]
except:
pass
torrent_sort = lambda t: (t.get('group', ''), t.get('episode', 0), t.get('quality', 0))
torrents = sorted(torrents.values(), key=torrent_sort)
return dumps(torrents)
if __name__ == '__main__':
app.debug = True
app.run(port=8080)