SoulofSukuna commited on
Commit
42d523e
·
verified ·
1 Parent(s): 2fa1c96

Update routers/v1/combo_routers.py

Browse files
Files changed (1) hide show
  1. 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
- for site in sites_list:
22
- limit = (
23
- all_sites[site]["limit"]
24
- if limit == 0 or limit > all_sites[site]["limit"]
25
- else limit
26
- )
27
- tasks.append(
28
- asyncio.create_task(
29
- all_sites[site]["website"]().search(query, page=1, limit=limit)
30
- )
31
- )
32
- results = await asyncio.gather(*tasks)
33
- for res in results:
34
- if res is not None and len(res["data"]) > 0:
35
- for torrent in res["data"]:
36
- COMBO["data"].append(torrent)
37
- total_torrents_overall = total_torrents_overall + res["total"]
38
- COMBO["time"] = time.time() - start_time
39
- COMBO["total"] = total_torrents_overall
40
- if total_torrents_overall == 0:
41
- return error_handler(
42
- status_code=status.HTTP_404_NOT_FOUND,
43
- json_message={"error": "Result not found."},
44
- )
45
- return COMBO
46
-
47
-
48
- @router.get("/trending")
49
- async def get_all_trending(limit: Optional[int] = 0):
50
- start_time = time.time()
51
- # * just getting all_sites dictionary
52
- all_sites = check_if_site_available("1337x")
53
- sites_list = [
54
- site
55
- for site in all_sites.keys()
56
- if all_sites[site]["trending_available"] and all_sites[site]["website"]
57
- ]
58
- tasks = []
59
- COMBO = {"data": []}
60
- total_torrents_overall = 0
61
- for site in sites_list:
62
- limit = (
63
- all_sites[site]["limit"]
64
- if limit == 0 or limit > all_sites[site]["limit"]
65
- else limit
66
- )
67
- tasks.append(
68
- asyncio.create_task(
69
- all_sites[site]["website"]().trending(
70
- category=None, page=1, limit=limit
71
- )
72
- )
73
- )
74
- results = await asyncio.gather(*tasks)
75
- for res in results:
76
- if res is not None and len(res["data"]) > 0:
77
- for torrent in res["data"]:
78
- COMBO["data"].append(torrent)
79
- total_torrents_overall = total_torrents_overall + res["total"]
80
- COMBO["time"] = time.time() - start_time
81
- COMBO["total"] = total_torrents_overall
82
- if total_torrents_overall == 0:
83
- return error_handler(
84
- status_code=status.HTTP_404_NOT_FOUND,
85
- json_message={"error": "Result not found."},
86
- )
87
- return COMBO
88
-
89
-
90
- @router.get("/recent")
91
- async def get_all_recent(limit: Optional[int] = 0):
92
- start_time = time.time()
93
- # just getting all_sites dictionary
94
- all_sites = check_if_site_available("1337x")
95
- sites_list = [
96
- site
97
- for site in all_sites.keys()
98
- if all_sites[site]["recent_available"] and all_sites[site]["website"]
99
- ]
100
- tasks = []
101
- COMBO = {"data": []}
102
- total_torrents_overall = 0
103
- for site in sites_list:
104
- limit = (
105
- all_sites[site]["limit"]
106
- if limit == 0 or limit > all_sites[site]["limit"]
107
- else limit
108
- )
109
- tasks.append(
110
- asyncio.create_task(
111
- all_sites[site]["website"]().recent(category=None, page=1, limit=limit)
112
- )
113
- )
114
- results = await asyncio.gather(*tasks)
115
- for res in results:
116
- if res is not None and len(res["data"]) > 0:
117
- for torrent in res["data"]:
118
- COMBO["data"].append(torrent)
119
- total_torrents_overall = total_torrents_overall + res["total"]
120
- COMBO["time"] = time.time() - start_time
121
- COMBO["total"] = total_torrents_overall
122
- if total_torrents_overall == 0:
123
- return error_handler(
124
- status_code=status.HTTP_404_NOT_FOUND,
125
- json_message={"error": "Result not found."},
126
- )
127
- return COMBO
 
 
 
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