From 6d13b1875a1d4319d2e611e903abd16f74a31f95 Mon Sep 17 00:00:00 2001 From: Lovi <62809003+Lovi-0@users.noreply.github.com> Date: Sun, 9 Mar 2025 09:36:04 +0100 Subject: [PATCH] Bump v2.9.3 --- .../Api/Site/animeunity/film_serie.py | 2 +- .../Api/Site/animeunity/site.py | 46 +++++---------- .../Api/Site/guardaserie/series.py | 2 +- .../Api/Site/streamingcommunity/series.py | 2 +- .../Api/Template/Util/manage_ep.py | 58 ++++++++++++++----- StreamingCommunity/Api/Template/site.py | 2 +- StreamingCommunity/Lib/TMBD/tmdb.py | 2 +- StreamingCommunity/Upload/version.py | 2 +- setup.py | 2 +- 9 files changed, 63 insertions(+), 55 deletions(-) diff --git a/StreamingCommunity/Api/Site/animeunity/film_serie.py b/StreamingCommunity/Api/Site/animeunity/film_serie.py index a85dbec..a8773f3 100644 --- a/StreamingCommunity/Api/Site/animeunity/film_serie.py +++ b/StreamingCommunity/Api/Site/animeunity/film_serie.py @@ -70,7 +70,7 @@ def download_episode(index_select: int, scrape_serie: ScrapeSerieAnime, video_so video_source.get_embed(obj_episode.id) # Create output path - title_name = f"{scrape_serie.series_name}_EP_{dynamic_format_number(int(obj_episode.number))}.mp4" + title_name = f"{scrape_serie.series_name}_EP_{dynamic_format_number(str(obj_episode.number))}.mp4" if scrape_serie.is_series: mp4_path = os_manager.get_sanitize_path(os.path.join(site_constant.ANIME_FOLDER, scrape_serie.series_name)) diff --git a/StreamingCommunity/Api/Site/animeunity/site.py b/StreamingCommunity/Api/Site/animeunity/site.py index 20ba0ef..b7f6da2 100644 --- a/StreamingCommunity/Api/Site/animeunity/site.py +++ b/StreamingCommunity/Api/Site/animeunity/site.py @@ -12,6 +12,7 @@ from rich.console import Console # Internal utilities from StreamingCommunity.Util.config_json import config_manager +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.table import TVShowManager from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance @@ -29,7 +30,7 @@ table_show_manager = TVShowManager() max_timeout = config_manager.get_int("REQUESTS", "timeout") -def get_token(site_name: str, domain: str) -> dict: +def get_token() -> dict: """ Function to retrieve session tokens from a specified website. @@ -40,8 +41,6 @@ def get_token(site_name: str, domain: str) -> dict: Returns: - dict: A dictionary containing session tokens. The keys are 'XSRF_TOKEN', 'animeunity_session', and 'csrf_token'. """ - - # Send a GET request to the specified URL composed of the site name and domain response = httpx.get( url=site_constant.FULL_URL, timeout=max_timeout @@ -50,17 +49,11 @@ def get_token(site_name: str, domain: str) -> dict: # Initialize variables to store CSRF token find_csrf_token = None - - # Parse the HTML response using BeautifulSoup soup = BeautifulSoup(response.text, "html.parser") - # Loop through all meta tags in the HTML response for html_meta in soup.find_all("meta"): - - # Check if the meta tag has a 'name' attribute equal to "csrf-token" if html_meta.get('name') == "csrf-token": - # If found, retrieve the content of the meta tag, which is the CSRF token find_csrf_token = html_meta.get('content') logging.info(f"Extract: ('animeunity_session': {response.cookies['animeunity_session']}, 'csrf_token': {find_csrf_token})") @@ -83,13 +76,12 @@ def get_real_title(record): Returns: - str: The title found in the record. If no title is found, returns None. """ - - if record['title'] is not None: - return record['title'] - - elif record['title_eng'] is not None: + if record['title_eng'] is not None: return record['title_eng'] + elif record['title'] is not None: + return record['title'] + else: return record['title_it'] @@ -117,26 +109,15 @@ def title_search(title: str) -> int: console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]") console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]") sys.exit(1) - - data = get_token(site_constant.SITE_NAME, domain_to_use) - # Prepare cookies to be used in the request - cookies = { - 'animeunity_session': data.get('animeunity_session') - } - - # Prepare headers for the request + # Create parameter for request + data = get_token() + cookies = {'animeunity_session': data.get('animeunity_session')} headers = { - 'accept': 'application/json, text/plain, */*', - 'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7', - 'content-type': 'application/json;charset=UTF-8', + 'user-agent': get_userAgent(), 'x-csrf-token': data.get('csrf_token') } - - # Prepare JSON data to be sent in the request - json_data = { - 'title': title - } + json_data = {'title': title} # Send a POST request to the API endpoint for live search try: @@ -167,8 +148,9 @@ def title_search(title: str) -> int: 'slug': dict_title.get('slug'), 'name': dict_title.get('name'), 'type': dict_title.get('type'), - 'score': dict_title.get('score'), - 'episodes_count': dict_title.get('episodes_count') + 'status': dict_title.get('status'), + 'episodes_count': dict_title.get('episodes_count'), + 'plot': ' '.join((words := str(dict_title.get('plot', '')).split())[:10]) + ('...' if len(words) > 10 else '') }) if site_constant.TELEGRAM_BOT: diff --git a/StreamingCommunity/Api/Site/guardaserie/series.py b/StreamingCommunity/Api/Site/guardaserie/series.py index 8905164..a55be07 100644 --- a/StreamingCommunity/Api/Site/guardaserie/series.py +++ b/StreamingCommunity/Api/Site/guardaserie/series.py @@ -51,7 +51,7 @@ def download_video(index_season_selected: int, index_episode_selected: int, scap - bool: kill handler status """ start_message() - index_season_selected = dynamic_format_number(index_season_selected) + index_season_selected = dynamic_format_number(str(index_season_selected)) # Get info about episode obj_episode = scape_info_serie.list_episodes[index_episode_selected - 1] diff --git a/StreamingCommunity/Api/Site/streamingcommunity/series.py b/StreamingCommunity/Api/Site/streamingcommunity/series.py index 7e48a15..b39046a 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/series.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/series.py @@ -50,7 +50,7 @@ def download_video(index_season_selected: int, index_episode_selected: int, scra - bool: kill handler status """ start_message() - index_season_selected = dynamic_format_number(index_season_selected) + index_season_selected = dynamic_format_number(str(index_season_selected)) # Get info about episode obj_episode = scrape_serie.episode_manager.get(index_episode_selected - 1) diff --git a/StreamingCommunity/Api/Template/Util/manage_ep.py b/StreamingCommunity/Api/Template/Util/manage_ep.py index 9be9a81..8a804c4 100644 --- a/StreamingCommunity/Api/Template/Util/manage_ep.py +++ b/StreamingCommunity/Api/Template/Util/manage_ep.py @@ -22,24 +22,50 @@ console = Console() MAP_EPISODE = config_manager.get('OUT_FOLDER', 'map_episode_name') -def dynamic_format_number(n: int) -> str: +def dynamic_format_number(number_str: str) -> str: """ - Formats a number by adding a leading zero if it is less than 9. - The width of the resulting string is dynamic, calculated as the number of digits in the number plus one - for numbers less than 9, otherwise the width remains the same. + Formats an episode number string, intelligently handling both integer and decimal episode numbers. + + This function is designed to handle various episode number formats commonly found in media series: + 1. For integer episode numbers less than 10 (e.g., 1, 2, ..., 9), it adds a leading zero (e.g., 01, 02, ..., 09) + 2. For integer episode numbers 10 and above, it preserves the original format without adding leading zeros + 3. For decimal episode numbers (e.g., "7.5", "10.5"), it preserves the decimal format exactly as provided + + The function is particularly useful for media file naming conventions where special episodes + or OVAs may have decimal notations (like episode 7.5) which should be preserved in their original format. Parameters: - - n (int): The number to format. + - number_str (str): The episode number as a string, which may contain integers or decimals. Returns: - - str: The formatted number as a string with a leading zero if the number is less than 9. + - str: The formatted episode number string, with appropriate handling based on the input type. + + Examples: + >>> dynamic_format_number("7") + "07" + >>> dynamic_format_number("15") + "15" + >>> dynamic_format_number("7.5") + "7.5" + >>> dynamic_format_number("10.5") + "10.5" """ - if n < 10: - width = len(str(n)) + 1 - else: - width = len(str(n)) + try: + if '.' in number_str: + return number_str + + n = int(number_str) - return str(n).zfill(width) + if n < 10: + width = len(str(n)) + 1 + else: + width = len(str(n)) + + return str(n).zfill(width) + + except Exception as e: + logging.warning(f"Could not format episode number '{number_str}': {str(e)}. Using original format.") + return number_str def manage_selection(cmd_insert: str, max_count: int) -> List[int]: @@ -103,14 +129,14 @@ def map_episode_title(tv_name: str, number_season: int, episode_number: int, epi map_episode_temp = map_episode_temp.replace("%(tv_name)", os_manager.get_sanitize_file(tv_name)) if number_season != None: - map_episode_temp = map_episode_temp.replace("%(season)", number_season) + map_episode_temp = map_episode_temp.replace("%(season)", str(number_season)) else: - map_episode_temp = map_episode_temp.replace("%(season)", dynamic_format_number(0)) + map_episode_temp = map_episode_temp.replace("%(season)", dynamic_format_number(str(0))) if episode_number != None: - map_episode_temp = map_episode_temp.replace("%(episode)", dynamic_format_number(episode_number)) + map_episode_temp = map_episode_temp.replace("%(episode)", dynamic_format_number(str(episode_number))) else: - map_episode_temp = map_episode_temp.replace("%(episode)", dynamic_format_number(0)) + map_episode_temp = map_episode_temp.replace("%(episode)", dynamic_format_number(str(0))) if episode_name != None: map_episode_temp = map_episode_temp.replace("%(episode_name)", os_manager.get_sanitize_file(episode_name)) @@ -227,7 +253,7 @@ def display_episodes_list(episodes_manager) -> str: last_command = table_show_manager.run() if last_command in ("q", "quit"): - console.print("\n[red]Quit [white]...") + console.print("\n[red]Quit ...") sys.exit(0) return last_command \ No newline at end of file diff --git a/StreamingCommunity/Api/Template/site.py b/StreamingCommunity/Api/Template/site.py index 31fb880..6c22244 100644 --- a/StreamingCommunity/Api/Template/site.py +++ b/StreamingCommunity/Api/Template/site.py @@ -72,7 +72,7 @@ def get_select_title(table_show_manager, media_search_manager): # Handle user's quit command if last_command == "q" or last_command == "quit": - console.print("\n[red]Quit [white]...") + console.print("\n[red]Quit ...") sys.exit(0) # Check if the selected index is within range diff --git a/StreamingCommunity/Lib/TMBD/tmdb.py b/StreamingCommunity/Lib/TMBD/tmdb.py index 21d5a40..66e468a 100644 --- a/StreamingCommunity/Lib/TMBD/tmdb.py +++ b/StreamingCommunity/Lib/TMBD/tmdb.py @@ -73,7 +73,7 @@ def get_select_title(table_show_manager, generic_obj): # Handle user's quit command if last_command == "q" or last_command == "quit": - console.print("\n[red]Quit [white]...") + console.print("\n[red]Quit ...") sys.exit(0) # Check if the selected index is within range diff --git a/StreamingCommunity/Upload/version.py b/StreamingCommunity/Upload/version.py index a9aae39..d49fd39 100644 --- a/StreamingCommunity/Upload/version.py +++ b/StreamingCommunity/Upload/version.py @@ -1,5 +1,5 @@ __title__ = 'StreamingCommunity' -__version__ = '2.9.2' +__version__ = '2.9.3' __author__ = 'Arrowar' __description__ = 'A command-line program to download film' __copyright__ = 'Copyright 2024' diff --git a/setup.py b/setup.py index 0d9bc2c..0dcadf7 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ with open("requirements.txt", "r", encoding="utf-8-sig") as f: setup( name="StreamingCommunity", - version="2.9.2", + version="2.9.3", long_description=read_readme(), long_description_content_type="text/markdown", author="Lovi-0",