Spaces:
Running
Running
BinaryONe
commited on
Commit
·
87159d4
1
Parent(s):
72617d0
APP-API-Endpoints Modifications -sparkdrive
Browse files- FileStream/TMDB/Endpoint.py +43 -3
- FileStream/Tools/cleanup.py +11 -2
- FileStream/server/routes_api.py +64 -5
FileStream/TMDB/Endpoint.py
CHANGED
@@ -5,11 +5,51 @@ from FileStream.Tools.cleanup import Get_Title_Year
|
|
5 |
|
6 |
def get_tvshows(tv_show_id):
|
7 |
return tv.details(tv_show_id).__dict__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
def
|
10 |
# Search for the title in TMDb
|
11 |
title, year = Get_Title_Year(name)
|
12 |
-
print("*", title, year,"\n Name :", name)
|
13 |
if title is None :
|
14 |
return None
|
15 |
search_results = search.multi(title)
|
@@ -31,7 +71,7 @@ def search_tmdb(name):
|
|
31 |
return result
|
32 |
|
33 |
except Exception as e :
|
34 |
-
|
35 |
return None
|
36 |
|
37 |
return None
|
|
|
5 |
|
6 |
def get_tvshows(tv_show_id):
|
7 |
return tv.details(tv_show_id).__dict__
|
8 |
+
|
9 |
+
def search_tmdb_movies(name):
|
10 |
+
# Search for the title in TMDb
|
11 |
+
title, year = Get_Title_Year(name)
|
12 |
+
#print("*", title, year,"\n Name :", name)
|
13 |
+
if title is None :
|
14 |
+
return None
|
15 |
+
search_results = search.multi(title)
|
16 |
+
# Filter results by year
|
17 |
+
try:
|
18 |
+
for result in search_results:
|
19 |
+
if result.media_type == "movie":
|
20 |
+
release_date=result.release_date or result.get("release_date") or result.get("first_air_date")
|
21 |
+
if release_date and int(release_date.split('-')[0]) == year:
|
22 |
+
return result
|
23 |
+
|
24 |
+
except Exception as e :
|
25 |
+
print("* Error at Endpoint", e, result)
|
26 |
+
return None
|
27 |
+
|
28 |
+
return None
|
29 |
+
|
30 |
+
def search_tmdb_tv(name):
|
31 |
+
# Search for the title in TMDb
|
32 |
+
title, year = Get_Title_Year(name)
|
33 |
+
#print("*", title, year,"\n Name :", name)
|
34 |
+
if title is None :
|
35 |
+
return None
|
36 |
+
search_results = search.multi(title)
|
37 |
+
# Filter results by year
|
38 |
+
try:
|
39 |
+
for result in search_results:
|
40 |
+
if result.media_type == "tv":
|
41 |
+
release_date=result.release_date or result.first_air_date or result.get("release_date") or result.get("first_air_date")
|
42 |
+
if release_date and int(release_date.split('-')[0]) == year:
|
43 |
+
return get_tvshows( result.id or result.get("id") )
|
44 |
+
except Exception as e :
|
45 |
+
print("* Error at Endpoint", e, result)
|
46 |
+
return None
|
47 |
+
return None
|
48 |
|
49 |
+
def search_tmdb_any(name):
|
50 |
# Search for the title in TMDb
|
51 |
title, year = Get_Title_Year(name)
|
52 |
+
#print("*", title, year,"\n Name :", name)
|
53 |
if title is None :
|
54 |
return None
|
55 |
search_results = search.multi(title)
|
|
|
71 |
return result
|
72 |
|
73 |
except Exception as e :
|
74 |
+
print("* Error at Endpoint", e, result)
|
75 |
return None
|
76 |
|
77 |
return None
|
FileStream/Tools/cleanup.py
CHANGED
@@ -20,6 +20,14 @@ def convert_special_to_normal(text):
|
|
20 |
text = re.sub(r'[^A-Za-z0-9 ]+', '', text)
|
21 |
return text
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def clean_text(input_text):
|
24 |
# Remove new line characters
|
25 |
text = input_text.replace('\n', '').replace('@', '')
|
@@ -43,9 +51,10 @@ def clean_text(input_text):
|
|
43 |
|
44 |
def Get_Title_Year(name):
|
45 |
# Regex to match title and year
|
46 |
-
words_to_remove = ["FC", "HEVC","ɴᴀᴍᴇ:","-","BuLMoviee" ,"𝗝𝗼𝗶𝗻 𝗨𝘀 𝗢𝗻 𝗧𝗲𝗹𝗲𝗴𝗿𝗮�","𝗝𝗼𝗶𝗻 𝗨𝘀 𝗢𝗻 𝗧𝗲𝗹𝗲𝗴𝗿𝗮𝗺","SIDHUU 591","𝑱𝒐𝒊𝒏 𝑼𝒔 𝑶ɴ 𝑻ᴇʟᴇɢʀᴀᴍ","Tɪᴛʟᴇ :"]
|
47 |
name=remove_words(name, words_to_remove)
|
48 |
match = re.search(r'(?P<title>.+?)[\s\.\(\)]*(?P<year>\d{4})',name )
|
|
|
49 |
if match:
|
50 |
-
return match.group('title').strip(), int(match.group('year'))
|
51 |
return None, None
|
|
|
20 |
text = re.sub(r'[^A-Za-z0-9 ]+', '', text)
|
21 |
return text
|
22 |
|
23 |
+
|
24 |
+
|
25 |
+
def clean_string_special(input_string):
|
26 |
+
# Define a regular expression pattern to remove special characters, including •, ▫️, etc.
|
27 |
+
# This pattern keeps only alphanumeric characters (A-Z, a-z, 0-9) and spaces.
|
28 |
+
cleaned_string = re.sub(r'[^\w\s]+', '', input_string)
|
29 |
+
return cleaned_string
|
30 |
+
|
31 |
def clean_text(input_text):
|
32 |
# Remove new line characters
|
33 |
text = input_text.replace('\n', '').replace('@', '')
|
|
|
51 |
|
52 |
def Get_Title_Year(name):
|
53 |
# Regex to match title and year
|
54 |
+
words_to_remove = ["Fɪʟᴇ ɴᴀᴍᴇ :","FC", "HEVC","ɴᴀᴍᴇ:","-","BuLMoviee" ,"𝗝𝗼𝗶𝗻 𝗨𝘀 𝗢𝗻 𝗧𝗲𝗹𝗲𝗴𝗿𝗮�","𝗝𝗼𝗶𝗻 𝗨𝘀 𝗢𝗻 𝗧𝗲𝗹𝗲𝗴𝗿𝗮𝗺","SIDHUU 591","𝑱𝒐𝒊𝒏 𝑼𝒔 𝑶ɴ 𝑻ᴇʟᴇɢʀᴀᴍ","Tɪᴛʟᴇ :","Bollywood","mkv","Mᴏᴠɪᴇ", "ɢʀᴏᴜᴘ" , "TGxMALLU_MOVIE"]
|
55 |
name=remove_words(name, words_to_remove)
|
56 |
match = re.search(r'(?P<title>.+?)[\s\.\(\)]*(?P<year>\d{4})',name )
|
57 |
+
|
58 |
if match:
|
59 |
+
return clean_string_special(match.group('title').strip()), int(match.group('year'))
|
60 |
return None, None
|
FileStream/server/routes_api.py
CHANGED
@@ -15,7 +15,7 @@ from aiohttp.http_exceptions import BadStatusLine
|
|
15 |
from FileStream.bot import req_client
|
16 |
from FileStream.config import Telegram,Server
|
17 |
from FileStream.Database import Database
|
18 |
-
from FileStream.TMDB.Endpoint import
|
19 |
from FileStream.server.exceptions import FIleNotFound, InvalidHash
|
20 |
|
21 |
from .Functions.downloader import media_streamer
|
@@ -29,6 +29,61 @@ async def list_all_files_db(request):
|
|
29 |
#print(files, type(files))
|
30 |
return web.json_response(json.loads(dumps(files)))
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
#api.router.add_get('/tmdb/list', list_all_files_tmdb)
|
34 |
async def list_all_files_tmdb(request):
|
@@ -40,10 +95,10 @@ async def list_all_files_tmdb(request):
|
|
40 |
#print(row['file']['caption'])
|
41 |
try :
|
42 |
#print("* Response",search_tmdb(row['file']['caption'] if row['file']['caption'] else row['file']['file_name']))
|
43 |
-
resp =
|
44 |
if resp != None :
|
45 |
#resp= dict(resp)
|
46 |
-
print("TMDB Response :",resp)
|
47 |
response.append(resp)
|
48 |
else:
|
49 |
print("\n * Skipped:",row['file']['caption'],str(row['file']['file_name']))
|
@@ -174,7 +229,11 @@ async def stream_handler(request: web.Request):
|
|
174 |
api = web.Application()
|
175 |
api.router.add_get('/', handle_v2)
|
176 |
api.router.add_get('/files', list_all_files_db)
|
177 |
-
api.router.add_get('/
|
178 |
-
|
|
|
|
|
|
|
|
|
179 |
api.router.add_get('/upload', upload_file)
|
180 |
api.router.add_get('/dl/{path}', stream_handler)
|
|
|
15 |
from FileStream.bot import req_client
|
16 |
from FileStream.config import Telegram,Server
|
17 |
from FileStream.Database import Database
|
18 |
+
from FileStream.TMDB.Endpoint import search_tmdb_any,search_tmdb_tv,search_tmdb_movies
|
19 |
from FileStream.server.exceptions import FIleNotFound, InvalidHash
|
20 |
|
21 |
from .Functions.downloader import media_streamer
|
|
|
29 |
#print(files, type(files))
|
30 |
return web.json_response(json.loads(dumps(files)))
|
31 |
|
32 |
+
async def list_all_tmdb_movies_from_db(request):
|
33 |
+
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
34 |
+
files= await db.get_all_files()
|
35 |
+
#print(files)
|
36 |
+
response=[]
|
37 |
+
async for row in files:
|
38 |
+
#print(row['file']['caption'])
|
39 |
+
try :
|
40 |
+
#print("* Response",search_tmdb(row['file']['caption'] if row['file']['caption'] else row['file']['file_name']))
|
41 |
+
resp = search_tmdb_movies( str(row['file']['caption']) if str(row['file']['caption']) else str(row['file']['file_name']))
|
42 |
+
if resp != None :
|
43 |
+
#resp= dict(resp)
|
44 |
+
#print("TMDB Response :",resp)
|
45 |
+
response.append(resp)
|
46 |
+
else:
|
47 |
+
print("\n * Skipped:",row['file']['caption'],str(row['file']['file_name']))
|
48 |
+
continue
|
49 |
+
except Exception as e:
|
50 |
+
print("Error ",e)
|
51 |
+
break
|
52 |
+
|
53 |
+
#print(response)
|
54 |
+
# Convert Python data to JSON
|
55 |
+
#json_response = json.dumps(response).encode('utf-8')
|
56 |
+
# Return as aiohttp response using web.json_response
|
57 |
+
#return web.json_response(response)
|
58 |
+
return web.json_response(json.loads(dumps(response)))
|
59 |
+
|
60 |
+
async def list_all_tmdb_tv_from_db(request):
|
61 |
+
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
62 |
+
files= await db.get_all_files()
|
63 |
+
#print(files)
|
64 |
+
response=[]
|
65 |
+
async for row in files:
|
66 |
+
#print(row['file']['caption'])
|
67 |
+
try :
|
68 |
+
#print("* Response",search_tmdb(row['file']['caption'] if row['file']['caption'] else row['file']['file_name']))
|
69 |
+
resp = search_tmdb_tv( str(row['file']['caption']) if str(row['file']['caption']) else str(row['file']['file_name']))
|
70 |
+
if resp != None :
|
71 |
+
#resp= dict(resp)
|
72 |
+
#print("TMDB Response :",resp)
|
73 |
+
response.append(resp)
|
74 |
+
else:
|
75 |
+
print("\n * Skipped:",row['file']['caption'],str(row['file']['file_name']))
|
76 |
+
continue
|
77 |
+
except Exception as e:
|
78 |
+
print("Error ",e)
|
79 |
+
break
|
80 |
+
|
81 |
+
#print(response)
|
82 |
+
# Convert Python data to JSON
|
83 |
+
#json_response = json.dumps(response).encode('utf-8')
|
84 |
+
# Return as aiohttp response using web.json_response
|
85 |
+
#return web.json_response(response)
|
86 |
+
return web.json_response(json.loads(dumps(response)))
|
87 |
|
88 |
#api.router.add_get('/tmdb/list', list_all_files_tmdb)
|
89 |
async def list_all_files_tmdb(request):
|
|
|
95 |
#print(row['file']['caption'])
|
96 |
try :
|
97 |
#print("* Response",search_tmdb(row['file']['caption'] if row['file']['caption'] else row['file']['file_name']))
|
98 |
+
resp = search_tmdb_any( str(row['file']['caption']) if str(row['file']['caption']) else str(row['file']['file_name']))
|
99 |
if resp != None :
|
100 |
#resp= dict(resp)
|
101 |
+
#print("TMDB Response :",resp)
|
102 |
response.append(resp)
|
103 |
else:
|
104 |
print("\n * Skipped:",row['file']['caption'],str(row['file']['file_name']))
|
|
|
229 |
api = web.Application()
|
230 |
api.router.add_get('/', handle_v2)
|
231 |
api.router.add_get('/files', list_all_files_db)
|
232 |
+
api.router.add_get('/files/mix', list_all_files)
|
233 |
+
|
234 |
+
api.router.add_get('/tmdb/mix', list_all_files_tmdb)
|
235 |
+
api.router.add_get('/tmdb/tv', list_all_tmdb_tv_from_db)
|
236 |
+
api.router.add_get('/tmdb/movies', list_all_tmdb_movies_from_db)
|
237 |
+
|
238 |
api.router.add_get('/upload', upload_file)
|
239 |
api.router.add_get('/dl/{path}', stream_handler)
|