diff --git a/README.md b/README.md index 4f491c6..ac3ea34 100644 --- a/README.md +++ b/README.md @@ -567,9 +567,9 @@ python3 telegram_bot.py | [AltadefinizioneGratis](https://altadefinizionegratis.pro/) | ✅ | -ALT | | [AnimeUnity](https://animeunity.so/) | ✅ | -ANI | | [Ilcorsaronero](https://ilcorsaronero.link/) | ✅ | `-ILC` | -| [CB01New](https://cb01new.media/) | ✅ | -CB0 | +| [CB01New](https://cb01new.gold/) | ✅ | -CB0 | | [DDLStreamItaly](https://ddlstreamitaly.co/) | ✅ | -DDL | -| [GuardaSerie](https://guardaserie.meme/) | ✅ | -GUA | +| [GuardaSerie](https://guardaserie.now/) | ✅ | -GUA | | [MostraGuarda](https://mostraguarda.stream/) | ✅ | -MOS | | [StreamingCommunity](https://streamingcommunity.paris/) | ✅ | -STR | diff --git a/StreamingCommunity/Api/Site/1337xx/__init__.py b/StreamingCommunity/Api/Site/1337xx/__init__.py index f0d5725..5025335 100644 --- a/StreamingCommunity/Api/Site/1337xx/__init__.py +++ b/StreamingCommunity/Api/Site/1337xx/__init__.py @@ -1,16 +1,15 @@ # 02.07.24 -import sys -import subprocess from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title # Logic class -from .site import title_search, run_get_select_title, media_search_manager +from .site import title_search, media_search_manager, table_show_manager from .title import download_title @@ -40,7 +39,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) # Download title download_title(select_title) diff --git a/StreamingCommunity/Api/Site/1337xx/site.py b/StreamingCommunity/Api/Site/1337xx/site.py index 6d683cb..a30db3a 100644 --- a/StreamingCommunity/Api/Site/1337xx/site.py +++ b/StreamingCommunity/Api/Site/1337xx/site.py @@ -13,7 +13,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -77,11 +76,4 @@ def title_search(word_to_search: str) -> int: print(f"Error parsing a film entry: {e}") # Return the number of titles found - return media_search_manager.get_length() - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) + return media_search_manager.get_length() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py b/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py index df2737f..30ca58a 100644 --- a/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py +++ b/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py @@ -7,11 +7,12 @@ from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class -from .site import title_search, run_get_select_title, media_search_manager +from .site import title_search, media_search_manager, table_show_manager from .film import download_film @@ -60,7 +61,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) # Download only film download_film(select_title) diff --git a/StreamingCommunity/Api/Site/altadefinizionegratis/site.py b/StreamingCommunity/Api/Site/altadefinizionegratis/site.py index 3b1a1a3..4e4e6ff 100644 --- a/StreamingCommunity/Api/Site/altadefinizionegratis/site.py +++ b/StreamingCommunity/Api/Site/altadefinizionegratis/site.py @@ -13,7 +13,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -107,11 +106,4 @@ def title_search(title_search: str) -> int: bot.send_message(f"Lista dei risultati:", choices) # Return the number of titles found - return media_search_manager.get_length() - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) \ No newline at end of file + return media_search_manager.get_length() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/animeunity/__init__.py b/StreamingCommunity/Api/Site/animeunity/__init__.py index 5a12833..87f5741 100644 --- a/StreamingCommunity/Api/Site/animeunity/__init__.py +++ b/StreamingCommunity/Api/Site/animeunity/__init__.py @@ -2,16 +2,16 @@ import sys import subprocess -from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class -from .site import title_search, run_get_select_title, media_search_manager +from .site import title_search, media_search_manager, table_show_manager from .film_serie import download_film, download_series @@ -58,7 +58,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list (type: TV \ Movie \ OVA) - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) if select_title.type == 'Movie' or select_title.type == 'OVA': download_film(select_title) diff --git a/StreamingCommunity/Api/Site/animeunity/site.py b/StreamingCommunity/Api/Site/animeunity/site.py index d36411f..48aa105 100644 --- a/StreamingCommunity/Api/Site/animeunity/site.py +++ b/StreamingCommunity/Api/Site/animeunity/site.py @@ -16,7 +16,6 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -182,11 +181,4 @@ def title_search(title: str) -> int: bot.send_message(f"Lista dei risultati:", choices) # Return the length of media search manager - return media_search_manager.get_length() - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) \ No newline at end of file + return media_search_manager.get_length() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/cb01new/__init__.py b/StreamingCommunity/Api/Site/cb01new/__init__.py index f29e299..641a4be 100644 --- a/StreamingCommunity/Api/Site/cb01new/__init__.py +++ b/StreamingCommunity/Api/Site/cb01new/__init__.py @@ -5,10 +5,11 @@ from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title # Logic class -from .site import title_search, run_get_select_title, media_search_manager +from .site import title_search, media_search_manager, table_show_manager from .film import download_film @@ -39,7 +40,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) # !!! ADD TYPE DONT WORK FOR SERIE download_film(select_title) diff --git a/StreamingCommunity/Api/Site/cb01new/site.py b/StreamingCommunity/Api/Site/cb01new/site.py index 0b3f910..8ca838a 100644 --- a/StreamingCommunity/Api/Site/cb01new/site.py +++ b/StreamingCommunity/Api/Site/cb01new/site.py @@ -12,7 +12,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -73,11 +72,4 @@ def title_search(word_to_search: str) -> int: print(f"Error parsing a film entry: {e}") # Return the number of titles found - return media_search_manager.get_length() - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) \ No newline at end of file + return media_search_manager.get_length() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py b/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py index 0e1ae46..f9864a4 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py @@ -6,10 +6,11 @@ from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title # Logic class -from .site import title_search, run_get_select_title, media_search_manager +from .site import title_search, media_search_manager, table_show_manager from .series import download_thread @@ -40,7 +41,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) # Download only film if "Serie TV" in str(select_title.type): diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/series.py b/StreamingCommunity/Api/Site/ddlstreamitaly/series.py index 62fa508..6e81454 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/series.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/series.py @@ -1,7 +1,6 @@ # 13.06.24 import os -import sys from urllib.parse import urlparse from typing import Tuple @@ -10,13 +9,17 @@ from typing import Tuple from StreamingCommunity.Util.console import console from StreamingCommunity.Util.message import start_message from StreamingCommunity.Util.os import os_manager -from StreamingCommunity.Util.table import TVShowManager from StreamingCommunity.Lib.Downloader import MP4_downloader # Logic class from StreamingCommunity.Api.Template.Class.SearchType import MediaItem -from StreamingCommunity.Api.Template.Util import manage_selection, map_episode_title, validate_episode_selection +from StreamingCommunity.Api.Template.Util import ( + manage_selection, + map_episode_title, + validate_episode_selection, + display_episodes_list +) # Player @@ -111,39 +114,3 @@ def download_thread(dict_serie: MediaItem): if kill_handler: break kill_handler = download_video(i_episode, scape_info_serie, video_source)[1] - - -def display_episodes_list(obj_episode_manager) -> str: - """ - Display episodes list and handle user input. - - Returns: - last_command (str): Last command entered by the user. - """ - - # Set up table for displaying episodes - table_show_manager = TVShowManager() - table_show_manager.set_slice_end(10) - - # Add columns to the table - column_info = { - "Index": {'color': 'red'}, - "Name": {'color': 'magenta'}, - } - table_show_manager.add_column(column_info) - - # Populate the table with episodes information - for i, media in enumerate(obj_episode_manager): - table_show_manager.add_tv_show({ - 'Index': str(i+1), - 'Name': media.get('name'), - }) - - # Run the table and handle user input - last_command = table_show_manager.run() - - if last_command == "q": - console.print("\n[red]Quit [white]...") - sys.exit(0) - - return last_command diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py index 3fceee0..70817be 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py @@ -16,7 +16,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -89,11 +88,4 @@ def title_search(word_to_search: str) -> int: logging.error("No table content found.") return -999 - return -9999 - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) \ No newline at end of file + return -9999 \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/guardaserie/__init__.py b/StreamingCommunity/Api/Site/guardaserie/__init__.py index e11597a..89a24b9 100644 --- a/StreamingCommunity/Api/Site/guardaserie/__init__.py +++ b/StreamingCommunity/Api/Site/guardaserie/__init__.py @@ -5,10 +5,11 @@ from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title # Logic class -from .site import title_search, run_get_select_title, media_search_manager +from .site import title_search, media_search_manager, table_show_manager from .series import download_series @@ -39,7 +40,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) # Download only film download_series(select_title) diff --git a/StreamingCommunity/Api/Site/guardaserie/series.py b/StreamingCommunity/Api/Site/guardaserie/series.py index a2ac9a9..a531a11 100644 --- a/StreamingCommunity/Api/Site/guardaserie/series.py +++ b/StreamingCommunity/Api/Site/guardaserie/series.py @@ -1,19 +1,24 @@ # 13.06.24 import os -import sys from typing import Tuple # Internal utilities from StreamingCommunity.Util.console import console, msg from StreamingCommunity.Util.message import start_message -from StreamingCommunity.Util.table import TVShowManager from StreamingCommunity.Lib.Downloader import HLS_Downloader # Logic class -from StreamingCommunity.Api.Template.Util import manage_selection, map_episode_title, dynamic_format_number, validate_selection, validate_episode_selection +from StreamingCommunity.Api.Template.Util import ( + manage_selection, + map_episode_title, + dynamic_format_number, + validate_selection, + validate_episode_selection, + display_episodes_list +) from StreamingCommunity.Api.Template.Class.SearchType import MediaItem @@ -161,40 +166,4 @@ def download_series(dict_serie: MediaItem) -> None: else: # Otherwise, let the user select specific episodes for the single season - download_episode(scape_info_serie, i_season, download_all=False) - - -def display_episodes_list(obj_episode_manager) -> str: - """ - Display episodes list and handle user input. - - Returns: - last_command (str): Last command entered by the user. - """ - - # Set up table for displaying episodes - table_show_manager = TVShowManager() - table_show_manager.set_slice_end(10) - - # Add columns to the table - column_info = { - "Index": {'color': 'red'}, - "Name": {'color': 'magenta'}, - } - table_show_manager.add_column(column_info) - - # Populate the table with episodes information - for media in obj_episode_manager: - table_show_manager.add_tv_show({ - 'Index': str(media.get('number')), - 'Name': media.get('name'), - }) - - # Run the table and handle user input - last_command = table_show_manager.run() - - if last_command == "q": - console.print("\n[red]Quit [white]...") - sys.exit(0) - - return last_command \ No newline at end of file + download_episode(scape_info_serie, i_season, download_all=False) \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/guardaserie/site.py b/StreamingCommunity/Api/Site/guardaserie/site.py index 8611b19..80c4c98 100644 --- a/StreamingCommunity/Api/Site/guardaserie/site.py +++ b/StreamingCommunity/Api/Site/guardaserie/site.py @@ -13,7 +13,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -80,11 +79,4 @@ def title_search(word_to_search: str) -> int: print(f"Error parsing a film entry: {e}") # Return the number of titles found - return media_search_manager.get_length() - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) \ No newline at end of file + return media_search_manager.get_length() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py b/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py index f7b195f..b9af96a 100644 --- a/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py +++ b/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py @@ -11,10 +11,15 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util._jsonConfig import config_manager # Logic class -from StreamingCommunity.Api.Template .Class.SearchType import MediaItem +from StreamingCommunity.Api.Template.Class.SearchType import MediaItem + + +# Variable +max_timeout = config_manager.get_int("REQUESTS", "timeout") class GetSerieInfo: @@ -40,19 +45,12 @@ class GetSerieInfo: try: # Make an HTTP request to the series URL - response = httpx.get(self.url, headers=self.headers, timeout=15) + response = httpx.get(self.url, headers=self.headers, timeout=max_timeout, follow_redirects=True) response.raise_for_status() - # Parse HTML content of the page soup = BeautifulSoup(response.text, "html.parser") - - # Find the container of seasons table_content = soup.find('div', class_="tt_season") - - # Count the number of seasons seasons_number = len(table_content.find_all("li")) - - # Extract the name of the series self.tv_name = soup.find("h1", class_="front_title").get_text(strip=True) return seasons_number @@ -60,7 +58,7 @@ class GetSerieInfo: except Exception as e: logging.error(f"Error parsing HTML page: {e}") - return -999 + return -1 def get_episode_number(self, n_season: int) -> List[Dict[str, str]]: """ @@ -75,7 +73,7 @@ class GetSerieInfo: try: # Make an HTTP request to the series URL - response = httpx.get(self.url, headers=self.headers, timeout=15) + response = httpx.get(self.url, headers=self.headers, timeout=max_timeout, follow_redirects=True) response.raise_for_status() # Parse HTML content of the page @@ -83,8 +81,6 @@ class GetSerieInfo: # Find the container of episodes for the specified season table_content = soup.find('div', class_="tab-pane", id=f"season-{n_season}") - - # Extract episode information episode_content = table_content.find_all("li") list_dict_episode = [] @@ -107,4 +103,4 @@ class GetSerieInfo: except Exception as e: logging.error(f"Error parsing HTML page: {e}") - return [] + return [] \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py b/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py index d82b916..1dc3214 100644 --- a/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py +++ b/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py @@ -6,10 +6,11 @@ from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title # Logic class -from .site import title_search, run_get_select_title, media_search_manager +from .site import title_search, media_search_manager, table_show_manager from .title import download_title @@ -40,7 +41,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) # Download title download_title(select_title) diff --git a/StreamingCommunity/Api/Site/ilcorsaronero/site.py b/StreamingCommunity/Api/Site/ilcorsaronero/site.py index 90aa769..827e5cd 100644 --- a/StreamingCommunity/Api/Site/ilcorsaronero/site.py +++ b/StreamingCommunity/Api/Site/ilcorsaronero/site.py @@ -7,7 +7,6 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager from .util.ilCorsarScraper import IlCorsaroNeroScraper @@ -62,11 +61,4 @@ async def title_search(word_to_search: str) -> int: print(f"Error parsing a film entry: {e}") # Return the number of titles found - return media_search_manager.get_length() - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) \ No newline at end of file + return media_search_manager.get_length() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py index 83aeb15..afab8cb 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py @@ -7,11 +7,12 @@ from urllib.parse import quote_plus # Internal utilities from StreamingCommunity.Util.console import console, msg +from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class -from .site import get_version_and_domain, title_search, run_get_select_title, media_search_manager +from .site import get_version_and_domain, title_search, table_show_manager, media_search_manager from .film import download_film from .series import download_series @@ -62,7 +63,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if len_database > 0: # Select title from list - select_title = run_get_select_title() + select_title = get_select_title(table_show_manager, media_search_manager) if select_title.type == 'tv': download_series(select_title, site_version) diff --git a/StreamingCommunity/Api/Site/streamingcommunity/series.py b/StreamingCommunity/Api/Site/streamingcommunity/series.py index 487e9ef..a4422d2 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/series.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/series.py @@ -1,20 +1,25 @@ # 3.12.23 import os -import sys from typing import Tuple # Internal utilities from StreamingCommunity.Util.console import console, msg from StreamingCommunity.Util.message import start_message -from StreamingCommunity.Util.table import TVShowManager from StreamingCommunity.Lib.Downloader import HLS_Downloader from StreamingCommunity.TelegramHelp.telegram_bot import TelegramSession, get_bot_instance # Logic class from .util.ScrapeSerie import ScrapeSerie -from StreamingCommunity.Api.Template.Util import manage_selection, map_episode_title, dynamic_format_number, validate_selection, validate_episode_selection +from StreamingCommunity.Api.Template.Util import ( + manage_selection, + map_episode_title, + dynamic_format_number, + validate_selection, + validate_episode_selection, + display_episodes_list +) from StreamingCommunity.Api.Template.Class.SearchType import MediaItem @@ -114,7 +119,7 @@ def download_episode(index_season_selected: int, scrape_serie: ScrapeSerie, vide else: # Display episodes list and manage user selection - last_command = display_episodes_list(scrape_serie) + last_command = display_episodes_list(scrape_serie.episode_manager.episodes) list_episode_select = manage_selection(last_command, episodes_count) try: @@ -204,55 +209,4 @@ def download_series(select_season: MediaItem, version: str) -> None: # Get script_id script_id = TelegramSession.get_session() if script_id != "unknown": - TelegramSession.deleteScriptId(script_id) - - -def display_episodes_list(scrape_serie) -> str: - """ - Display episodes list and handle user input. - - Returns: - last_command (str): Last command entered by the user. - """ - if TELEGRAM_BOT: - bot = get_bot_instance() - - # Set up table for displaying episodes - table_show_manager = TVShowManager() - table_show_manager.set_slice_end(10) - - # Add columns to the table - column_info = { - "Index": {'color': 'red'}, - "Name": {'color': 'magenta'}, - "Duration": {'color': 'green'} - } - table_show_manager.add_column(column_info) - - # Populate the table with episodes information - if TELEGRAM_BOT: - choices = [] - - for i, media in enumerate(scrape_serie.episode_manager.episodes): - table_show_manager.add_tv_show({ - 'Index': str(media.number), - 'Name': media.name, - 'Duration': str(media.duration) - }) - - if TELEGRAM_BOT: - choice_text = f"{media.number} - {media.name} ({media.duration} min)" - choices.append(choice_text) - - if TELEGRAM_BOT: - if choices: - bot.send_message(f"Lista episodi:", choices) - - # Run the table and handle user input - last_command = table_show_manager.run() - - if last_command == "q" or last_command == "quit": - console.print("\n[red]Quit [white]...") - sys.exit(0) - - return last_command \ No newline at end of file + TelegramSession.deleteScriptId(script_id) \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/streamingcommunity/site.py b/StreamingCommunity/Api/Site/streamingcommunity/site.py index 0064865..ba5b3b3 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/site.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/site.py @@ -19,7 +19,6 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class -from StreamingCommunity.Api.Template import get_select_title from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager @@ -147,11 +146,4 @@ def title_search(title_search: str, domain: str) -> int: bot.send_message(f"Lista dei risultati:", choices) # Return the number of titles found - return media_search_manager.get_length() - - -def run_get_select_title(): - """ - Display a selection of titles and prompt the user to choose one. - """ - return get_select_title(table_show_manager, media_search_manager) \ No newline at end of file + return media_search_manager.get_length() \ No newline at end of file diff --git a/StreamingCommunity/Api/Template/Util/__init__.py b/StreamingCommunity/Api/Template/Util/__init__.py index e40d729..dd21aa8 100644 --- a/StreamingCommunity/Api/Template/Util/__init__.py +++ b/StreamingCommunity/Api/Template/Util/__init__.py @@ -2,4 +2,11 @@ from .recall_search import execute_search from .get_domain import search_domain -from .manage_ep import manage_selection, map_episode_title, validate_episode_selection, validate_selection, dynamic_format_number \ No newline at end of file +from .manage_ep import ( + manage_selection, + map_episode_title, + validate_episode_selection, + validate_selection, + dynamic_format_number, + display_episodes_list +) \ No newline at end of file diff --git a/StreamingCommunity/Api/Template/Util/manage_ep.py b/StreamingCommunity/Api/Template/Util/manage_ep.py index d420b13..808434e 100644 --- a/StreamingCommunity/Api/Template/Util/manage_ep.py +++ b/StreamingCommunity/Api/Template/Util/manage_ep.py @@ -1,12 +1,15 @@ # 19.06.24 +import sys import logging from typing import List # Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager +from StreamingCommunity.Util.console import console from StreamingCommunity.Util.os import os_manager +from StreamingCommunity.Util._jsonConfig import config_manager +from StreamingCommunity.Util.table import TVShowManager # Config @@ -176,4 +179,45 @@ def validate_episode_selection(list_episode_select: List[int], episodes_count: i # Prompt the user for valid input again input_episodes = input(f"Enter valid episode numbers (1-{episodes_count}): ") - list_episode_select = list(map(int, input_episodes.split(','))) \ No newline at end of file + list_episode_select = list(map(int, input_episodes.split(','))) + +def display_episodes_list(episodes_manager) -> str: + """ + Display episodes list and handle user input. + + Returns: + last_command (str): Last command entered by the user. + """ + # Set up table for displaying episodes + table_show_manager = TVShowManager() + table_show_manager.set_slice_end(10) + + # Add columns to the table + column_info = { + "Index": {'color': 'red'}, + "Name": {'color': 'magenta'}, + "Duration": {'color': 'blue'} + } + table_show_manager.add_column(column_info) + + # Populate the table with episodes information + for i, media in enumerate(episodes_manager): + name = media.get('name') if isinstance(media, dict) else getattr(media, 'name', None) + duration = media.get('duration') if isinstance(media, dict) else getattr(media, 'duration', None) + + episode_info = { + 'Index': str(i + 1), + 'Name': name, + 'Duration': duration + } + + table_show_manager.add_tv_show(episode_info) + + # Run the table and handle user input + last_command = table_show_manager.run() + + if last_command in ("q", "quit"): + console.print("\n[red]Quit [white]...") + sys.exit(0) + + return last_command \ No newline at end of file diff --git a/StreamingCommunity/Lib/Downloader/HLS/segments.py b/StreamingCommunity/Lib/Downloader/HLS/segments.py index 1c9c8ce..f03348b 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/segments.py +++ b/StreamingCommunity/Lib/Downloader/HLS/segments.py @@ -93,7 +93,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() @@ -208,7 +207,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 @@ -310,6 +309,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 @@ -325,6 +326,7 @@ class M3U8_Segments: - type (str): Type of download: 'video' or 'audio' """ if TELEGRAM_BOT: + # Viene usato per lo screen console.log("####") @@ -336,7 +338,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..0647880 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,37 @@ 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. diff --git a/config.json b/config.json index 45017d6..346e918 100644 --- a/config.json +++ b/config.json @@ -65,7 +65,7 @@ "domain": "pro" }, "guardaserie": { - "domain": "meme" + "domain": "now" }, "mostraguarda": { "domain": "stream" @@ -82,7 +82,7 @@ "domain": "so" }, "cb01new": { - "domain": "media" + "domain": "gold" }, "1337xx": { "domain": "to"