mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 20:15: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_maxRetry = 0
|
||||||
self.info_nRetry = 0
|
self.info_nRetry = 0
|
||||||
self.info_nFailed = 0
|
self.info_nFailed = 0
|
||||||
|
|
||||||
self.active_retries = 0
|
self.active_retries = 0
|
||||||
self.active_retries_lock = threading.Lock()
|
self.active_retries_lock = threading.Lock()
|
||||||
|
|
||||||
@ -309,6 +308,8 @@ class M3U8_Segments:
|
|||||||
|
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
self.current_timeout = min(MAX_TIMEOOUT, self.current_timeout * 1.1)
|
self.current_timeout = min(MAX_TIMEOOUT, self.current_timeout * 1.1)
|
||||||
|
time.sleep(0.05)
|
||||||
|
|
||||||
if self.stop_event.is_set():
|
if self.stop_event.is_set():
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -331,7 +332,8 @@ class M3U8_Segments:
|
|||||||
unit='s',
|
unit='s',
|
||||||
ascii='░▒█',
|
ascii='░▒█',
|
||||||
bar_format=self._get_bar_format(description),
|
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.
|
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 subtitle
|
||||||
return None
|
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:
|
class M3U8_Parser:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -560,7 +519,6 @@ class M3U8_Parser:
|
|||||||
- m3u8_obj: The M3U8 object containing encryption keys.
|
- m3u8_obj: The M3U8 object containing encryption keys.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if m3u8_obj.key is not None:
|
if m3u8_obj.key is not None:
|
||||||
if self.keys is None:
|
if self.keys is None:
|
||||||
self.keys = {
|
self.keys = {
|
||||||
@ -569,7 +527,6 @@ class M3U8_Parser:
|
|||||||
'uri': m3u8_obj.key.uri
|
'uri': m3u8_obj.key.uri
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error parsing encryption keys: {e}")
|
logging.error(f"Error parsing encryption keys: {e}")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@ -634,7 +591,6 @@ class M3U8_Parser:
|
|||||||
"""
|
"""
|
||||||
Initialize variables for video, audio, and subtitle playlists.
|
Initialize variables for video, audio, and subtitle playlists.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._video = M3U8_Video(self.video_playlist)
|
self._video = M3U8_Video(self.video_playlist)
|
||||||
self._audio = M3U8_Audio(self.audio_playlist)
|
self._audio = M3U8_Audio(self.audio_playlist)
|
||||||
self._subtitle = M3U8_Subtitle(self.subtitle_playlist)
|
self._subtitle = M3U8_Subtitle(self.subtitle_playlist)
|
||||||
|
@ -101,6 +101,8 @@ class TheMovieDB:
|
|||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.base_url = "https://api.themoviedb.org/3"
|
self.base_url = "https://api.themoviedb.org/3"
|
||||||
#self.genres = self._fetch_genres()
|
#self.genres = self._fetch_genres()
|
||||||
|
self._cached_trending_tv = None
|
||||||
|
self._cached_trending_movies = None
|
||||||
|
|
||||||
def _make_request(self, endpoint, params=None):
|
def _make_request(self, endpoint, params=None):
|
||||||
"""
|
"""
|
||||||
@ -162,17 +164,36 @@ class TheMovieDB:
|
|||||||
def display_trending_tv_shows(self):
|
def display_trending_tv_shows(self):
|
||||||
"""
|
"""
|
||||||
Fetch and display the top 5 trending TV shows of the week.
|
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", [])
|
if self._cached_trending_tv is None:
|
||||||
self._display_top_5("Trending TV shows", data, name_key='name')
|
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):
|
def display_trending_films(self):
|
||||||
"""
|
"""
|
||||||
Fetch and display the top 5 trending films of the week.
|
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", [])
|
if self._cached_trending_movies is None:
|
||||||
self._display_top_5("Trending films", data, name_key='title')
|
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):
|
def search_movie(self, movie_name: str):
|
||||||
"""
|
"""
|
||||||
Search for a movie by name and return its TMDB ID.
|
Search for a movie by name and return its TMDB ID.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user