Spaces:
Sleeping
Sleeping
SoulofSukuna
commited on
Update routers/v1/combo_routers.py
Browse files- routers/v1/combo_routers.py +129 -127
routers/v1/combo_routers.py
CHANGED
@@ -1,127 +1,129 @@
|
|
1 |
-
from fastapi import APIRouter, status
|
2 |
-
from typing import Optional
|
3 |
-
from helper.is_site_available import check_if_site_available
|
4 |
-
import time
|
5 |
-
import asyncio
|
6 |
-
from helper.error_messages import error_handler
|
7 |
-
|
8 |
-
|
9 |
-
router = APIRouter(tags=["Combo Routes"])
|
10 |
-
|
11 |
-
|
12 |
-
@router.get("/search")
|
13 |
-
async def get_search_combo(query: str, limit: Optional[int] = 0):
|
14 |
-
start_time = time.time()
|
15 |
-
query = query.lower()
|
16 |
-
all_sites = check_if_site_available("1337x")
|
17 |
-
sites_list = list(all_sites.keys())
|
18 |
-
tasks = []
|
19 |
-
COMBO = {"data": []}
|
20 |
-
total_torrents_overall = 0
|
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 |
-
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, status
|
2 |
+
from typing import Optional
|
3 |
+
from helper.is_site_available import check_if_site_available
|
4 |
+
import time
|
5 |
+
import asyncio
|
6 |
+
from helper.error_messages import error_handler
|
7 |
+
|
8 |
+
|
9 |
+
router = APIRouter(tags=["Combo Routes"])
|
10 |
+
|
11 |
+
|
12 |
+
@router.get("/search")
|
13 |
+
async def get_search_combo(query: str, limit: Optional[int] = 0):
|
14 |
+
start_time = time.time()
|
15 |
+
query = query.lower()
|
16 |
+
all_sites = check_if_site_available("1337x")
|
17 |
+
sites_list = list(all_sites.keys())
|
18 |
+
tasks = []
|
19 |
+
COMBO = {"data": []}
|
20 |
+
total_torrents_overall = 0
|
21 |
+
ignoresites = ["glodls", "ybt", "tgx"]
|
22 |
+
for site in sites_list:
|
23 |
+
if site not in ignoresites:
|
24 |
+
limit = (
|
25 |
+
all_sites[site]["limit"]
|
26 |
+
if limit == 0 or limit > all_sites[site]["limit"]
|
27 |
+
else limit
|
28 |
+
)
|
29 |
+
tasks.append(
|
30 |
+
asyncio.create_task(
|
31 |
+
all_sites[site]["website"]().search(query, page=1, limit=limit)
|
32 |
+
)
|
33 |
+
)
|
34 |
+
results = await asyncio.gather(*tasks)
|
35 |
+
for res in results:
|
36 |
+
if res is not None and len(res["data"]) > 0:
|
37 |
+
for torrent in res["data"]:
|
38 |
+
COMBO["data"].append(torrent)
|
39 |
+
total_torrents_overall = total_torrents_overall + res["total"]
|
40 |
+
COMBO["time"] = time.time() - start_time
|
41 |
+
COMBO["total"] = total_torrents_overall
|
42 |
+
if total_torrents_overall == 0:
|
43 |
+
return error_handler(
|
44 |
+
status_code=status.HTTP_404_NOT_FOUND,
|
45 |
+
json_message={"error": "Result not found."},
|
46 |
+
)
|
47 |
+
return COMBO
|
48 |
+
|
49 |
+
|
50 |
+
@router.get("/trending")
|
51 |
+
async def get_all_trending(limit: Optional[int] = 0):
|
52 |
+
start_time = time.time()
|
53 |
+
# * just getting all_sites dictionary
|
54 |
+
all_sites = check_if_site_available("1337x")
|
55 |
+
sites_list = [
|
56 |
+
site
|
57 |
+
for site in all_sites.keys()
|
58 |
+
if all_sites[site]["trending_available"] and all_sites[site]["website"]
|
59 |
+
]
|
60 |
+
tasks = []
|
61 |
+
COMBO = {"data": []}
|
62 |
+
total_torrents_overall = 0
|
63 |
+
for site in sites_list:
|
64 |
+
limit = (
|
65 |
+
all_sites[site]["limit"]
|
66 |
+
if limit == 0 or limit > all_sites[site]["limit"]
|
67 |
+
else limit
|
68 |
+
)
|
69 |
+
tasks.append(
|
70 |
+
asyncio.create_task(
|
71 |
+
all_sites[site]["website"]().trending(
|
72 |
+
category=None, page=1, limit=limit
|
73 |
+
)
|
74 |
+
)
|
75 |
+
)
|
76 |
+
results = await asyncio.gather(*tasks)
|
77 |
+
for res in results:
|
78 |
+
if res is not None and len(res["data"]) > 0:
|
79 |
+
for torrent in res["data"]:
|
80 |
+
COMBO["data"].append(torrent)
|
81 |
+
total_torrents_overall = total_torrents_overall + res["total"]
|
82 |
+
COMBO["time"] = time.time() - start_time
|
83 |
+
COMBO["total"] = total_torrents_overall
|
84 |
+
if total_torrents_overall == 0:
|
85 |
+
return error_handler(
|
86 |
+
status_code=status.HTTP_404_NOT_FOUND,
|
87 |
+
json_message={"error": "Result not found."},
|
88 |
+
)
|
89 |
+
return COMBO
|
90 |
+
|
91 |
+
|
92 |
+
@router.get("/recent")
|
93 |
+
async def get_all_recent(limit: Optional[int] = 0):
|
94 |
+
start_time = time.time()
|
95 |
+
# just getting all_sites dictionary
|
96 |
+
all_sites = check_if_site_available("1337x")
|
97 |
+
sites_list = [
|
98 |
+
site
|
99 |
+
for site in all_sites.keys()
|
100 |
+
if all_sites[site]["recent_available"] and all_sites[site]["website"]
|
101 |
+
]
|
102 |
+
tasks = []
|
103 |
+
COMBO = {"data": []}
|
104 |
+
total_torrents_overall = 0
|
105 |
+
for site in sites_list:
|
106 |
+
limit = (
|
107 |
+
all_sites[site]["limit"]
|
108 |
+
if limit == 0 or limit > all_sites[site]["limit"]
|
109 |
+
else limit
|
110 |
+
)
|
111 |
+
tasks.append(
|
112 |
+
asyncio.create_task(
|
113 |
+
all_sites[site]["website"]().recent(category=None, page=1, limit=limit)
|
114 |
+
)
|
115 |
+
)
|
116 |
+
results = await asyncio.gather(*tasks)
|
117 |
+
for res in results:
|
118 |
+
if res is not None and len(res["data"]) > 0:
|
119 |
+
for torrent in res["data"]:
|
120 |
+
COMBO["data"].append(torrent)
|
121 |
+
total_torrents_overall = total_torrents_overall + res["total"]
|
122 |
+
COMBO["time"] = time.time() - start_time
|
123 |
+
COMBO["total"] = total_torrents_overall
|
124 |
+
if total_torrents_overall == 0:
|
125 |
+
return error_handler(
|
126 |
+
status_code=status.HTTP_404_NOT_FOUND,
|
127 |
+
json_message={"error": "Result not found."},
|
128 |
+
)
|
129 |
+
return COMBO
|