From d942613dd8487d2055b0250c1dca3a8541e8b48c Mon Sep 17 00:00:00 2001 From: Fede14it <115009551+Fede14it@users.noreply.github.com> Date: Thu, 11 Apr 2024 08:00:51 +0200 Subject: [PATCH] Added map for episode names (#98) * Added map for episode names * Fix --- README.md | 10 ++++++++++ Src/Api/series.py | 3 ++- Src/Util/mapper.py | 23 +++++++++++++++++++++++ config.json | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Src/Util/mapper.py diff --git a/README.md b/README.md index b09e638..d493b3a 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ You can change some behaviors by tweaking the configuration file. "specific_list_subtitles": [ "eng" ], + "map_episode_name": "%(tv_name)_S%(season)E%(episode)_%(episode_name)", } } ``` @@ -148,6 +149,7 @@ You can change some behaviors by tweaking the configuration file. | download_subtitles | true | Indicates whether subtitles should be downloaded or not. | false | | specific_list_audio | ["ita"] | A list of specific audio languages to download. | ["eng", "fra"] | | specific_list_subtitles | ["eng"] | A list of specific subtitle languages to download. | ["spa", "por"] | +|map_episode_name |%(tv_name)_S%(season)E%(episode)_%(episode_name)| Mapping to choose the name of all episode of TV Show (see [Episode Name Usage](#Episode-name-usage)). > [!IMPORTANT] > If you're on **Windows** you'll need to use double black slashes. On Linux/MacOS, one slash is fine. @@ -159,3 +161,11 @@ You can change some behaviors by tweaking the configuration file. ## Tutorial For a detailed walkthrough, refer to the [video tutorial](https://www.youtube.com/watch?v=Ok7hQCgxqLg&ab_channel=Nothing) + +#### Episode name usage: +You can choose different vars: +* `%(tv_name)` : Is the name of TV Show +* `%(season)` : Is the number of the season +* `%(episode)` : Is the number of the episode +* `%(episode_name)` : Is the name of the episode +>NOTE: You don't need to add .mp4 at the end \ No newline at end of file diff --git a/Src/Api/series.py b/Src/Api/series.py index 31f63bd..6863bcd 100644 --- a/Src/Api/series.py +++ b/Src/Api/series.py @@ -13,6 +13,7 @@ from Src.Util.message import start_message from Src.Util.os import remove_special_characters from Src.Lib.Unidecode import transliterate from Src.Lib.FFmpeg.my_m3u8 import Downloader +from Src.Util.mapper import map_episode_title from .Class import VideoSource @@ -114,7 +115,7 @@ def donwload_video(tv_name: str, index_season_selected: int, index_episode_selec episode_id = video_source.obj_episode_manager.episodes[index_episode_selected - 1].id # Define filename and path for the downloaded video - mp4_name = remove_special_characters(f"{index_episode_selected}_{transliterate(video_source.obj_episode_manager.episodes[index_episode_selected - 1].name)}.mp4") + mp4_name = remove_special_characters(f"{map_episode_title(tv_name,video_source.obj_episode_manager.episodes[index_episode_selected - 1],index_season_selected)}.mp4") mp4_path = remove_special_characters(os.path.join(ROOT_PATH, SERIES_FOLDER, tv_name, f"S{index_season_selected}")) os.makedirs(mp4_path, exist_ok=True) diff --git a/Src/Util/mapper.py b/Src/Util/mapper.py new file mode 100644 index 0000000..1a7dd21 --- /dev/null +++ b/Src/Util/mapper.py @@ -0,0 +1,23 @@ +from Src.Lib.Unidecode import transliterate +from Src.Util.config import config_manager + +map_episode = config_manager.get('M3U8_OPTIONS', 'map_episode_name') + +def map_episode_title(tv_name: str, 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) + return transliterate(map_episode_temp) \ No newline at end of file diff --git a/config.json b/config.json index 8f53178..5830763 100644 --- a/config.json +++ b/config.json @@ -40,6 +40,7 @@ "specific_list_subtitles": [ "eng" ], + "map_episode_name": "%(tv_name)_S%(season)E%(episode)_%(episode_name)", "request": { "index": { "authority": "vixcloud.co",