From f4d01a69f3bafc5ffe46c56e4867b3a33e86093c Mon Sep 17 00:00:00 2001 From: Lovi <62809003+Lovi-0@users.noreply.github.com> Date: Wed, 19 Jun 2024 22:41:45 +0200 Subject: [PATCH] Dinamic manage_selection() and map_episode_title() --- .../Core => Template}/Util/manage_ep.py | 2 +- Src/Api/Template/__init__.py | 3 +- Src/Api/animeunity/Core/Util/__init__.py | 6 -- Src/Api/animeunity/Core/Util/manage_ep.py | 74 ------------------ Src/Api/animeunity/anime.py | 2 +- Src/Api/ddlstreamitaly/series.py | 5 +- Src/Api/ddlstreamitaly/site.py | 2 +- Src/Api/guardaserie/Core/Util/manage_ep.py | 71 ------------------ Src/Api/guardaserie/series.py | 3 +- .../streamingcommunity/Core/Util/__init__.py | 6 -- .../streamingcommunity/Core/Util/manage_ep.py | 75 ------------------- Src/Api/streamingcommunity/__init__.py | 7 +- Src/Api/streamingcommunity/film.py | 2 +- Src/Api/streamingcommunity/series.py | 7 +- Src/Api/streamingcommunity/site.py | 1 - Src/Lib/Hls/downloader.py | 2 +- 16 files changed, 17 insertions(+), 251 deletions(-) rename Src/Api/{ddlstreamitaly/Core => Template}/Util/manage_ep.py (99%) delete mode 100644 Src/Api/animeunity/Core/Util/__init__.py delete mode 100644 Src/Api/animeunity/Core/Util/manage_ep.py delete mode 100644 Src/Api/guardaserie/Core/Util/manage_ep.py delete mode 100644 Src/Api/streamingcommunity/Core/Util/__init__.py delete mode 100644 Src/Api/streamingcommunity/Core/Util/manage_ep.py diff --git a/Src/Api/ddlstreamitaly/Core/Util/manage_ep.py b/Src/Api/Template/Util/manage_ep.py similarity index 99% rename from Src/Api/ddlstreamitaly/Core/Util/manage_ep.py rename to Src/Api/Template/Util/manage_ep.py index 06b24fd..09ca8cf 100644 --- a/Src/Api/ddlstreamitaly/Core/Util/manage_ep.py +++ b/Src/Api/Template/Util/manage_ep.py @@ -1,4 +1,4 @@ -# 02.05.24 +# 19.06.24 import logging diff --git a/Src/Api/Template/__init__.py b/Src/Api/Template/__init__.py index 7a99f16..5fd5ea0 100644 --- a/Src/Api/Template/__init__.py +++ b/Src/Api/Template/__init__.py @@ -1,4 +1,5 @@ # 19.06.24 from .site import get_select_title -from .Util.get_domain import search_domain \ No newline at end of file +from .Util.get_domain import search_domain +from .Util.manage_ep import manage_selection, map_episode_title \ No newline at end of file diff --git a/Src/Api/animeunity/Core/Util/__init__.py b/Src/Api/animeunity/Core/Util/__init__.py deleted file mode 100644 index cdee8b4..0000000 --- a/Src/Api/animeunity/Core/Util/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# 21.05.24 - -from .manage_ep import ( - manage_selection, - map_episode_title -) \ No newline at end of file diff --git a/Src/Api/animeunity/Core/Util/manage_ep.py b/Src/Api/animeunity/Core/Util/manage_ep.py deleted file mode 100644 index 331771c..0000000 --- a/Src/Api/animeunity/Core/Util/manage_ep.py +++ /dev/null @@ -1,74 +0,0 @@ -# 02.05.24 - -import logging - -from typing import List - - -# Internal utilities -from Src.Util._jsonConfig import config_manager - - -# Logic class -from ..Class.EpisodeType import Episode - - -# Config -MAP_EPISODE = config_manager.get('DEFAULT', 'map_episode_name') - - -def manage_selection(cmd_insert: str, max_count: int) -> List[int]: - """ - Manage user selection for seasons to download. - - Args: - - cmd_insert (str): User input for season selection. - - max_count (int): Maximum count of seasons available. - - Returns: - list_season_select (List[int]): List of selected seasons. - """ - list_season_select = [] - logging.info(f"Command insert: {cmd_insert}, end index: {max_count + 1}") - - # For a single number (e.g., '5') - if cmd_insert.isnumeric(): - list_season_select.append(int(cmd_insert)) - - # For a range (e.g., '[5-12]') - elif "[" in cmd_insert: - start, end = map(int, cmd_insert[1:-1].split('-')) - list_season_select = list(range(start, end + 1)) - - # For all seasons - elif cmd_insert == "*": - list_season_select = list(range(1, max_count+1)) - - # Return list of selected seasons) - logging.info(f"List return: {list_season_select}") - return list_season_select - - -def map_episode_title(tv_name: str, episode: Episode, number_season: int): - """ - Maps the episode title to a specific format. - - Args: - - tv_name (str): The name of the TV show. - - episode (Episode): The episode object. - - number_season (int): The season number. - - Returns: - str: The mapped episode title. - """ - map_episode_temp = MAP_EPISODE - map_episode_temp = map_episode_temp.replace("%(tv_name)", tv_name) - map_episode_temp = map_episode_temp.replace("%(season)", str(number_season).zfill(2)) - map_episode_temp = map_episode_temp.replace("%(episode)", str(episode.number).zfill(2)) - map_episode_temp = map_episode_temp.replace("%(episode_name)", episode.name) - - # Additional fix - map_episode_temp = map_episode_temp.replace(".", "_") - - logging.info(f"Map episode string return: {map_episode_temp}") - return map_episode_temp diff --git a/Src/Api/animeunity/anime.py b/Src/Api/animeunity/anime.py index 3d597ad..ca1a12c 100644 --- a/Src/Api/animeunity/anime.py +++ b/Src/Api/animeunity/anime.py @@ -8,11 +8,11 @@ import logging from Src.Util.console import console, msg from Src.Lib.Hls.downloader import Downloader from Src.Util.message import start_message +from ..Template import manage_selection # Logic class from .Core.Player.vixcloud import VideoSource -from .Core.Util import manage_selection # Variable diff --git a/Src/Api/ddlstreamitaly/series.py b/Src/Api/ddlstreamitaly/series.py index 8903fdc..6b13077 100644 --- a/Src/Api/ddlstreamitaly/series.py +++ b/Src/Api/ddlstreamitaly/series.py @@ -9,16 +9,16 @@ from urllib.parse import urlparse # Internal utilities from Src.Util.color import Colors from Src.Util.console import console, msg +from Src.Util.message import start_message from Src.Util.os import create_folder, can_create_file from Src.Util.table import TVShowManager -from Src.Util.message import start_message from Src.Lib.Hls.download_mp4 import MP4_downloader +from ..Template import manage_selection, map_episode_title # Logic class from .Core.Class.SearchType import MediaItem from .Core.Class.ScrapeSerie import GetSerieInfo -from .Core.Util.manage_ep import manage_selection, map_episode_title from .Core.Player.ddl import VideoSource @@ -28,6 +28,7 @@ table_show_manager = TVShowManager() video_source = VideoSource() + def donwload_video(scape_info_serie: GetSerieInfo, index_episode_selected: int) -> None: """ Download a single episode video. diff --git a/Src/Api/ddlstreamitaly/site.py b/Src/Api/ddlstreamitaly/site.py index f54b03c..694ac01 100644 --- a/Src/Api/ddlstreamitaly/site.py +++ b/Src/Api/ddlstreamitaly/site.py @@ -16,7 +16,7 @@ from ..Template import search_domain, get_select_title # Logic class -from .Core.Class.SearchType import MediaManager, MediaItem +from .Core.Class.SearchType import MediaManager # Variable diff --git a/Src/Api/guardaserie/Core/Util/manage_ep.py b/Src/Api/guardaserie/Core/Util/manage_ep.py deleted file mode 100644 index 06b24fd..0000000 --- a/Src/Api/guardaserie/Core/Util/manage_ep.py +++ /dev/null @@ -1,71 +0,0 @@ -# 02.05.24 - -import logging - -from typing import List - - -# Internal utilities -from Src.Util._jsonConfig import config_manager -from Src.Util.os import remove_special_characters - - -# Config -MAP_EPISODE = config_manager.get('DEFAULT', 'map_episode_name') - - -def manage_selection(cmd_insert: str, max_count: int) -> List[int]: - """ - Manage user selection for seasons to download. - - Args: - - cmd_insert (str): User input for season selection. - - max_count (int): Maximum count of seasons available. - - Returns: - list_season_select (List[int]): List of selected seasons. - """ - list_season_select = [] - logging.info(f"Command insert: {cmd_insert}, end index: {max_count + 1}") - - # For a single number (e.g., '5') - if cmd_insert.isnumeric(): - list_season_select.append(int(cmd_insert)) - - # For a range (e.g., '[5-12]') - elif "[" in cmd_insert: - start, end = map(int, cmd_insert[1:-1].split('-')) - list_season_select = list(range(start, end + 1)) - - # For all seasons - elif cmd_insert == "*": - list_season_select = list(range(1, max_count+1)) - - # Return list of selected seasons) - logging.info(f"List return: {list_season_select}") - return list_season_select - -def map_episode_title(tv_name: str, number_season: int, episode_number: int, episode_name: str) -> str: - """ - Maps the episode title to a specific format. - - Args: - tv_name (str): The name of the TV show. - number_season (int): The season number. - episode_number (int): The episode number. - episode_name (str): The original name of the episode. - - Returns: - str: The mapped episode title. - """ - map_episode_temp = MAP_EPISODE - map_episode_temp = map_episode_temp.replace("%(tv_name)", remove_special_characters(tv_name)) - map_episode_temp = map_episode_temp.replace("%(season)", str(number_season)) - map_episode_temp = map_episode_temp.replace("%(episode)", str(episode_number)) - map_episode_temp = map_episode_temp.replace("%(episode_name)", remove_special_characters(episode_name)) - - # Additional fix - map_episode_temp = map_episode_temp.replace(".", "_") - - logging.info(f"Map episode string return: {map_episode_temp}") - return map_episode_temp diff --git a/Src/Api/guardaserie/series.py b/Src/Api/guardaserie/series.py index 4f677ac..ccfd1f6 100644 --- a/Src/Api/guardaserie/series.py +++ b/Src/Api/guardaserie/series.py @@ -10,12 +10,12 @@ from Src.Util.console import console, msg from Src.Util.table import TVShowManager from Src.Util.message import start_message from Src.Lib.Hls.downloader import Downloader +from ..Template import manage_selection, map_episode_title # Logic class from .Core.Class.SearchType import MediaItem from .Core.Class.ScrapeSerie import GetSerieInfo -from .Core.Util.manage_ep import manage_selection, map_episode_title from .Core.Player.supervideo import VideoSource @@ -25,6 +25,7 @@ table_show_manager = TVShowManager() video_source = VideoSource() + def donwload_video(scape_info_serie: GetSerieInfo, index_season_selected: int, index_episode_selected: int) -> None: """ Download a single episode video. diff --git a/Src/Api/streamingcommunity/Core/Util/__init__.py b/Src/Api/streamingcommunity/Core/Util/__init__.py deleted file mode 100644 index cdee8b4..0000000 --- a/Src/Api/streamingcommunity/Core/Util/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# 21.05.24 - -from .manage_ep import ( - manage_selection, - map_episode_title -) \ No newline at end of file diff --git a/Src/Api/streamingcommunity/Core/Util/manage_ep.py b/Src/Api/streamingcommunity/Core/Util/manage_ep.py deleted file mode 100644 index ab4ae71..0000000 --- a/Src/Api/streamingcommunity/Core/Util/manage_ep.py +++ /dev/null @@ -1,75 +0,0 @@ -# 02.05.24 - -import logging - -from typing import List - - -# Internal utilities -from Src.Util._jsonConfig import config_manager -from Src.Util.os import remove_special_characters - - -# Logic class -from ..Class.EpisodeType import Episode - - -# Config -MAP_EPISODE = config_manager.get('DEFAULT', 'map_episode_name') - - -def manage_selection(cmd_insert: str, max_count: int) -> List[int]: - """ - Manage user selection for seasons to download. - - Args: - - cmd_insert (str): User input for season selection. - - max_count (int): Maximum count of seasons available. - - Returns: - list_season_select (List[int]): List of selected seasons. - """ - list_season_select = [] - logging.info(f"Command insert: {cmd_insert}, end index: {max_count + 1}") - - # For a single number (e.g., '5') - if cmd_insert.isnumeric(): - list_season_select.append(int(cmd_insert)) - - # For a range (e.g., '[5-12]') - elif "[" in cmd_insert: - start, end = map(int, cmd_insert[1:-1].split('-')) - list_season_select = list(range(start, end + 1)) - - # For all seasons - elif cmd_insert == "*": - list_season_select = list(range(1, max_count+1)) - - # Return list of selected seasons) - logging.info(f"List return: {list_season_select}") - return list_season_select - - -def map_episode_title(tv_name: str, episode: Episode, number_season: int): - """ - Maps the episode title to a specific format. - - Args: - - tv_name (str): The name of the TV show. - - episode (Episode): The episode object. - - number_season (int): The season number. - - Returns: - str: The mapped episode title. - """ - map_episode_temp = MAP_EPISODE - map_episode_temp = map_episode_temp.replace("%(tv_name)", remove_special_characters(tv_name)) - map_episode_temp = map_episode_temp.replace("%(season)", str(number_season).zfill(2)) - map_episode_temp = map_episode_temp.replace("%(episode)", str(episode.number).zfill(2)) - map_episode_temp = map_episode_temp.replace("%(episode_name)", remove_special_characters(episode.name)) - - # Additional fix - map_episode_temp = map_episode_temp.replace(".", "_") - - logging.info(f"Map episode string return: {map_episode_temp}") - return map_episode_temp diff --git a/Src/Api/streamingcommunity/__init__.py b/Src/Api/streamingcommunity/__init__.py index 9aaddf4..02ed88a 100644 --- a/Src/Api/streamingcommunity/__init__.py +++ b/Src/Api/streamingcommunity/__init__.py @@ -5,12 +5,7 @@ from Src.Util.console import console, msg # Logic class -from .site import ( - get_version_and_domain, - title_search, - run_get_select_title -) - +from .site import get_version_and_domain, title_search, run_get_select_title from .film import download_film from .series import download_series diff --git a/Src/Api/streamingcommunity/film.py b/Src/Api/streamingcommunity/film.py index 95fdd19..9f0e804 100644 --- a/Src/Api/streamingcommunity/film.py +++ b/Src/Api/streamingcommunity/film.py @@ -53,4 +53,4 @@ def download_film(id_film: str, title_name: str, domain: str): Downloader( m3u8_playlist = master_playlist, output_filename = os.path.join(mp4_path, mp4_format) - ).start() \ No newline at end of file + ).start() diff --git a/Src/Api/streamingcommunity/series.py b/Src/Api/streamingcommunity/series.py index 6b69387..a9f2365 100644 --- a/Src/Api/streamingcommunity/series.py +++ b/Src/Api/streamingcommunity/series.py @@ -7,14 +7,14 @@ import logging # Internal utilities from Src.Util.console import console, msg -from Src.Util.table import TVShowManager from Src.Util.message import start_message +from Src.Util.table import TVShowManager from Src.Lib.Hls.downloader import Downloader +from ..Template import manage_selection, map_episode_title # Logic class from .Core.Player.vixcloud import VideoSource -from .Core.Util import manage_selection, map_episode_title # Variable @@ -23,6 +23,7 @@ video_source = VideoSource() table_show_manager = TVShowManager() + def donwload_video(tv_name: str, index_season_selected: int, index_episode_selected: int) -> None: """ Download a single episode video. @@ -41,7 +42,7 @@ def donwload_video(tv_name: str, index_season_selected: int, index_episode_selec print() # Define filename and path for the downloaded video - mp4_name = f"{map_episode_title(tv_name, obj_episode, index_season_selected)}.mp4" + mp4_name = f"{map_episode_title(tv_name, index_season_selected, index_episode_selected, obj_episode.name)}.mp4" mp4_path = os.path.join(ROOT_PATH, SITE_NAME, SERIES_FOLDER, tv_name, f"S{index_season_selected}") # Retrieve scws and if available master playlist diff --git a/Src/Api/streamingcommunity/site.py b/Src/Api/streamingcommunity/site.py index a0ee431..6cd1d87 100644 --- a/Src/Api/streamingcommunity/site.py +++ b/Src/Api/streamingcommunity/site.py @@ -20,7 +20,6 @@ from Src.Util.table import TVShowManager from ..Template import search_domain, get_select_title - # Logic class from .Core.Class.SearchType import MediaManager diff --git a/Src/Lib/Hls/downloader.py b/Src/Lib/Hls/downloader.py index 11cd0a8..a29127a 100644 --- a/Src/Lib/Hls/downloader.py +++ b/Src/Lib/Hls/downloader.py @@ -76,7 +76,7 @@ class Downloader(): self.m3u8_playlist = m3u8_playlist self.m3u8_index = m3u8_index - self.output_filename = output_filename + self.output_filename = output_filename.replace(" ", "_") # Auto generate out file name if not present if output_filename == None: