From 38cf30f9772dc1460b1ffdf6db8bb2f4c21db3ed Mon Sep 17 00:00:00 2001 From: Dark1291 Date: Wed, 12 Feb 2025 09:42:38 +0100 Subject: [PATCH] Remove constant --- .../Api/Site/1337xx/__init__.py | 4 +- StreamingCommunity/Api/Site/1337xx/costant.py | 15 ---- StreamingCommunity/Api/Site/1337xx/site.py | 10 +-- StreamingCommunity/Api/Site/1337xx/title.py | 8 +-- .../Site/altadefinizionegratis/__init__.py | 8 +-- .../Api/Site/altadefinizionegratis/costant.py | 21 ------ .../Api/Site/animeunity/__init__.py | 8 +-- .../Api/Site/animeunity/costant.py | 21 ------ .../Api/Site/cb01new/__init__.py | 4 +- .../Api/Site/cb01new/costant.py | 19 ----- StreamingCommunity/Api/Site/cb01new/film.py | 6 +- StreamingCommunity/Api/Site/cb01new/site.py | 8 +-- .../Api/Site/ddlstreamitaly/__init__.py | 4 +- .../Api/Site/ddlstreamitaly/costant.py | 20 ------ .../Api/Site/ddlstreamitaly/series.py | 13 ++-- .../Api/Site/ddlstreamitaly/site.py | 14 ++-- .../Site/ddlstreamitaly/util/ScrapeSerie.py | 4 +- .../Api/Site/guardaserie/__init__.py | 4 +- .../Api/Site/guardaserie/costant.py | 19 ----- .../Api/Site/ilcorsaronero/__init__.py | 4 +- .../Api/Site/ilcorsaronero/costant.py | 19 ----- .../Api/Site/ilcorsaronero/site.py | 8 +-- .../Api/Site/ilcorsaronero/title.py | 8 +-- .../Api/Site/mostraguarda/__init__.py | 4 +- .../Api/Site/mostraguarda/costant.py | 19 ----- .../Api/Site/mostraguarda/film.py | 11 ++- .../Api/Site/streamingcommunity/__init__.py | 8 +-- .../Api/Site/streamingcommunity/costant.py | 21 ------ .../Api/Site/streamingcommunity/film.py | 13 ++-- .../Api/Site/streamingcommunity/series.py | 19 +++-- .../Api/Site/streamingcommunity/site.py | 24 +++---- .../Api/Template/config_loader.py | 71 +++++++++++++++++++ 32 files changed, 156 insertions(+), 283 deletions(-) delete mode 100644 StreamingCommunity/Api/Site/1337xx/costant.py delete mode 100644 StreamingCommunity/Api/Site/altadefinizionegratis/costant.py delete mode 100644 StreamingCommunity/Api/Site/animeunity/costant.py delete mode 100644 StreamingCommunity/Api/Site/cb01new/costant.py delete mode 100644 StreamingCommunity/Api/Site/ddlstreamitaly/costant.py delete mode 100644 StreamingCommunity/Api/Site/guardaserie/costant.py delete mode 100644 StreamingCommunity/Api/Site/ilcorsaronero/costant.py delete mode 100644 StreamingCommunity/Api/Site/mostraguarda/costant.py delete mode 100644 StreamingCommunity/Api/Site/streamingcommunity/costant.py create mode 100644 StreamingCommunity/Api/Template/config_loader.py diff --git a/StreamingCommunity/Api/Site/1337xx/__init__.py b/StreamingCommunity/Api/Site/1337xx/__init__.py index 5025335..e16f109 100644 --- a/StreamingCommunity/Api/Site/1337xx/__init__.py +++ b/StreamingCommunity/Api/Site/1337xx/__init__.py @@ -9,6 +9,7 @@ from StreamingCommunity.Api.Template import get_select_title # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from .site import title_search, media_search_manager, table_show_manager from .title import download_title @@ -19,7 +20,6 @@ _useFor = "film_serie" _deprecate = False _priority = 2 _engineDownload = "tor" -from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -27,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): Main function of the application for film and series. """ if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = title_search(quote_plus(string_to_search)) diff --git a/StreamingCommunity/Api/Site/1337xx/costant.py b/StreamingCommunity/Api/Site/1337xx/costant.py deleted file mode 100644 index c4bd929..0000000 --- a/StreamingCommunity/Api/Site/1337xx/costant.py +++ /dev/null @@ -1,15 +0,0 @@ -# 09.06.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -SERIES_FOLDER = config_manager.get('DEFAULT', 'serie_folder_name') -MOVIE_FOLDER = config_manager.get('DEFAULT', 'movie_folder_name') \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/1337xx/site.py b/StreamingCommunity/Api/Site/1337xx/site.py index a30db3a..4941df5 100644 --- a/StreamingCommunity/Api/Site/1337xx/site.py +++ b/StreamingCommunity/Api/Site/1337xx/site.py @@ -13,12 +13,12 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager # Variable -from .costant import SITE_NAME, DOMAIN_NOW media_search_manager = MediaManager() table_show_manager = TVShowManager() max_timeout = config_manager.get_int("REQUESTS", "timeout") @@ -39,15 +39,15 @@ def title_search(word_to_search: str) -> int: table_show_manager.clear() # Find new domain if prev dont work - domain_to_use = DOMAIN_NOW + domain_to_use = site_constant.DOMAIN_NOW if not disable_searchDomain: - domain_to_use, base_url = search_domain(SITE_NAME, f"https://{SITE_NAME}.{DOMAIN_NOW}") + domain_to_use, base_url = search_domain(site_constant.SITE_NAME, f"https://{site_constant.SITE_NAME}.{site_constant.DOMAIN_NOW}") # Construct the full site URL and load the search page try: response = httpx.get( - url=f"https://{SITE_NAME}.{domain_to_use}/search/{word_to_search}/1/", + url=f"https://{site_constant.SITE_NAME}.{domain_to_use}/search/{word_to_search}/1/", headers={'user-agent': get_headers()}, follow_redirects=True, timeout=max_timeout @@ -55,7 +55,7 @@ def title_search(word_to_search: str) -> int: response.raise_for_status() except Exception as e: - console.print(f"Site: {SITE_NAME}, request search error: {e}") + console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") # Create soup and find table soup = BeautifulSoup(response.text, "html.parser") diff --git a/StreamingCommunity/Api/Site/1337xx/title.py b/StreamingCommunity/Api/Site/1337xx/title.py index c0fd43e..e757878 100644 --- a/StreamingCommunity/Api/Site/1337xx/title.py +++ b/StreamingCommunity/Api/Site/1337xx/title.py @@ -17,12 +17,10 @@ from StreamingCommunity.Lib.Downloader import TOR_downloader # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Class.SearchType import MediaItem -# Config -from .costant import DOMAIN_NOW, SITE_NAME, MOVIE_FOLDER - def download_title(select_title: MediaItem): """ @@ -37,13 +35,13 @@ def download_title(select_title: MediaItem): # Define output path title_name = os_manager.get_sanitize_file(select_title.name) - mp4_path = os.path.join(MOVIE_FOLDER, title_name.replace(".mp4", "")) + mp4_path = os.path.join(site_constant.MOVIE_FOLDER, title_name.replace(".mp4", "")) # Create output folder os_manager.create_path(mp4_path) # Make request to page with magnet - full_site_name = f"{SITE_NAME}.{DOMAIN_NOW}" + full_site_name = f"{site_constant.SITE_NAME}.{site_constant.DOMAIN_NOW}" response = httpx.get( url="https://" + full_site_name + select_title.url, headers={ diff --git a/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py b/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py index 30ca58a..b4e2214 100644 --- a/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py +++ b/StreamingCommunity/Api/Site/altadefinizionegratis/__init__.py @@ -12,6 +12,7 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from .site import title_search, media_search_manager, table_show_manager from .film import download_film @@ -22,14 +23,13 @@ _useFor = "film" _deprecate = False _priority = 2 _engineDownload = "hls" -from .costant import SITE_NAME, TELEGRAM_BOT def search(string_to_search: str = None, get_onylDatabase: bool = False): """ Main function of the application for film and series. """ - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot = get_bot_instance() if string_to_search is None: @@ -49,7 +49,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): else: if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = title_search(quote_plus(string_to_search)) @@ -67,7 +67,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): download_film(select_title) else: - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot.send_message(f"Nessun risultato trovato riprova", None) console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}") diff --git a/StreamingCommunity/Api/Site/altadefinizionegratis/costant.py b/StreamingCommunity/Api/Site/altadefinizionegratis/costant.py deleted file mode 100644 index e4d4d9a..0000000 --- a/StreamingCommunity/Api/Site/altadefinizionegratis/costant.py +++ /dev/null @@ -1,21 +0,0 @@ -# 26.05.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -SERIES_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'serie_folder_name')) -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - SERIES_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'serie_folder_name')) - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) - -TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot') \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/animeunity/__init__.py b/StreamingCommunity/Api/Site/animeunity/__init__.py index 87f5741..a2f0b2e 100644 --- a/StreamingCommunity/Api/Site/animeunity/__init__.py +++ b/StreamingCommunity/Api/Site/animeunity/__init__.py @@ -11,6 +11,7 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from .site import title_search, media_search_manager, table_show_manager from .film_serie import download_film, download_series @@ -21,12 +22,11 @@ _useFor = "anime" _deprecate = False _priority = 2 _engineDownload = "mp4" -from .costant import SITE_NAME, TELEGRAM_BOT def search(string_to_search: str = None, get_onylDatabase: bool = False): - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot = get_bot_instance() if string_to_search is None: @@ -46,7 +46,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): else: if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = title_search(string_to_search) @@ -67,7 +67,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): download_series(select_title) else: - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot.send_message(f"Nessun risultato trovato riprova", None) console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}") diff --git a/StreamingCommunity/Api/Site/animeunity/costant.py b/StreamingCommunity/Api/Site/animeunity/costant.py deleted file mode 100644 index 1702282..0000000 --- a/StreamingCommunity/Api/Site/animeunity/costant.py +++ /dev/null @@ -1,21 +0,0 @@ -# 26.05.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) -ANIME_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'anime_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) - ANIME_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'anime_folder_name')) - -TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot') \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/cb01new/__init__.py b/StreamingCommunity/Api/Site/cb01new/__init__.py index 641a4be..fdbe5ed 100644 --- a/StreamingCommunity/Api/Site/cb01new/__init__.py +++ b/StreamingCommunity/Api/Site/cb01new/__init__.py @@ -9,6 +9,7 @@ from StreamingCommunity.Api.Template import get_select_title # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from .site import title_search, media_search_manager, table_show_manager from .film import download_film @@ -19,7 +20,6 @@ _useFor = "film" _deprecate = False _priority = 2 _engineDownload = "mp4" -from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -28,7 +28,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = title_search(quote_plus(string_to_search)) diff --git a/StreamingCommunity/Api/Site/cb01new/costant.py b/StreamingCommunity/Api/Site/cb01new/costant.py deleted file mode 100644 index 72d34e9..0000000 --- a/StreamingCommunity/Api/Site/cb01new/costant.py +++ /dev/null @@ -1,19 +0,0 @@ -# 03.07.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -SERIES_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'serie_folder_name')) -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - SERIES_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'serie_folder_name')) - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) diff --git a/StreamingCommunity/Api/Site/cb01new/film.py b/StreamingCommunity/Api/Site/cb01new/film.py index 8c89f27..949c3bb 100644 --- a/StreamingCommunity/Api/Site/cb01new/film.py +++ b/StreamingCommunity/Api/Site/cb01new/film.py @@ -11,6 +11,7 @@ from StreamingCommunity.Lib.Downloader import HLS_Downloader # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Class.SearchType import MediaItem @@ -18,9 +19,6 @@ from StreamingCommunity.Api.Template.Class.SearchType import MediaItem from StreamingCommunity.Api.Player.maxstream import VideoSource -# Config -from .costant import MOVIE_FOLDER - def download_film(select_title: MediaItem) -> str: """ @@ -40,7 +38,7 @@ def download_film(select_title: MediaItem) -> str: # Define output path title_name = os_manager.get_sanitize_file(select_title.name) +".mp4" - mp4_path = os.path.join(MOVIE_FOLDER, title_name.replace(".mp4", "")) + mp4_path = os.path.join(site_constant.MOVIE_FOLDER, title_name.replace(".mp4", "")) # Get m3u8 master playlist master_playlist = video_source.get_playlist() diff --git a/StreamingCommunity/Api/Site/cb01new/site.py b/StreamingCommunity/Api/Site/cb01new/site.py index 8ca838a..bf13737 100644 --- a/StreamingCommunity/Api/Site/cb01new/site.py +++ b/StreamingCommunity/Api/Site/cb01new/site.py @@ -12,12 +12,12 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager # Variable -from .costant import SITE_NAME, DOMAIN_NOW media_search_manager = MediaManager() table_show_manager = TVShowManager() max_timeout = config_manager.get_int("REQUESTS", "timeout") @@ -38,13 +38,13 @@ def title_search(word_to_search: str) -> int: table_show_manager.clear() # Find new domain if prev dont work - domain_to_use = DOMAIN_NOW + domain_to_use = site_constant.DOMAIN_NOW if not disable_searchDomain: - domain_to_use, base_url = search_domain(SITE_NAME, f"https://{SITE_NAME}.{DOMAIN_NOW}") + domain_to_use, base_url = search_domain(site_constant.SITE_NAME, f"https://{site_constant.SITE_NAME}.{site_constant.DOMAIN_NOW}") response = httpx.get( - url=f"https://{SITE_NAME}.{domain_to_use}/?s={word_to_search}", + url=f"https://{site_constant.SITE_NAME}.{domain_to_use}/?s={word_to_search}", headers={'user-agent': get_headers()}, timeout=max_timeout ) diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py b/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py index f9864a4..69bb417 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py @@ -10,6 +10,7 @@ from StreamingCommunity.Api.Template import get_select_title # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from .site import title_search, media_search_manager, table_show_manager from .series import download_thread @@ -20,7 +21,6 @@ _useFor = "serie" _deprecate = False _priority = 2 _engineDownload = "mp4" -from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -29,7 +29,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = title_search(quote_plus(string_to_search)) diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/costant.py b/StreamingCommunity/Api/Site/ddlstreamitaly/costant.py deleted file mode 100644 index 576ad37..0000000 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/costant.py +++ /dev/null @@ -1,20 +0,0 @@ -# 09.06.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] -COOKIE = config_manager.get_dict('SITE', SITE_NAME)['extra'] - -SERIES_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'serie_folder_name')) -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - SERIES_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'serie_folder_name')) - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/series.py b/StreamingCommunity/Api/Site/ddlstreamitaly/series.py index 6e81454..d71f705 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/series.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/series.py @@ -20,6 +20,7 @@ from StreamingCommunity.Api.Template.Util import ( validate_episode_selection, display_episodes_list ) +from StreamingCommunity.Api.Template.config_loader import site_constant # Player @@ -27,10 +28,6 @@ from .util.ScrapeSerie import GetSerieInfo from StreamingCommunity.Api.Player.ddl import VideoSource -# Variable -from .costant import SERIES_FOLDER - - def download_video(index_episode_selected: int, scape_info_serie: GetSerieInfo, video_source: VideoSource) -> Tuple[str,bool]: """ @@ -54,7 +51,7 @@ def download_video(index_episode_selected: int, scape_info_serie: GetSerieInfo, title_name = os_manager.get_sanitize_file( f"{map_episode_title(scape_info_serie.tv_name, None, index_episode_selected, obj_episode.get('name'))}.mp4" ) - mp4_path = os.path.join(SERIES_FOLDER, scape_info_serie.tv_name) + mp4_path = os.path.join(site_constant.SERIES_FOLDER, scape_info_serie.tv_name) # Create output folder os_manager.create_path(mp4_path) @@ -86,8 +83,6 @@ def download_thread(dict_serie: MediaItem): """ Download all episode of a thread """ - - # Start message and set up video source start_message() # Init class @@ -104,6 +99,7 @@ def download_thread(dict_serie: MediaItem): try: list_episode_select = validate_episode_selection(list_episode_select, episodes_count) + except ValueError as e: console.print(f"[red]{str(e)}") return @@ -113,4 +109,5 @@ def download_thread(dict_serie: MediaItem): for i_episode in list_episode_select: if kill_handler: break - kill_handler = download_video(i_episode, scape_info_serie, video_source)[1] + + kill_handler = download_video(i_episode, scape_info_serie, video_source)[1] \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py index 70817be..834a9bf 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py @@ -16,12 +16,12 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager # Variable -from .costant import SITE_NAME, DOMAIN_NOW media_search_manager = MediaManager() table_show_manager = TVShowManager() max_timeout = config_manager.get_int("REQUESTS", "timeout") @@ -42,22 +42,22 @@ def title_search(word_to_search: str) -> int: table_show_manager.clear() # Find new domain if prev dont work - domain_to_use = DOMAIN_NOW + domain_to_use = site_constant.DOMAIN_NOW if not disable_searchDomain: - domain_to_use, base_url = search_domain(SITE_NAME, f"https://{SITE_NAME}.{DOMAIN_NOW}") + domain_to_use, base_url = search_domain(site_constant.SITE_NAME, f"https://{site_constant.SITE_NAME}.{site_constant.DOMAIN_NOW}") # Send request to search for titles try: response = httpx.get( - url=f"https://{SITE_NAME}.{domain_to_use}/search/?&q={word_to_search}&quick=1&type=videobox_video&nodes=11", + url=f"https://{site_constant.SITE_NAME}.{domain_to_use}/search/?&q={word_to_search}&quick=1&type=videobox_video&nodes=11", headers={'user-agent': get_headers()}, timeout=max_timeout ) response.raise_for_status() except Exception as e: - console.print(f"Site: {SITE_NAME}, request search error: {e}") + console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") # Create soup and find table soup = BeautifulSoup(response.text, "html.parser") @@ -86,6 +86,4 @@ def title_search(word_to_search: str) -> int: else: logging.error("No table content found.") - return -999 - - return -9999 \ No newline at end of file + return -999 \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py b/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py index a3b4ad4..8cbaffa 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py @@ -16,11 +16,11 @@ from StreamingCommunity.Util.headers import get_headers # Logic class +from ..site import site_constant from StreamingCommunity.Api.Template.Class.SearchType import MediaItem # Variable -from ..costant import COOKIE max_timeout = config_manager.get_int("REQUESTS", "timeout") @@ -33,7 +33,7 @@ class GetSerieInfo: - dict_serie (MediaItem): Dictionary containing series information (optional). """ self.headers = {'user-agent': get_headers()} - self.cookies = COOKIE + self.cookies = site_constant.COOKIE self.url = dict_serie.url self.tv_name = None self.list_episodes = None diff --git a/StreamingCommunity/Api/Site/guardaserie/__init__.py b/StreamingCommunity/Api/Site/guardaserie/__init__.py index 89a24b9..4bc4520 100644 --- a/StreamingCommunity/Api/Site/guardaserie/__init__.py +++ b/StreamingCommunity/Api/Site/guardaserie/__init__.py @@ -9,6 +9,7 @@ from StreamingCommunity.Api.Template import get_select_title # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from .site import title_search, media_search_manager, table_show_manager from .series import download_series @@ -19,7 +20,6 @@ _useFor = "serie" _deprecate = False _priority = 2 _engineDownload = "hls" -from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -28,7 +28,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = title_search(quote_plus(string_to_search)) diff --git a/StreamingCommunity/Api/Site/guardaserie/costant.py b/StreamingCommunity/Api/Site/guardaserie/costant.py deleted file mode 100644 index 9ce5286..0000000 --- a/StreamingCommunity/Api/Site/guardaserie/costant.py +++ /dev/null @@ -1,19 +0,0 @@ -# 09.06.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -SERIES_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'serie_folder_name')) -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - SERIES_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'serie_folder_name')) - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) diff --git a/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py b/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py index 1dc3214..a949631 100644 --- a/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py +++ b/StreamingCommunity/Api/Site/ilcorsaronero/__init__.py @@ -10,6 +10,7 @@ from StreamingCommunity.Api.Template import get_select_title # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from .site import title_search, media_search_manager, table_show_manager from .title import download_title @@ -20,7 +21,6 @@ _useFor = "film_serie" _deprecate = False _priority = 2 _engineDownload = "tor" -from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -29,7 +29,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Search on database len_database = asyncio.run(title_search(quote_plus(string_to_search))) diff --git a/StreamingCommunity/Api/Site/ilcorsaronero/costant.py b/StreamingCommunity/Api/Site/ilcorsaronero/costant.py deleted file mode 100644 index fefb15d..0000000 --- a/StreamingCommunity/Api/Site/ilcorsaronero/costant.py +++ /dev/null @@ -1,19 +0,0 @@ -# 09.06.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -SERIES_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'serie_folder_name')) -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - SERIES_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'serie_folder_name')) - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/ilcorsaronero/site.py b/StreamingCommunity/Api/Site/ilcorsaronero/site.py index 827e5cd..e76936b 100644 --- a/StreamingCommunity/Api/Site/ilcorsaronero/site.py +++ b/StreamingCommunity/Api/Site/ilcorsaronero/site.py @@ -7,13 +7,13 @@ from StreamingCommunity.Util.table import TVShowManager # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager from .util.ilCorsarScraper import IlCorsaroNeroScraper # Variable -from .costant import SITE_NAME, DOMAIN_NOW media_search_manager = MediaManager() table_show_manager = TVShowManager() max_timeout = config_manager.get_int("REQUESTS", "timeout") @@ -34,14 +34,14 @@ async def title_search(word_to_search: str) -> int: table_show_manager.clear() # Find new domain if prev dont work - domain_to_use = DOMAIN_NOW + domain_to_use = site_constant.DOMAIN_NOW if not disable_searchDomain: - domain_to_use, base_url = search_domain(SITE_NAME, f"https://{SITE_NAME}.{DOMAIN_NOW}") + domain_to_use, base_url = search_domain(site_constant.SITE_NAME, f"https://{site_constant.SITE_NAME}.{site_constant.DOMAIN_NOW}") # Create scraper and collect result print("\n") - scraper = IlCorsaroNeroScraper(f"https://{SITE_NAME}.{domain_to_use}/", 1) + scraper = IlCorsaroNeroScraper(f"https://{site_constant.SITE_NAME}.{domain_to_use}/", 1) results = await scraper.search(word_to_search) for i, torrent in enumerate(results): diff --git a/StreamingCommunity/Api/Site/ilcorsaronero/title.py b/StreamingCommunity/Api/Site/ilcorsaronero/title.py index e32af4d..3c28164 100644 --- a/StreamingCommunity/Api/Site/ilcorsaronero/title.py +++ b/StreamingCommunity/Api/Site/ilcorsaronero/title.py @@ -11,12 +11,10 @@ from StreamingCommunity.Lib.Downloader import TOR_downloader # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Class.SearchType import MediaItem -# Config -from .costant import MOVIE_FOLDER - def download_title(select_title: MediaItem): """ @@ -32,7 +30,7 @@ def download_title(select_title: MediaItem): # Define output path title_name = os_manager.get_sanitize_file(select_title.name) - mp4_path = os.path.join(MOVIE_FOLDER, title_name.replace(".mp4", "")) + mp4_path = os.path.join(site_constant.MOVIE_FOLDER, title_name.replace(".mp4", "")) # Create output folder os_manager.create_path(mp4_path) @@ -41,4 +39,4 @@ def download_title(select_title: MediaItem): manager = TOR_downloader() manager.add_magnet_link(select_title.url) manager.start_download() - manager.move_downloaded_files(mp4_path) + manager.move_downloaded_files(mp4_path) \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/mostraguarda/__init__.py b/StreamingCommunity/Api/Site/mostraguarda/__init__.py index 3d1a7d1..a9cf4e4 100644 --- a/StreamingCommunity/Api/Site/mostraguarda/__init__.py +++ b/StreamingCommunity/Api/Site/mostraguarda/__init__.py @@ -8,6 +8,7 @@ from StreamingCommunity.Util.console import console, msg # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Lib.TMBD import tmdb, Json_film from .film import download_film @@ -18,7 +19,6 @@ _useFor = "film" _deprecate = False _priority = 2 _engineDownload = "hls" -from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -27,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{SITE_NAME}").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [green]{site_constant.SITE_NAME}").strip() # Not available for the moment if get_onylDatabase: diff --git a/StreamingCommunity/Api/Site/mostraguarda/costant.py b/StreamingCommunity/Api/Site/mostraguarda/costant.py deleted file mode 100644 index cb76a8b..0000000 --- a/StreamingCommunity/Api/Site/mostraguarda/costant.py +++ /dev/null @@ -1,19 +0,0 @@ -# 26.05.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -SERIES_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'serie_folder_name')) -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - SERIES_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'serie_folder_name')) - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/mostraguarda/film.py b/StreamingCommunity/Api/Site/mostraguarda/film.py index 746886d..0ae4124 100644 --- a/StreamingCommunity/Api/Site/mostraguarda/film.py +++ b/StreamingCommunity/Api/Site/mostraguarda/film.py @@ -22,14 +22,11 @@ from StreamingCommunity.Lib.Downloader import HLS_Downloader from StreamingCommunity.Api.Player.supervideo import VideoSource -# TMBD +# Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Lib.TMBD import Json_film -# Config -from .costant import SITE_NAME, DOMAIN_NOW, MOVIE_FOLDER - - def download_film(movie_details: Json_film) -> str: """ Downloads a film using the provided tmbd id. @@ -47,7 +44,7 @@ def download_film(movie_details: Json_film) -> str: # Make request to main site try: - url = f"https://{SITE_NAME}.{DOMAIN_NOW}/set-movie-a/{movie_details.imdb_id}" + url = f"https://{site_constant.SITE_NAME}.{site_constant.DOMAIN_NOW}/set-movie-a/{movie_details.imdb_id}" response = httpx.get(url, headers={'User-Agent': get_headers()}) response.raise_for_status() @@ -69,7 +66,7 @@ def download_film(movie_details: Json_film) -> str: # Define output path title_name = os_manager.get_sanitize_file(movie_details.title) + ".mp4" - mp4_path = os.path.join(MOVIE_FOLDER, title_name.replace(".mp4", "")) + mp4_path = os.path.join(site_constant.MOVIE_FOLDER, title_name.replace(".mp4", "")) # Get m3u8 master playlist master_playlist = video_source.get_playlist() diff --git a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py index afab8cb..bbba379 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py @@ -12,6 +12,7 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant 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 @@ -23,14 +24,13 @@ _useFor = "film_serie" _deprecate = False _priority = 1 _engineDownload = "hls" -from .costant import SITE_NAME, TELEGRAM_BOT def search(string_to_search: str = None, get_onylDatabase: bool = False): """ Main function of the application for film and series. """ - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot = get_bot_instance() if string_to_search is None: @@ -74,8 +74,8 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): else: console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}") - if TELEGRAM_BOT: - bot.send_message(f"Nessun risultato trovato riprova", None) + if site_constant.TELEGRAM_BOT: + bot.send_message(f"Nessun risultato trovato riprova", None) # Retry search() \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/streamingcommunity/costant.py b/StreamingCommunity/Api/Site/streamingcommunity/costant.py deleted file mode 100644 index bb5f066..0000000 --- a/StreamingCommunity/Api/Site/streamingcommunity/costant.py +++ /dev/null @@ -1,21 +0,0 @@ -# 26.05.24 - -import os - - -# Internal utilities -from StreamingCommunity.Util._jsonConfig import config_manager - - -SITE_NAME = os.path.basename(os.path.dirname(os.path.abspath(__file__))) -ROOT_PATH = config_manager.get('DEFAULT', 'root_path') -DOMAIN_NOW = config_manager.get_dict('SITE', SITE_NAME)['domain'] - -SERIES_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'serie_folder_name')) -MOVIE_FOLDER = os.path.join(ROOT_PATH, config_manager.get('DEFAULT', 'movie_folder_name')) - -if config_manager.get_bool("DEFAULT", "add_siteName"): - SERIES_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'serie_folder_name')) - MOVIE_FOLDER = os.path.join(ROOT_PATH, SITE_NAME, config_manager.get('DEFAULT', 'movie_folder_name')) - -TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot') \ No newline at end of file diff --git a/StreamingCommunity/Api/Site/streamingcommunity/film.py b/StreamingCommunity/Api/Site/streamingcommunity/film.py index 7b6ab8c..eab7e53 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/film.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/film.py @@ -12,6 +12,7 @@ from StreamingCommunity.TelegramHelp.telegram_bot import TelegramSession, get_bo # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Class.SearchType import MediaItem @@ -19,10 +20,6 @@ from StreamingCommunity.Api.Template.Class.SearchType import MediaItem from StreamingCommunity.Api.Player.vixcloud import VideoSource -# Variable -from .costant import SITE_NAME, MOVIE_FOLDER, TELEGRAM_BOT - - def download_film(select_title: MediaItem) -> str: """ Downloads a film using the provided film ID, title name, and domain. @@ -34,7 +31,7 @@ def download_film(select_title: MediaItem) -> str: Return: - str: output path """ - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot = get_bot_instance() bot.send_message(f"Download in corso:\n{select_title.name}", None) @@ -51,7 +48,7 @@ def download_film(select_title: MediaItem) -> str: console.print(f"[yellow]Download: [red]{select_title.name} \n") # Init class - video_source = VideoSource(SITE_NAME, False) + video_source = VideoSource(site_constant.SITE_NAME, False) video_source.setup(select_title.id) # Retrieve scws and if available master playlist @@ -61,7 +58,7 @@ def download_film(select_title: MediaItem) -> str: # Define the filename and path for the downloaded film title_name = os_manager.get_sanitize_file(select_title.name) + ".mp4" - mp4_path = os.path.join(MOVIE_FOLDER, title_name.replace(".mp4", "")) + mp4_path = os.path.join(site_constant.MOVIE_FOLDER, title_name.replace(".mp4", "")) # Download the film using the m3u8 playlist, and output filename r_proc = HLS_Downloader( @@ -69,7 +66,7 @@ def download_film(select_title: MediaItem) -> str: output_path=os.path.join(mp4_path, title_name) ).start() - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: # Delete script_id script_id = TelegramSession.get_session() diff --git a/StreamingCommunity/Api/Site/streamingcommunity/series.py b/StreamingCommunity/Api/Site/streamingcommunity/series.py index a4422d2..013faab 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/series.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/series.py @@ -20,6 +20,7 @@ from StreamingCommunity.Api.Template.Util import ( validate_episode_selection, display_episodes_list ) +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Class.SearchType import MediaItem @@ -27,10 +28,6 @@ from StreamingCommunity.Api.Template.Class.SearchType import MediaItem from StreamingCommunity.Api.Player.vixcloud import VideoSource -# Variable -from .costant import SITE_NAME, SERIES_FOLDER, TELEGRAM_BOT - - def download_video(index_season_selected: int, index_episode_selected: int, scrape_serie: ScrapeSerie, video_source: VideoSource) -> Tuple[str,bool]: """ Download a single episode video. @@ -51,7 +48,7 @@ def download_video(index_season_selected: int, index_episode_selected: int, scra console.print(f"[yellow]Download: [red]{index_season_selected}:{index_episode_selected} {obj_episode.name}") print() - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot = get_bot_instance() # Invio a telegram @@ -67,7 +64,7 @@ def download_video(index_season_selected: int, index_episode_selected: int, scra # Define filename and path for the downloaded video mp4_name = f"{map_episode_title(scrape_serie.series_name, index_season_selected, index_episode_selected, obj_episode.name)}.mp4" - mp4_path = os.path.join(SERIES_FOLDER, scrape_serie.series_name, f"S{index_season_selected}") + mp4_path = os.path.join(site_constant.SERIES_FOLDER, scrape_serie.series_name, f"S{index_season_selected}") # Retrieve scws and if available master playlist video_source.get_iframe(obj_episode.id) @@ -144,15 +141,15 @@ def download_series(select_season: MediaItem, version: str) -> None: - domain (str): Domain from which to download. - version (str): Version of the site. """ - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot = get_bot_instance() # Start message and set up video source start_message() # Init class - scrape_serie = ScrapeSerie(SITE_NAME) - video_source = VideoSource(SITE_NAME, True) + scrape_serie = ScrapeSerie(site_constant.SITE_NAME) + video_source = VideoSource(site_constant.SITE_NAME, True) # Setup video source scrape_serie.setup(version, select_season.id, select_season.slug) @@ -165,7 +162,7 @@ def download_series(select_season: MediaItem, version: str) -> None: # Prompt user for season selection and download episodes console.print(f"\n[green]Seasons found: [red]{seasons_count}") - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: console.print("\n[cyan]Insert season number [yellow](e.g., 1), [red]* [cyan]to download all seasons, " "[yellow](e.g., 1-2) [cyan]for a range of seasons, or [yellow](e.g., 3-*) [cyan]to download from a specific season to the end") @@ -203,7 +200,7 @@ def download_series(select_season: MediaItem, version: str) -> None: # Otherwise, let the user select specific episodes for the single season download_episode(i_season, scrape_serie, video_source, download_all=False) - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot.send_message(f"Finito di scaricare tutte le serie e episodi", None) # Get script_id diff --git a/StreamingCommunity/Api/Site/streamingcommunity/site.py b/StreamingCommunity/Api/Site/streamingcommunity/site.py index ba5b3b3..2a0a7e2 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/site.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/site.py @@ -19,13 +19,11 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance # Logic class +from StreamingCommunity.Api.Template.config_loader import site_constant from StreamingCommunity.Api.Template.Util import search_domain from StreamingCommunity.Api.Template.Class.SearchType import MediaManager -# Config -from .costant import SITE_NAME, DOMAIN_NOW, TELEGRAM_BOT - # Variable media_search_manager = MediaManager() @@ -46,7 +44,7 @@ def get_version(domain: str): """ try: response = httpx.get( - url=f"https://{SITE_NAME}.{domain}/", + url=f"https://{site_constant.SITE_NAME}.{domain}/", headers={'User-Agent': get_headers()}, timeout=max_timeout ) @@ -74,12 +72,10 @@ def get_version_and_domain(): - Determines the correct domain to use for the site by searching for a specific meta tag. - Fetches the content of the site to extract the version information. """ - - # Find new domain if prev dont work - domain_to_use = DOMAIN_NOW + domain_to_use = site_constant if not disable_searchDomain: - domain_to_use, base_url = search_domain(SITE_NAME, f"https://{SITE_NAME}.{DOMAIN_NOW}") + domain_to_use, base_url = search_domain(site_constant.SITE_NAME, f"https://{site_constant.SITE_NAME}.{site_constant.DOMAIN_NOW}") try: version = get_version(domain_to_use) @@ -102,7 +98,7 @@ def title_search(title_search: str, domain: str) -> int: Returns: int: The number of titles found. """ - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: bot = get_bot_instance() media_search_manager.clear() @@ -110,17 +106,17 @@ def title_search(title_search: str, domain: str) -> int: try: response = httpx.get( - url=f"https://{SITE_NAME}.{domain}/api/search?q={title_search.replace(' ', '+')}", + url=f"https://{site_constant.SITE_NAME}.{domain}/api/search?q={title_search.replace(' ', '+')}", headers={'user-agent': get_headers()}, timeout=max_timeout ) response.raise_for_status() except Exception as e: - console.print(f"Site: {SITE_NAME}, request search error: {e}") + console.print(f"Site: {site_constant.SITE_NAME}, request search error: {e}") # Prepara le scelte per l'utente - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: choices = [] for i, dict_title in enumerate(response.json()['data']): @@ -134,14 +130,14 @@ def title_search(title_search: str, domain: str) -> int: 'score': dict_title.get('score') }) - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: choice_text = f"{i} - {dict_title.get('name')} ({dict_title.get('type')}) - {dict_title.get('last_air_date')}" choices.append(choice_text) except Exception as e: print(f"Error parsing a film entry: {e}") - if TELEGRAM_BOT: + if site_constant.TELEGRAM_BOT: if choices: bot.send_message(f"Lista dei risultati:", choices) diff --git a/StreamingCommunity/Api/Template/config_loader.py b/StreamingCommunity/Api/Template/config_loader.py new file mode 100644 index 0000000..3384203 --- /dev/null +++ b/StreamingCommunity/Api/Template/config_loader.py @@ -0,0 +1,71 @@ +# 11.02.25 + +import os +import inspect + + +# Internal utilities +from StreamingCommunity.Util._jsonConfig import config_manager + + +def get_site_name_from_stack(): + for frame_info in inspect.stack(): + file_path = frame_info.filename + + if "__init__" in file_path: + parts = file_path.split(f"Site{os.sep}") + + if len(parts) > 1: + site_name = parts[1].split(os.sep)[0] + return site_name + + return None + + +class SiteConstant: + @property + def SITE_NAME(self): + return get_site_name_from_stack() + + @property + def ROOT_PATH(self): + return config_manager.get('DEFAULT', 'root_path') + + @property + def DOMAIN_NOW(self): + return config_manager.get_dict('SITE', self.SITE_NAME)['domain'] + + @property + def SERIES_FOLDER(self): + base_path = self.ROOT_PATH + if config_manager.get_bool("DEFAULT", "add_siteName"): + base_path = os.path.join(base_path, self.SITE_NAME) + return os.path.join(base_path, config_manager.get('DEFAULT', 'serie_folder_name')) + + @property + def MOVIE_FOLDER(self): + base_path = self.ROOT_PATH + if config_manager.get_bool("DEFAULT", "add_siteName"): + base_path = os.path.join(base_path, self.SITE_NAME) + return os.path.join(base_path, config_manager.get('DEFAULT', 'movie_folder_name')) + + @property + def ANIME_FOLDER(self): + base_path = self.ROOT_PATH + if config_manager.get_bool("DEFAULT", "add_siteName"): + base_path = os.path.join(base_path, self.SITE_NAME) + return os.path.join(base_path, config_manager.get('DEFAULT', 'anime_folder_name')) + + @property + def COOKIE(self): + try: + return config_manager.get_dict('SITE', self.SITE_NAME)['extra'] + except KeyError: + return None + + @property + def TELEGRAM_BOT(self): + return config_manager.get_bool('DEFAULT', 'telegram_bot') + + +site_constant = SiteConstant() \ No newline at end of file