Spaces:
Running
Running
BinaryONe
commited on
Commit
·
1a39b92
1
Parent(s):
5c17bf3
Callback Update
Browse files- FileStream/APIs/IMDB-core/__init__.py +2 -0
- FileStream/APIs/IMDB-core/imdb.py +414 -0
- FileStream/APIs/IMDB-core/parser.py +54 -0
- FileStream/APIs/IMDB-core/usage.txt +0 -0
- FileStream/APIs/IMDB/__init__.py +2 -0
- FileStream/{TMDB → APIs/TMDB}/Endpoint.py +0 -0
- FileStream/{TMDB → APIs/TMDB}/__init__.py +0 -0
- FileStream/APIs/__init__.py +0 -0
- FileStream/Tools/cleanup.py +6 -2
- FileStream/bot/plugins/FileHandlers/callback.py +5 -4
- FileStream/utils/FileProcessors/bot_utils.py +12 -18
- requirements.txt +1 -0
FileStream/APIs/IMDB-core/__init__.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
from .parser import ImdbParser
|
2 |
+
from .imdb import IMDB
|
FileStream/APIs/IMDB-core/imdb.py
ADDED
@@ -0,0 +1,414 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
import json
|
3 |
+
import requests
|
4 |
+
from PyMovieDb import ImdbParser
|
5 |
+
from requests_html import HTMLSession
|
6 |
+
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
7 |
+
|
8 |
+
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
9 |
+
|
10 |
+
|
11 |
+
class IMDB:
|
12 |
+
"""
|
13 |
+
A class to represent IMDB API.
|
14 |
+
|
15 |
+
--------------
|
16 |
+
|
17 |
+
Main Methods of the IMDB API
|
18 |
+
--------------
|
19 |
+
#1. search(name, year=None, tv=False, person=False)
|
20 |
+
-- to search a query on IMDB
|
21 |
+
|
22 |
+
#2. get_by_name(name, year=None, tv=False)
|
23 |
+
-- to get a Movie/TV-Series info by it's name (pass year also to increase accuracy)
|
24 |
+
|
25 |
+
#3. get_by_id(file_id)
|
26 |
+
-- to get a Movie/TV-Series info by it's IMDB-ID (pass year also to increase accuracy)
|
27 |
+
|
28 |
+
#4. person_by_name(name)
|
29 |
+
-- to get a person's info by his/her name
|
30 |
+
|
31 |
+
#5. person_by_id( p_id)
|
32 |
+
-- to get a person's info by his/her IMDB-ID
|
33 |
+
|
34 |
+
#6. upcoming(region=None)
|
35 |
+
-- to get upcoming movies/TV-Series
|
36 |
+
|
37 |
+
#7. popular_movies(genre=None, start_id=1, sort_by=None)
|
38 |
+
-- to get IMDB popular movies
|
39 |
+
|
40 |
+
#8. popular_tv(genre=None, start_id=1, sort_by=None)
|
41 |
+
-- to get IMDB popular Tv-Series
|
42 |
+
"""
|
43 |
+
def __init__(self):
|
44 |
+
self.session = HTMLSession()
|
45 |
+
self.headers = {
|
46 |
+
"Accept": "application/json, text/plain, */*",
|
47 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36",
|
48 |
+
"Referer": "https://www.imdb.com/"
|
49 |
+
}
|
50 |
+
self.baseURL = "https://www.imdb.com"
|
51 |
+
self.search_results = {'result_count': 0, 'results': []}
|
52 |
+
self.NA = json.dumps({"status": 404, "message": "No Result Found!", 'result_count': 0, 'results': []})
|
53 |
+
|
54 |
+
# ..................................method to search on IMDB...........................................
|
55 |
+
def search(self, name, year=None, tv=False, person=False):
|
56 |
+
"""
|
57 |
+
@description:- Helps to search a query on IMDB.
|
58 |
+
@parameter-1:- <str:name>, query value to search.
|
59 |
+
@parameter-2:- <int:year> OPTIONAL, release year of query/movie/tv/file to search.
|
60 |
+
@parameter-3:- <bool:tv> OPTIONAL, to filter/limit/bound search results only for 'TV Series'.
|
61 |
+
@parameter-4:- <bool:person> OPTIONAL, to filter search results only for person.
|
62 |
+
@returns:- A JSON string:
|
63 |
+
- {'result_count': <int:total_search_results>, 'results': <list:list_of_files/movie_info_dict>}
|
64 |
+
"""
|
65 |
+
assert isinstance(name, str)
|
66 |
+
self.search_results = {'result_count': 0, 'results': []}
|
67 |
+
|
68 |
+
name = name.replace(" ", "+")
|
69 |
+
|
70 |
+
if year is None:
|
71 |
+
url = f"https://www.imdb.com/find?q={name}"
|
72 |
+
else:
|
73 |
+
assert isinstance(year, int)
|
74 |
+
url = f"https://www.imdb.com/find?q={name}+{year}"
|
75 |
+
# print(url)
|
76 |
+
|
77 |
+
try:
|
78 |
+
response = self.session.get(url)
|
79 |
+
except requests.exceptions.ConnectionError as e:
|
80 |
+
response = self.session.get(url, verify=False)
|
81 |
+
|
82 |
+
# results = response.html.xpath("//table[@class='findList']/tr")
|
83 |
+
results = response.html.xpath("//section[@data-testid='find-results-section-title']/div/ul/li")
|
84 |
+
# print(len(results))
|
85 |
+
if tv is True:
|
86 |
+
results = [result for result in results if "TV" in result.text]
|
87 |
+
|
88 |
+
if person is True:
|
89 |
+
results = response.html.xpath("//section[@data-testid='find-results-section-name']/div/ul/li")
|
90 |
+
results = [result for result in results if 'name' in result.find('a')[0].attrs['href']]
|
91 |
+
# print(results)
|
92 |
+
output = []
|
93 |
+
for result in results:
|
94 |
+
name = result.text.replace('\n', ' ')
|
95 |
+
url = result.find('a')[0].attrs['href']
|
96 |
+
if ('Podcast' not in name) and ('Music Video' not in name):
|
97 |
+
try:
|
98 |
+
image = result.xpath("//img")[0].attrs['src']
|
99 |
+
file_id = url.split('/')[2]
|
100 |
+
output.append({
|
101 |
+
'id': file_id,
|
102 |
+
"name": name,
|
103 |
+
"url": f"https://www.imdb.com{url}",
|
104 |
+
"poster": image
|
105 |
+
})
|
106 |
+
except IndexError:
|
107 |
+
pass
|
108 |
+
self.search_results = {'result_count': len(output), 'results': output}
|
109 |
+
return json.dumps(self.search_results, indent=2)
|
110 |
+
|
111 |
+
# ..............................methods to get a movie/web-series/tv info..............................
|
112 |
+
def get(self, url):
|
113 |
+
"""
|
114 |
+
@description:- helps to get a file's complete info (used by get_by_name() & get_by_id() )
|
115 |
+
@parameter:- <str:url>, url of the file/movie/tv-series.
|
116 |
+
@returns:- File/movie/TV info as JSON string.
|
117 |
+
"""
|
118 |
+
try:
|
119 |
+
response = self.session.get(url)
|
120 |
+
result = response.html.xpath("//script[@type='application/ld+json']")[0].text
|
121 |
+
result = ''.join(result.splitlines()) # removing newlines
|
122 |
+
result = f"""{result}"""
|
123 |
+
# print(result)
|
124 |
+
except IndexError:
|
125 |
+
return self.NA
|
126 |
+
try:
|
127 |
+
# converting json string into dict
|
128 |
+
result = json.loads(result)
|
129 |
+
except json.decoder.JSONDecodeError as e:
|
130 |
+
# sometimes json is invalid as 'description' contains inverted commas or other html escape chars
|
131 |
+
try:
|
132 |
+
to_parse = ImdbParser(result)
|
133 |
+
# removing trailer & description schema from json string
|
134 |
+
parsed = to_parse.remove_trailer
|
135 |
+
parsed = to_parse.remove_description
|
136 |
+
# print(parsed)
|
137 |
+
result = json.loads(parsed)
|
138 |
+
except json.decoder.JSONDecodeError as e:
|
139 |
+
try:
|
140 |
+
# removing reviewBody from json string
|
141 |
+
parsed = to_parse.remove_review_body
|
142 |
+
result = json.loads(parsed)
|
143 |
+
except json.decoder.JSONDecodeError as e:
|
144 |
+
# invalid char(s) is/are not in description/trailer/reviewBody schema
|
145 |
+
return self.NA
|
146 |
+
|
147 |
+
output = {
|
148 |
+
"type": result.get('@type'),
|
149 |
+
"name": result.get('name'),
|
150 |
+
"url": self.baseURL + result.get('url').split("/title")[-1],
|
151 |
+
"poster": result.get('image'),
|
152 |
+
"description": result.get('description'),
|
153 |
+
"review": {
|
154 |
+
"author": result.get("review", {'author': {'name': None}}).get('author').get('name'),
|
155 |
+
"dateCreated": result.get("review", {"dateCreated": None}).get("dateCreated"),
|
156 |
+
"inLanguage": result.get("review", {"inLanguage": None}).get("inLanguage"),
|
157 |
+
"heading": result.get("review", {"name": None}).get("name"),
|
158 |
+
"reviewBody": result.get("review", {"reviewBody": None}).get("reviewBody"),
|
159 |
+
"reviewRating": {
|
160 |
+
"worstRating": result.get("review", {"reviewRating": {"worstRating": None}})
|
161 |
+
.get("reviewRating",{"worstRating": None}).get("worstRating"),
|
162 |
+
"bestRating": result.get("review", {"reviewRating": {"bestRating": None}})
|
163 |
+
.get("reviewRating",{"bestRating": None}).get("bestRating"),
|
164 |
+
"ratingValue": result.get("review", {"reviewRating": {"ratingValue": None}})
|
165 |
+
.get("reviewRating",{"ratingValue": None}).get("ratingValue"),
|
166 |
+
},
|
167 |
+
},
|
168 |
+
"rating": {
|
169 |
+
"ratingCount": result.get("aggregateRating", {"ratingCount": None}).get("ratingCount"),
|
170 |
+
"bestRating": result.get("aggregateRating", {"bestRating": None}).get("bestRating"),
|
171 |
+
"worstRating": result.get("aggregateRating", {"worstRating": None}).get("worstRating"),
|
172 |
+
"ratingValue": result.get("aggregateRating", {"ratingValue": None}).get("ratingValue"),
|
173 |
+
},
|
174 |
+
"contentRating": result.get("contentRating"),
|
175 |
+
"genre": result.get("genre"),
|
176 |
+
"datePublished": result.get("datePublished"),
|
177 |
+
"keywords": result.get("keywords"),
|
178 |
+
"duration": result.get("duration"),
|
179 |
+
"actor": [
|
180 |
+
{"name": actor.get("name"), "url": actor.get("url")} for actor in result.get("actor", [])
|
181 |
+
],
|
182 |
+
"director": [
|
183 |
+
{"name": director.get("name"), "url": director.get("url")} for director in result.get("director", [])
|
184 |
+
],
|
185 |
+
"creator": [
|
186 |
+
{"name": creator.get("name"), "url": creator.get("url")} for creator in result.get("creator", [])
|
187 |
+
if creator.get('@type') == 'Person'
|
188 |
+
]
|
189 |
+
}
|
190 |
+
return json.dumps(output, indent=2)
|
191 |
+
|
192 |
+
def get_by_name(self, name, year=None, tv=False):
|
193 |
+
"""
|
194 |
+
@description:- Helps to search a file/movie/tv by name.
|
195 |
+
@parameter-1:- <str:name>, query/name to search.
|
196 |
+
@parameter-2:- <int:year> OPTIONAL, release year of query/movie/tv/file to search.
|
197 |
+
@parameter-3:- <bool:tv> OPTIONAL, to filter/limit/bound search result only for 'TV Series'.
|
198 |
+
@returns:- File/movie/TV info as JSON string.
|
199 |
+
"""
|
200 |
+
results = json.loads(self.search(name, year=year))
|
201 |
+
all_results = [i for i in self.search_results['results'] if 'title' in i['url']]
|
202 |
+
# print(all_results)
|
203 |
+
|
204 |
+
# filtering TV and movies
|
205 |
+
if tv is True: # for tv/Web-Series only
|
206 |
+
tv_only = [result for result in all_results if "TV" in result['name']]
|
207 |
+
if year is not None:
|
208 |
+
tv_only = [result for result in tv_only if str(year) in result['name']]
|
209 |
+
# double checking by file name
|
210 |
+
if bool(tv_only):
|
211 |
+
tv_only_checked = [result for result in tv_only if result['name'].lower().startswith(name.split(" ")[0].lower())]
|
212 |
+
tv_only = tv_only_checked if bool(tv_only_checked) else tv_only
|
213 |
+
results['results'] = tv_only if bool(tv_only) else all_results
|
214 |
+
|
215 |
+
else: # for movies only
|
216 |
+
movie_only = [result for result in all_results if "TV" not in result['name']]
|
217 |
+
if year is not None:
|
218 |
+
movie_only = [result for result in movie_only if str(year) in result['name']]
|
219 |
+
# double checking by file name
|
220 |
+
if bool(movie_only):
|
221 |
+
movie_only_checked = [result for result in movie_only if result['name'].lower().startswith(name.split(" ")[0].lower())]
|
222 |
+
movie_only = movie_only_checked if bool(movie_only_checked) else movie_only
|
223 |
+
results['results'] = movie_only if bool(movie_only) else all_results
|
224 |
+
# print(results['results'])
|
225 |
+
|
226 |
+
if len(results['results']) > 0:
|
227 |
+
return self.get(results['results'][0].get('url'))
|
228 |
+
else:
|
229 |
+
return self.NA
|
230 |
+
|
231 |
+
def get_by_id(self, file_id):
|
232 |
+
"""
|
233 |
+
@description:- Helps to search a file/movie/tv by its imdb ID.
|
234 |
+
@parameter-1:- <str:file_id>, imdb ID of the file/movie/tv.
|
235 |
+
@returns:- File/movie/TV info as JSON string.
|
236 |
+
"""
|
237 |
+
assert isinstance(file_id, str)
|
238 |
+
url = f"{self.baseURL}/title/{file_id}"
|
239 |
+
return self.get(url)
|
240 |
+
|
241 |
+
# ........................................Methods for person profile...................................
|
242 |
+
def get_person(self, url):
|
243 |
+
"""
|
244 |
+
@description:- Helps to search a person info by its url, (used by person_by_name() & person_by_id() ).
|
245 |
+
@parameter-1:- <str:url>, url of the person's profile page.
|
246 |
+
@returns:- Person's info as JSON string.
|
247 |
+
"""
|
248 |
+
try:
|
249 |
+
response = self.session.get(url)
|
250 |
+
result = response.html.xpath("//script[@type='application/ld+json']")[0].text
|
251 |
+
result = f"""{result}"""
|
252 |
+
result = json.loads(result)
|
253 |
+
except json.decoder.JSONDecodeError as e:
|
254 |
+
return self.NA
|
255 |
+
|
256 |
+
del result["@context"]
|
257 |
+
result['type'] = result.get('@type')
|
258 |
+
del result["@type"]
|
259 |
+
return json.dumps(result, indent=2)
|
260 |
+
|
261 |
+
def person_by_name(self, name):
|
262 |
+
"""
|
263 |
+
@description:- Helps to search a person info by its name.
|
264 |
+
@parameter-1:- <str:name>, name of the person.
|
265 |
+
@returns:- Person's info as JSON string.
|
266 |
+
"""
|
267 |
+
results = json.loads(self.search(name, person=True))
|
268 |
+
# print(results)
|
269 |
+
url = results['results'][0].get('url')
|
270 |
+
return self.get_person(url)
|
271 |
+
|
272 |
+
def person_by_id(self, p_id):
|
273 |
+
"""
|
274 |
+
@description:- Helps to search a person info by its imdb ID.
|
275 |
+
@parameter-1:- <str:p_id>, imdb ID of the person's profile.
|
276 |
+
@returns:- Person's info as JSON string.
|
277 |
+
"""
|
278 |
+
assert isinstance(p_id, str)
|
279 |
+
url = f"{self.baseURL}/name/{p_id}"
|
280 |
+
return self.get_person(url)
|
281 |
+
|
282 |
+
# .........................................For Upcoming Movies.........................................
|
283 |
+
def upcoming(self, region=None):
|
284 |
+
"""
|
285 |
+
@description:- Helps to get upcoming movies/tv-series.
|
286 |
+
@parameter-1:- <str:region> OPTIONAL, country code (like US, IN etc.) to filter results by region/country.
|
287 |
+
@returns:- upcoming movies/TV-Series info as JSON string.
|
288 |
+
"""
|
289 |
+
if region is not None:
|
290 |
+
assert isinstance(region, str)
|
291 |
+
url = f"https://www.imdb.com/calendar?region={region}"
|
292 |
+
else:
|
293 |
+
url = "https://www.imdb.com/calendar"
|
294 |
+
|
295 |
+
try:
|
296 |
+
response = self.session.get(url)
|
297 |
+
except requests.exceptions.ConnectionError as e:
|
298 |
+
response = self.session.get(url, verify=False)
|
299 |
+
|
300 |
+
output = []
|
301 |
+
div = response.html.xpath("//main")[0]
|
302 |
+
# movies are divided/enlisted within article tag
|
303 |
+
articles = div.find('article')
|
304 |
+
for article in articles:
|
305 |
+
h3 = article.find('h3')[0]
|
306 |
+
ul = article.xpath('//ul')[0].xpath('//li')
|
307 |
+
for li in ul:
|
308 |
+
try:
|
309 |
+
movie = li.find('a')[0]
|
310 |
+
poster = ul[0].find('img')[0].attrs.get('src')
|
311 |
+
output.append({
|
312 |
+
'id': movie.attrs['href'].split('/')[2],
|
313 |
+
'name': movie.text,
|
314 |
+
'url': self.baseURL + movie.attrs['href'],
|
315 |
+
'release_data': h3.text,
|
316 |
+
'poster': poster.split(',')[0]
|
317 |
+
})
|
318 |
+
except IndexError:
|
319 |
+
pass
|
320 |
+
|
321 |
+
results = {'result_count': len(output), 'results': output}
|
322 |
+
if results['result_count'] > 0:
|
323 |
+
return json.dumps(results, indent=2)
|
324 |
+
else:
|
325 |
+
return self.NA
|
326 |
+
|
327 |
+
# ............................................For Popular Movies.......................................
|
328 |
+
def get_popular(self, url):
|
329 |
+
"""
|
330 |
+
@description:- Helps to search popular movies/TV-Series by url, (used by popular_movies() & popular_tv() ).
|
331 |
+
@parameter-1:- <str:url>, url to search.
|
332 |
+
@returns:- Files/Movies/TV-Series info as JSON string.
|
333 |
+
"""
|
334 |
+
assert isinstance(url, str)
|
335 |
+
try:
|
336 |
+
response = self.session.get(url)
|
337 |
+
except requests.exceptions.ConnectionError as e:
|
338 |
+
response = self.session.get(url, verify=False)
|
339 |
+
|
340 |
+
all_li = response.html.xpath('//ul[@role="presentation"]/li')
|
341 |
+
|
342 |
+
output = []
|
343 |
+
# for link, year in zip(links, years):
|
344 |
+
for li in all_li:
|
345 |
+
for obj in li.find('a'):
|
346 |
+
if ("title" in obj.attrs.get('href')) and (". " in obj.text):
|
347 |
+
href = obj.attrs.get('href')
|
348 |
+
name = obj.text.split(". ")[-1]
|
349 |
+
break
|
350 |
+
|
351 |
+
# getting year
|
352 |
+
for span in li.find('span'):
|
353 |
+
if len(span.text.strip()) == 4:
|
354 |
+
try:
|
355 |
+
year = int(span.text.strip())
|
356 |
+
break
|
357 |
+
except:
|
358 |
+
year = "N/A"
|
359 |
+
|
360 |
+
# getting poster
|
361 |
+
try:
|
362 |
+
file_id = href.split('/')[2]
|
363 |
+
poster = li.xpath("//img[@loading='lazy']")
|
364 |
+
poster = poster[0].attrs.get('src')
|
365 |
+
poster = poster if bool(poster) else 'image_not_found'
|
366 |
+
except:
|
367 |
+
poster = 'image_not_found'
|
368 |
+
# creating file object
|
369 |
+
output.append({
|
370 |
+
'id': file_id,
|
371 |
+
'name': name,
|
372 |
+
'year': year,
|
373 |
+
'url': self.baseURL + href,
|
374 |
+
'poster': poster
|
375 |
+
})
|
376 |
+
|
377 |
+
self.search_results = {'result_count': len(output), 'results': output}
|
378 |
+
return json.dumps(self.search_results, indent=2)
|
379 |
+
|
380 |
+
def popular_movies(self, genre=None, start_id=1, sort_by=None):
|
381 |
+
"""
|
382 |
+
@description:- Helps to get 50 popular movies starting from <start_id>.
|
383 |
+
@parameter-1:- <str:genre> OPTIONAL, to filter results by genre.
|
384 |
+
@parameter-2:- <int:start_id> DEFAULT=1, start id to show results (shows results from start_id to start_id+50).
|
385 |
+
@parameter-3:- <bool:sort_by> OPTIONAL, to sort results (eg. sort=user_rating,desc OR sort=user_rating,asc).
|
386 |
+
- (visit 'https://www.imdb.com/search/title/?title_type=movie' for more info)
|
387 |
+
@returns:- Popular Movies (by genre) info as JSON string.
|
388 |
+
"""
|
389 |
+
assert isinstance(start_id, int)
|
390 |
+
if genre is not None:
|
391 |
+
assert isinstance(genre, str)
|
392 |
+
url = f"https://www.imdb.com/search/title/?title_type=movie&genres={genre}&start={start_id}&sort={sort_by}"
|
393 |
+
else:
|
394 |
+
url = f"https://www.imdb.com/search/title/?title_type=movie&start={start_id}&sort={sort_by}"
|
395 |
+
return self.get_popular(url)
|
396 |
+
|
397 |
+
def popular_tv(self, genre=None, start_id=1, sort_by=None):
|
398 |
+
"""
|
399 |
+
@description:- Helps to get 50 popular TV-Series starting from <start_id>.
|
400 |
+
@parameter-1:- <str:genre> OPTIONAL, to filter results by genre.
|
401 |
+
@parameter-2:- <int:start_id> DEFAULT=1, start id to show results (shows results from start_id to start_id+50).
|
402 |
+
@parameter-3:- <bool:sort_by> OPTIONAL, to sort results (eg. sort=user_rating,desc OR sort=user_rating,asc).
|
403 |
+
- (visit 'https://www.imdb.com/search/title/?title_type=movie' for more info)
|
404 |
+
@returns:- Popular TV-Series info as JSON string.
|
405 |
+
"""
|
406 |
+
assert isinstance(start_id, int)
|
407 |
+
if genre is not None:
|
408 |
+
assert isinstance(genre, str)
|
409 |
+
url = f"https://www.imdb.com/search/title/?title_type=tv_series,tv_miniseries&genres={genre}&start={start_id}&sort={sort_by}"
|
410 |
+
else:
|
411 |
+
url = f"https://www.imdb.com/search/title/?title_type=tv_series,tv_miniseries&start={start_id}&sort={sort_by}"
|
412 |
+
|
413 |
+
return self.get_popular(url)
|
414 |
+
|
FileStream/APIs/IMDB-core/parser.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# for manipulate incoming data/json from IMDB (for invalid json string)
|
2 |
+
class ImdbParser:
|
3 |
+
"""
|
4 |
+
- A class to manipulate incoming json string data of a movie/TV from IMDB.
|
5 |
+
- Changes are required as sometimes the json contains invalid chars in description/reviewBody/trailer schema
|
6 |
+
"""
|
7 |
+
def __init__(self, json_string):
|
8 |
+
self.json_string = json_string
|
9 |
+
|
10 |
+
@property
|
11 |
+
def remove_trailer(self):
|
12 |
+
"""
|
13 |
+
@description:- Helps to remove 'trailer' schema from IMDB data json string.
|
14 |
+
@returns:- New updated JSON string.
|
15 |
+
"""
|
16 |
+
try:
|
17 |
+
self.json_string = ''.join(self.json_string.splitlines())
|
18 |
+
trailer_i = self.json_string.index('"trailer"')
|
19 |
+
actor_i = self.json_string.index('"actor"')
|
20 |
+
to_remove = self.json_string[trailer_i:actor_i:1]
|
21 |
+
self.json_string = self.json_string.replace(to_remove, "")
|
22 |
+
except ValueError:
|
23 |
+
self.json_string = self.json_string
|
24 |
+
return self.json_string
|
25 |
+
|
26 |
+
@property
|
27 |
+
def remove_description(self):
|
28 |
+
"""
|
29 |
+
@description:- Helps to remove 'description' schema from IMDB file json string.
|
30 |
+
@returns:- New updated JSON string.
|
31 |
+
"""
|
32 |
+
try:
|
33 |
+
review_i = self.json_string.index('"review"')
|
34 |
+
des_i = self.json_string.index('"description"', 0, review_i)
|
35 |
+
to_remove = self.json_string[des_i:review_i:1]
|
36 |
+
self.json_string = self.json_string.replace(to_remove, "")
|
37 |
+
except ValueError:
|
38 |
+
self.json_string = self.json_string
|
39 |
+
return self.json_string
|
40 |
+
|
41 |
+
@property
|
42 |
+
def remove_review_body(self):
|
43 |
+
"""
|
44 |
+
@description:- Helps to remove 'reviewBody' schema from IMDB file json string.
|
45 |
+
@returns:- New updated JSON string.
|
46 |
+
"""
|
47 |
+
try:
|
48 |
+
reviewrating_i = self.json_string.index('"reviewRating"')
|
49 |
+
reviewbody_i = self.json_string.index('"reviewBody"', 0, reviewrating_i)
|
50 |
+
to_remove = self.json_string[reviewbody_i:reviewrating_i:1]
|
51 |
+
self.json_string = self.json_string.replace(to_remove, "")
|
52 |
+
except ValueError:
|
53 |
+
self.json_string = self.json_string
|
54 |
+
return self.json_string
|
FileStream/APIs/IMDB-core/usage.txt
ADDED
File without changes
|
FileStream/APIs/IMDB/__init__.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
from PyMovieDb import IMDB
|
2 |
+
imdb = IMDB()
|
FileStream/{TMDB → APIs/TMDB}/Endpoint.py
RENAMED
File without changes
|
FileStream/{TMDB → APIs/TMDB}/__init__.py
RENAMED
File without changes
|
FileStream/APIs/__init__.py
ADDED
File without changes
|
FileStream/Tools/cleanup.py
CHANGED
@@ -20,12 +20,16 @@ def convert_special_to_normal(text):
|
|
20 |
text = re.sub(r'[^A-Za-z0-9 ]+', '', text)
|
21 |
return text
|
22 |
|
23 |
-
def
|
24 |
-
# Define a regular expression pattern to remove special characters, including •, ▫️, etc.
|
25 |
# This pattern keeps only alphanumeric characters (A-Z, a-z, 0-9) and spaces.
|
26 |
cleaned_string = re.sub(r'[^\w\s]+', '', input_string)
|
27 |
return cleaned_string
|
28 |
|
|
|
|
|
|
|
|
|
|
|
29 |
def clean_text(input_text):
|
30 |
# Remove new line characters
|
31 |
text = input_text.replace('\n', '').replace('@', '')
|
|
|
20 |
text = re.sub(r'[^A-Za-z0-9 ]+', '', text)
|
21 |
return text
|
22 |
|
23 |
+
def clean_string_special_old(input_string):
|
|
|
24 |
# This pattern keeps only alphanumeric characters (A-Z, a-z, 0-9) and spaces.
|
25 |
cleaned_string = re.sub(r'[^\w\s]+', '', input_string)
|
26 |
return cleaned_string
|
27 |
|
28 |
+
def clean_string_special(input_string):
|
29 |
+
# This pattern replaces underscores and all special characters with a whitespace.
|
30 |
+
cleaned_string = re.sub(r'[_\W]+', ' ', input_string)
|
31 |
+
return cleaned_string
|
32 |
+
|
33 |
def clean_text(input_text):
|
34 |
# Remove new line characters
|
35 |
text = input_text.replace('\n', '').replace('@', '')
|
FileStream/bot/plugins/FileHandlers/callback.py
CHANGED
@@ -24,6 +24,9 @@ from FileStream.utils.FileProcessors.human_readable import humanbytes
|
|
24 |
from FileStream.bot.plugins.FileHandlers.stream import private_receive_handler
|
25 |
from FileStream.utils.FileProcessors.file_properties import get_file_ids, get_file_info,get_name
|
26 |
from FileStream.utils.FileProcessors.bot_utils import gen_link, priv_func, gen_priv_file_link
|
|
|
|
|
|
|
27 |
#-----------------Starting Point --------------------------#
|
28 |
|
29 |
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
@@ -153,13 +156,11 @@ async def cb_data(bot: Client, update: CallbackQuery):
|
|
153 |
name = getattr(message, "caption", f"{get_name(message)}" ) or "None/Unknown"
|
154 |
#file_name = get_name(message)
|
155 |
#name = file_caption if (file_caption) != "None/Unknown" else file_name
|
156 |
-
from FileStream.TMDB.Endpoint import search_tmdb_any, search_tmdb_tv, search_tmdb_movies
|
157 |
-
|
158 |
print("ANY Resp :",search_tmdb_any(name))
|
159 |
-
|
160 |
if msg_type == 'MOVIE':
|
161 |
resp=search_tmdb_movies(name)
|
162 |
-
|
|
|
163 |
result={
|
164 |
'title': resp['title'],
|
165 |
'id': resp['id'],
|
|
|
24 |
from FileStream.bot.plugins.FileHandlers.stream import private_receive_handler
|
25 |
from FileStream.utils.FileProcessors.file_properties import get_file_ids, get_file_info,get_name
|
26 |
from FileStream.utils.FileProcessors.bot_utils import gen_link, priv_func, gen_priv_file_link
|
27 |
+
|
28 |
+
from FileStream.APIs.TMDB.Endpoint import search_tmdb_any, search_tmdb_tv, search_tmdb_movies
|
29 |
+
from FileStream.APIs.IMDB import imdb
|
30 |
#-----------------Starting Point --------------------------#
|
31 |
|
32 |
db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
|
|
|
156 |
name = getattr(message, "caption", f"{get_name(message)}" ) or "None/Unknown"
|
157 |
#file_name = get_name(message)
|
158 |
#name = file_caption if (file_caption) != "None/Unknown" else file_name
|
|
|
|
|
159 |
print("ANY Resp :",search_tmdb_any(name))
|
|
|
160 |
if msg_type == 'MOVIE':
|
161 |
resp=search_tmdb_movies(name)
|
162 |
+
res = imdb.search('liger', year=2022)
|
163 |
+
print("TMDB Movie Response:",resp,"\n IMDB",res)
|
164 |
result={
|
165 |
'title': resp['title'],
|
166 |
'id': resp['id'],
|
FileStream/utils/FileProcessors/bot_utils.py
CHANGED
@@ -142,8 +142,7 @@ async def gen_priv_file_link(_id):
|
|
142 |
file_link = f"https://t.me/{FileStream.username}?start=privfile_{_id}"
|
143 |
|
144 |
if "video" in mime_type:
|
145 |
-
stream_text = LANG.STREAM_TEXT.format(file_name, file_size, stream_link,
|
146 |
-
page_link, file_link)
|
147 |
reply_markup = InlineKeyboardMarkup(
|
148 |
[ [
|
149 |
InlineKeyboardButton("sᴛʀᴇᴀᴍ",url=page_link),
|
@@ -155,8 +154,7 @@ async def gen_priv_file_link(_id):
|
|
155 |
callback_data=f"msgdelpvt_{_id}")
|
156 |
], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]])
|
157 |
else:
|
158 |
-
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,
|
159 |
-
file_link)
|
160 |
reply_markup = InlineKeyboardMarkup(
|
161 |
[[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
162 |
[
|
@@ -181,8 +179,7 @@ async def gen_link(_id):
|
|
181 |
file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
|
182 |
|
183 |
if "video" in mime_type:
|
184 |
-
stream_text = LANG.STREAM_TEXT.format(file_name, file_size, stream_link,
|
185 |
-
page_link, file_link)
|
186 |
reply_markup = InlineKeyboardMarkup(
|
187 |
[[
|
188 |
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
@@ -194,8 +191,7 @@ async def gen_link(_id):
|
|
194 |
callback_data=f"msgdelpvt_{_id}")
|
195 |
], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]])
|
196 |
else:
|
197 |
-
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,
|
198 |
-
file_link)
|
199 |
reply_markup = InlineKeyboardMarkup(
|
200 |
[[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
201 |
[
|
@@ -220,15 +216,13 @@ async def gen_linkx(m: Message, _id, name: list):
|
|
220 |
file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
|
221 |
|
222 |
if "video" in mime_type:
|
223 |
-
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,
|
224 |
-
page_link)
|
225 |
reply_markup = InlineKeyboardMarkup([[
|
226 |
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
227 |
InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)
|
228 |
]])
|
229 |
else:
|
230 |
-
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,
|
231 |
-
file_link)
|
232 |
reply_markup = InlineKeyboardMarkup(
|
233 |
[[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)]])
|
234 |
return reply_markup, stream_text
|
@@ -252,11 +246,12 @@ async def is_user_banned(message):
|
|
252 |
async def is_channel_banned(bot, message):
|
253 |
if await db.is_user_banned(message.chat.id):
|
254 |
await bot.edit_message_reply_markup(
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
|
|
260 |
return True
|
261 |
return False
|
262 |
|
@@ -307,7 +302,6 @@ async def is_channel_exist(bot, message):
|
|
307 |
# Decorator Function to check if user is authorized
|
308 |
#----------------------------------------------------------------
|
309 |
def verify_users(func):
|
310 |
-
|
311 |
@functools.wraps(func)
|
312 |
async def wrapper(bot, message):
|
313 |
response = {}
|
|
|
142 |
file_link = f"https://t.me/{FileStream.username}?start=privfile_{_id}"
|
143 |
|
144 |
if "video" in mime_type:
|
145 |
+
stream_text = LANG.STREAM_TEXT.format(file_name, file_size, stream_link, page_link, file_link)
|
|
|
146 |
reply_markup = InlineKeyboardMarkup(
|
147 |
[ [
|
148 |
InlineKeyboardButton("sᴛʀᴇᴀᴍ",url=page_link),
|
|
|
154 |
callback_data=f"msgdelpvt_{_id}")
|
155 |
], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]])
|
156 |
else:
|
157 |
+
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,file_link)
|
|
|
158 |
reply_markup = InlineKeyboardMarkup(
|
159 |
[[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
160 |
[
|
|
|
179 |
file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
|
180 |
|
181 |
if "video" in mime_type:
|
182 |
+
stream_text = LANG.STREAM_TEXT.format(file_name, file_size, stream_link,page_link, file_link)
|
|
|
183 |
reply_markup = InlineKeyboardMarkup(
|
184 |
[[
|
185 |
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
|
|
191 |
callback_data=f"msgdelpvt_{_id}")
|
192 |
], [InlineKeyboardButton("ᴄʟᴏsᴇ", callback_data="close")]])
|
193 |
else:
|
194 |
+
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,file_link)
|
|
|
195 |
reply_markup = InlineKeyboardMarkup(
|
196 |
[[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)],
|
197 |
[
|
|
|
216 |
file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
|
217 |
|
218 |
if "video" in mime_type:
|
219 |
+
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,page_link)
|
|
|
220 |
reply_markup = InlineKeyboardMarkup([[
|
221 |
InlineKeyboardButton("sᴛʀᴇᴀᴍ", url=page_link),
|
222 |
InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)
|
223 |
]])
|
224 |
else:
|
225 |
+
stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link,file_link)
|
|
|
226 |
reply_markup = InlineKeyboardMarkup(
|
227 |
[[InlineKeyboardButton("ᴅᴏᴡɴʟᴏᴀᴅ", url=stream_link)]])
|
228 |
return reply_markup, stream_text
|
|
|
246 |
async def is_channel_banned(bot, message):
|
247 |
if await db.is_user_banned(message.chat.id):
|
248 |
await bot.edit_message_reply_markup(
|
249 |
+
chat_id=message.chat.id,
|
250 |
+
message_id=message.id,
|
251 |
+
reply_markup=InlineKeyboardMarkup(
|
252 |
+
[[InlineKeyboardButton(f"ᴄʜᴀɴɴᴇʟ ɪs ʙᴀɴɴᴇᴅ",callback_data="N/A")]]
|
253 |
+
)
|
254 |
+
)
|
255 |
return True
|
256 |
return False
|
257 |
|
|
|
302 |
# Decorator Function to check if user is authorized
|
303 |
#----------------------------------------------------------------
|
304 |
def verify_users(func):
|
|
|
305 |
@functools.wraps(func)
|
306 |
async def wrapper(bot, message):
|
307 |
response = {}
|
requirements.txt
CHANGED
@@ -30,3 +30,4 @@ TgCrypto==1.2.5
|
|
30 |
typing_extensions==4.10.0
|
31 |
urllib3==2.2.1
|
32 |
yarl==1.9.4
|
|
|
|
30 |
typing_extensions==4.10.0
|
31 |
urllib3==2.2.1
|
32 |
yarl==1.9.4
|
33 |
+
PyMovieDb
|