-
Notifications
You must be signed in to change notification settings - Fork 4
/
egybest_api.py
89 lines (76 loc) · 2.27 KB
/
egybest_api.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
from fastapi import FastAPI
from typing import Optional
from b64 import Tag64
from base64 import b64encode
from egy_best import (
Site,
Actor,
Home,
Serie,
Movie,
Season,
Episode
)
app = FastAPI()
session = Site()
@app.get("/")
def read_root():
return {"error": "NO!"}
@app.get("/search")
def search(q: str):
resutls = session.search(q)
content = dict()
for i, r in enumerate(resutls):
info = r.get_thumbnail_info()
# info['thumbnail'] = Tag64(f"https:{info['thumbnail']}", 'img').html_tag
info['type'] = r.page_type
info['url'] = r.link
if r.page_type == 'series':
info['seasons'] = f'/seasons?url={r.link}'
else:
info['downloadinfo'] = f'/downloadinfo?url={r.link}'
content.update({i: info})
return content
@app.get("/filter/{material}")
def filter(material, q):
# return session.supported
if material in session.supported:
rs = session.filter(material, q.split('-'))
if rs:
content = dict()
for i, r in enumerate(rs):
info = r.get_thumbnail_info()
info['type'] = r.page_type
info['url'] = r.link
if r.page_type == 'series':
info['seasons'] = f'/seasons?url={r.link}'
else:
info['downloadinfo'] = f'/downloadinfo?url={r.link}'
content.update({i: info})
return content
return {'error': 'Nothing Has Been Found'}
@app.get("/seasons")
def seasons(url: str):
return {n:
{'title': s.title, 'url': s.link, 'episodes': f'/episodes?url={s.link}', 'thumbnail': s.thumbnail}
for n, s in enumerate(Serie(url).seasons)}
@app.get("/episodes")
def episodes(url: str):
return {n:
{
'url': s.link,
'title': s.title,
'thumbnail': s.thumbnail,
'downloadinfo': f'/downloadinfo?url={s.link}'
} for n, s in enumerate(Season(url).episodes)}
@app.get('/downloadinfo')
def download(url: str):
if 'episode' in url:
c = Episode
elif 'movie' in url:
c = Movie
ob = c(url)
rr = ob.get_source_link()
if rr:
return rr
return {'error': 'Bad Usage'}