diff --git a/StreamingCommunity/Lib/Downloader/HLS/segments.py b/StreamingCommunity/Lib/Downloader/HLS/segments.py index 7974438..7dca027 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/segments.py +++ b/StreamingCommunity/Lib/Downloader/HLS/segments.py @@ -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. ) diff --git a/StreamingCommunity/Lib/M3U8/parser.py b/StreamingCommunity/Lib/M3U8/parser.py index 07a6db3..f1bde82 100644 --- a/StreamingCommunity/Lib/M3U8/parser.py +++ b/StreamingCommunity/Lib/M3U8/parser.py @@ -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)} \ No newline at end of file diff --git a/StreamingCommunity/Lib/TMBD/tmdb.py b/StreamingCommunity/Lib/TMBD/tmdb.py index de1b4fb..4348be0 100644 --- a/StreamingCommunity/Lib/TMBD/tmdb.py +++ b/StreamingCommunity/Lib/TMBD/tmdb.py @@ -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.