mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-06 19:45:24 +00:00
Add cache for tmbd
This commit is contained in:
parent
a78dd10b36
commit
88edb3766c
@ -92,7 +92,6 @@ class M3U8_Segments:
|
||||
self.info_maxRetry = 0
|
||||
self.info_nRetry = 0
|
||||
self.info_nFailed = 0
|
||||
|
||||
self.active_retries = 0
|
||||
self.active_retries_lock = threading.Lock()
|
||||
|
||||
@ -207,7 +206,7 @@ class M3U8_Segments:
|
||||
- index (int): The index of the segment.
|
||||
- progress_bar (tqdm): Progress counter for tracking download progress.
|
||||
- backoff_factor (float): The backoff factor for exponential backoff (default is 1.5 seconds).
|
||||
"""
|
||||
"""
|
||||
for attempt in range(REQUEST_MAX_RETRY):
|
||||
if self.interrupt_flag.is_set():
|
||||
return
|
||||
@ -309,6 +308,8 @@ class M3U8_Segments:
|
||||
|
||||
except queue.Empty:
|
||||
self.current_timeout = min(MAX_TIMEOOUT, self.current_timeout * 1.1)
|
||||
time.sleep(0.05)
|
||||
|
||||
if self.stop_event.is_set():
|
||||
break
|
||||
|
||||
@ -331,7 +332,8 @@ class M3U8_Segments:
|
||||
unit='s',
|
||||
ascii='░▒█',
|
||||
bar_format=self._get_bar_format(description),
|
||||
mininterval=0.05,
|
||||
mininterval=0.6,
|
||||
maxinterval=1.0,
|
||||
file=sys.stdout, # Using file=sys.stdout to force in-place updates because sys.stderr may not support carriage returns in this environment.
|
||||
)
|
||||
|
||||
|
@ -382,47 +382,6 @@ class M3U8_Subtitle:
|
||||
return subtitle
|
||||
return None
|
||||
|
||||
def download_all(self, custom_subtitle):
|
||||
"""
|
||||
Download all subtitles listed in the object's attributes, filtering based on a provided list of custom subtitles.
|
||||
|
||||
Parameters:
|
||||
- custom_subtitle (list): A list of custom subtitles to download.
|
||||
|
||||
Returns:
|
||||
list: A list containing dictionaries with subtitle information including name, language, and URI.
|
||||
"""
|
||||
|
||||
output = [] # Initialize an empty list to store subtitle information
|
||||
|
||||
# Iterate through all available subtitles
|
||||
for obj_subtitle in self.subtitle_get_all_uris_and_names():
|
||||
|
||||
# Check if the subtitle name is not in the list of custom subtitles, and skip if not found
|
||||
if obj_subtitle.get('name') not in custom_subtitle:
|
||||
continue
|
||||
|
||||
# Send a request to retrieve the subtitle content
|
||||
logging.info(f"Download subtitle: {obj_subtitle.get('name')}")
|
||||
response_subitle = httpx.get(obj_subtitle.get('uri'))
|
||||
|
||||
try:
|
||||
# Try to extract the VTT URL from the subtitle content
|
||||
sub_parse = M3U8_Parser()
|
||||
sub_parse.parse_data(obj_subtitle.get('uri'), response_subitle.text)
|
||||
url_subititle = sub_parse.subtitle[0]
|
||||
|
||||
output.append({
|
||||
'name': obj_subtitle.get('name'),
|
||||
'language': obj_subtitle.get('language'),
|
||||
'uri': url_subititle
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Cant download: {obj_subtitle.get('name')}, error: {e}")
|
||||
|
||||
return output
|
||||
|
||||
|
||||
class M3U8_Parser:
|
||||
def __init__(self):
|
||||
@ -560,7 +519,6 @@ class M3U8_Parser:
|
||||
- m3u8_obj: The M3U8 object containing encryption keys.
|
||||
"""
|
||||
try:
|
||||
|
||||
if m3u8_obj.key is not None:
|
||||
if self.keys is None:
|
||||
self.keys = {
|
||||
@ -569,7 +527,6 @@ class M3U8_Parser:
|
||||
'uri': m3u8_obj.key.uri
|
||||
}
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Error parsing encryption keys: {e}")
|
||||
sys.exit(0)
|
||||
@ -634,7 +591,6 @@ class M3U8_Parser:
|
||||
"""
|
||||
Initialize variables for video, audio, and subtitle playlists.
|
||||
"""
|
||||
|
||||
self._video = M3U8_Video(self.video_playlist)
|
||||
self._audio = M3U8_Audio(self.audio_playlist)
|
||||
self._subtitle = M3U8_Subtitle(self.subtitle_playlist)
|
||||
@ -668,4 +624,4 @@ class M3U8_Parser:
|
||||
if return_string:
|
||||
return f"[yellow]{int(hours)}[red]h [yellow]{int(minutes)}[red]m [yellow]{int(seconds)}[red]s"
|
||||
else:
|
||||
return {'h': int(hours), 'm': int(minutes), 's': int(seconds)}
|
||||
return {'h': int(hours), 'm': int(minutes), 's': int(seconds)}
|
@ -101,6 +101,8 @@ class TheMovieDB:
|
||||
self.api_key = api_key
|
||||
self.base_url = "https://api.themoviedb.org/3"
|
||||
#self.genres = self._fetch_genres()
|
||||
self._cached_trending_tv = None
|
||||
self._cached_trending_movies = None
|
||||
|
||||
def _make_request(self, endpoint, params=None):
|
||||
"""
|
||||
@ -162,17 +164,36 @@ class TheMovieDB:
|
||||
def display_trending_tv_shows(self):
|
||||
"""
|
||||
Fetch and display the top 5 trending TV shows of the week.
|
||||
Uses cached data if available, otherwise makes a new request.
|
||||
"""
|
||||
data = self._make_request("trending/tv/week").get("results", [])
|
||||
self._display_top_5("Trending TV shows", data, name_key='name')
|
||||
if self._cached_trending_tv is None:
|
||||
self._cached_trending_tv = self._make_request("trending/tv/week").get("results", [])
|
||||
|
||||
self._display_top_5("Trending TV shows", self._cached_trending_tv, name_key='name')
|
||||
|
||||
def refresh_trending_tv_shows(self):
|
||||
"""
|
||||
Force a refresh of the trending TV shows cache.
|
||||
"""
|
||||
self._cached_trending_tv = self._make_request("trending/tv/week").get("results", [])
|
||||
return self._cached_trending_tv
|
||||
|
||||
def display_trending_films(self):
|
||||
"""
|
||||
Fetch and display the top 5 trending films of the week.
|
||||
Uses cached data if available, otherwise makes a new request.
|
||||
"""
|
||||
data = self._make_request("trending/movie/week").get("results", [])
|
||||
self._display_top_5("Trending films", data, name_key='title')
|
||||
if self._cached_trending_movies is None:
|
||||
self._cached_trending_movies = self._make_request("trending/movie/week").get("results", [])
|
||||
|
||||
self._display_top_5("Trending films", self._cached_trending_movies, name_key='title')
|
||||
|
||||
def refresh_trending_films(self):
|
||||
"""
|
||||
Force a refresh of the trending films cache.
|
||||
"""
|
||||
self._cached_trending_movies = self._make_request("trending/movie/week").get("results", [])
|
||||
return self._cached_trending_movies
|
||||
def search_movie(self, movie_name: str):
|
||||
"""
|
||||
Search for a movie by name and return its TMDB ID.
|
||||
|
Loading…
x
Reference in New Issue
Block a user