From 2939da93db2d43173cc13c43e6bc79bb0d9f5f89 Mon Sep 17 00:00:00 2001 From: Ghost <62809003+Ghost6446@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:45:47 +0200 Subject: [PATCH] Fix sys.exit with raise --- README.md | 137 ++++++++++++++++++++++--------- Src/Api/Class/Video.py | 15 ++-- Src/Api/film.py | 17 ++-- Src/Api/series.py | 16 ++-- Src/Api/site.py | 7 +- Src/Lib/FFmpeg/my_m3u8.py | 13 +-- Src/Lib/FFmpeg/util/installer.py | 3 + Src/Lib/FFmpeg/util/math_calc.py | 1 + Src/Lib/FFmpeg/util/url_fix.py | 3 +- 9 files changed, 134 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index 45688f4..efafa25 100644 --- a/README.md +++ b/README.md @@ -69,46 +69,107 @@ python3 update.py You can change some behaviors by tweaking the configuration file. +### Options (DEFAULT) -#### Options +* debug: Whether debugging information should be displayed or not. + - Default Value: false -| Key | Default Value | Description | Value Example | -| -------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -| DEFAULT | | Contains default configuration options for users. | | -| debug | false | Whether debugging information should be displayed or not. | true | -| get_info | false | Whether additional information should be fetched or not with debug enable. | true | -| show_message | true | Whether messages should be displayed to the user or not. | false | -| clean_console | true | Whether the console should be cleared before displaying new information or not. | false | -| get_moment_title | false | Whether to fetch the title of the moment or not. | true | -| root_path | videos | Path where the script will add movies and TV series folders (see[Path Examples](#Path-examples)). | media/streamingcommunity | -| movies_folder_name | Movies | The folder name where all the movies will be placed. Do not put a trailing slash. | downloaded-movies | -| series_folder_name | Series | The folder name where all the TV series will be placed. Do not put a trailing slash. | mytvseries | -| anime_folder_name | Anime | The folder name where all the anime will be placed. Do not put a trailing slash. | myanime | -| not_close | false | Whether to keep the application running after completion or not. | true | -| -------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -| SITE | | Contains site-specific configuration options. | | -| streaming_domain | forum | The domain of the streaming site. | express | -| anime_domain | to | The domain of the anime site. | estate | -| -------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -| M3U8 | | Contains options specific to M3U8. | | -| tdqm_workers | 20 | The number of workers that will cooperate to download .ts files.**A high value may slow down your PC** | 40 | -| tqdm_progress_timeout | 10 | The timeout duration for progress display updates in seconds after quit download. | 5 | -| minimum_ts_files_in_folder | 15 | The minimum number of .ts files expected in a folder. | 10 | -| download_percentage | 1 | The percentage of download completion required to consider the download complete. | 0.95 | -| requests_timeout | 5 | The timeout duration for HTTP requests in seconds. | 10 | -| use_openssl | false | Indicates whether OpenSSL should be utilized for encryption during the conversion of TS files with key and IV. | true | -| use_codecs | false | Specifies whether specific codecs (e.g., h264 for video, AAC for audio) should be used for converting TS files to MP4. | true | -| enable_time_quit | false | Whether to enable quitting the download after a certain time period. | true | -| tqdm_show_progress | false | Whether to show progress during downloads or not.**May slow down your PC** | true | -| cleanup_tmp_folder | true | Whether to clean up temporary folders after processing or not. | false | -| -------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -| M3U8_OPTIONS | | Contains options specific to M3U8 file format. | | -| download_audio | true | Indicates whether audio files should be downloaded or not. | false | -| download_subtitles | true | Indicates whether subtitles should be downloaded or not. | false | -| merge_subtitles | true | Indicates if you want to merge subs in mp4 file or separate files .vtt| 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)). +* get_info: Whether additional information should be fetched or not with debug enabled. + - Default Value: false + +* show_message: Whether messages should be displayed to the user or not. + - Default Value: true + +* clean_console: Whether the console should be cleared before displaying new information or not. + - Default Value: true + +* get_moment_title: Whether to fetch the title of the moment or not. + - Default Value: false + +* root_path: Path where the script will add movies and TV series folders (see [Path Examples](#Path-examples)). + - Default Value: media/streamingcommunity + - Example Value: /path/to/root + +* movies_folder_name: The folder name where all the movies will be placed. Do not put a trailing slash. + - Default Value: downloaded-movies + - Example Value: Movies + +* series_folder_name: The folder name where all the TV series will be placed. Do not put a trailing slash. + - Default Value: mytvseries + - Example Value: Series + +* anime_folder_name: The folder name where all the anime will be placed. Do not put a trailing slash. + - Default Value: myanime + - Example Value: Anime + +* not_close: Whether to keep the application running after completion or not. + - Default Value: false + +### Options (SITE) + +* streaming_domain: The domain of the streaming site. + - Default Value: forum + - Example Value: express + +* anime_domain: The domain of the anime site. + - Default Value: to + - Example Value: estate + +### Options (M3U8) + +* tdqm_workers: The number of workers that will cooperate to download .ts files. **A high value may slow down your PC** + - Default Value: 20 + +* tqdm_progress_timeout: The timeout duration for progress display updates in seconds after quit download. + - Default Value: 10 + +* minimum_ts_files_in_folder: The minimum number of .ts files expected in a folder. + - Default Value: 15 + +* download_percentage: The percentage of download completion required to consider the download complete. + - Default Value: 1 + - Example Value: 0.95 + +* requests_timeout: The timeout duration for HTTP requests in seconds. + - Default Value: 5 + +* use_openssl: Indicates whether OpenSSL should be utilized for encryption during the conversion of TS files with key and IV. + - Default Value: false + +* use_codecs: Specifies whether specific codecs (e.g., h264 for video, AAC for audio) should be used for converting TS files to MP4. **May slow down your PC** + - Default Value: false + +* enable_time_quit: Whether to enable quitting the download after a certain time period. + - Default Value: false + +* tqdm_show_progress: Whether to show progress during downloads or not. **May slow down your PC** + - Default Value: false + +* cleanup_tmp_folder: Whether to clean up temporary folders after processing or not. + - Default Value: true + +### Options (M3U8_OPTIONS) + +* download_audio: Indicates whether audio files should be downloaded or not. + - Default Value: true + +* download_subtitles: Indicates whether subtitles should be downloaded or not. + - Default Value: true + +* merge_subtitles: Indicates if you want to merge subs in mp4 file or separate files .vtt + - Default Value: true + +* specific_list_audio: A list of specific audio languages to download. + - Default Value: ["ita"] + - Example Value: ["eng", "fra"] + +* specific_list_subtitles: A list of specific subtitle languages to download. + - Default Value: ["eng"] + - Example Value: ["spa", "por"] + +* map_episode_name: Mapping to choose the name of all episodes of TV Shows (see [Episode Name Usage](#Episode-name-usage)). + - Default Value: %(tv_name)_S%(season)E%(episode)_%(episode_name) + - Example Value: %(tv_name) [S%(season)] [E%(episode)] %(episode_name) > [!IMPORTANT] > If you're on **Windows** you'll need to use double black slashes. On Linux/MacOS, one slash is fine. diff --git a/Src/Api/Class/Video.py b/Src/Api/Class/Video.py index 06f0076..7d0ec75 100644 --- a/Src/Api/Class/Video.py +++ b/Src/Api/Class/Video.py @@ -5,7 +5,6 @@ import re import json import binascii import logging -import sys from urllib.parse import urljoin, urlencode, quote @@ -106,7 +105,7 @@ class VideoSource: except Exception as e: logging.error(f"Error collecting season info: {e}") - sys.exit(0) + raise def collect_title_season(self, number_season: int) -> None: """ @@ -132,7 +131,7 @@ class VideoSource: except Exception as e: logging.error(f"Error collecting title season info: {e}") - sys.exit(0) + raise def get_iframe(self, episode_id: str = None) -> None: """ @@ -164,7 +163,7 @@ class VideoSource: except Exception as e: logging.error(f"Error getting iframe source: {e}") - sys.exit(0) + raise def parse_script(self, script_text: str) -> None: """ @@ -189,7 +188,7 @@ class VideoSource: except Exception as e: logging.error(f"Error parsing script: {e}") - sys.exit(0) + raise def get_content(self) -> None: """ @@ -215,7 +214,7 @@ class VideoSource: except Exception as e: logging.error(f"Error getting content: {e}") - sys.exit(0) + raise def get_playlist(self) -> str: """ @@ -236,7 +235,7 @@ class VideoSource: except AttributeError as e: logging.error(f"Error getting playlist: {e}") - sys.exit(0) + raise def get_key(self) -> str: """ @@ -265,7 +264,7 @@ class VideoSource: except Exception as e: logging.error(f"Error getting key: {e}") - sys.exit(0) + raise class VideoSourceAnime(VideoSource): """ diff --git a/Src/Api/film.py b/Src/Api/film.py index 41420ba..a3ff674 100644 --- a/Src/Api/film.py +++ b/Src/Api/film.py @@ -50,15 +50,10 @@ def download_film(id_film: str, title_name: str, domain: str): mp4_format = mp4_name + ".mp4" # Download the film using the m3u8 playlist, key, and output filename - try: - obj_download = Downloader( - m3u8_playlist = video_source.get_playlist(), - key = video_source.get_key(), - output_filename = os.path.join(ROOT_PATH, MOVIE_FOLDER, title_name, mp4_format) - ) + obj_download = Downloader( + m3u8_playlist = video_source.get_playlist(), + key = video_source.get_key(), + output_filename = os.path.join(ROOT_PATH, MOVIE_FOLDER, title_name, mp4_format) + ) - obj_download.download_m3u8() - - except Exception as e: - logging.error(f"(download_film) Error downloading film: {e}") - pass + obj_download.download_m3u8() \ No newline at end of file diff --git a/Src/Api/series.py b/Src/Api/series.py index 6863bcd..1123cc0 100644 --- a/Src/Api/series.py +++ b/Src/Api/series.py @@ -125,18 +125,14 @@ def donwload_video(tv_name: str, index_season_selected: int, index_episode_selec video_source.set_url_base_name(STREAM_SITE_NAME) # Download the episode - try: - obj_download = Downloader( - m3u8_playlist = video_source.get_playlist(), - key = video_source.get_key(), - output_filename = os.path.join(mp4_path, mp4_name) - ) + obj_download = Downloader( + m3u8_playlist = video_source.get_playlist(), + key = video_source.get_key(), + output_filename = os.path.join(mp4_path, mp4_name) + ) - obj_download.download_m3u8() + obj_download.download_m3u8() - except Exception as e: - logging.error(f"(donwload_video) Error downloading film: {e}") - pass def donwload_episode(tv_name: str, index_season_selected: int, donwload_all: bool = False) -> None: diff --git a/Src/Api/site.py b/Src/Api/site.py index 195a561..27caa96 100644 --- a/Src/Api/site.py +++ b/Src/Api/site.py @@ -157,8 +157,9 @@ def test_site(domain: str) -> str: return None except Exception as e: - logging.error(f"Error testing site: {e}") - return None + console.log("[red]Try again in 10 minutes.") + logging.error(f"Error testing site: {e}, changing DOMAIN ...") + raise def get_version(text: str) -> str: @@ -182,7 +183,7 @@ def get_version(text: str) -> str: except Exception as e: logging.error(f"Error extracting version: {e}") - sys.exit(0) + raise def get_version_and_domain() -> tuple[str, str]: diff --git a/Src/Lib/FFmpeg/my_m3u8.py b/Src/Lib/FFmpeg/my_m3u8.py index c8119e1..c8b6714 100644 --- a/Src/Lib/FFmpeg/my_m3u8.py +++ b/Src/Lib/FFmpeg/my_m3u8.py @@ -1,7 +1,6 @@ # 5.01.24 -> 7.01.24 -> 20.02.24 -> 29.03.24 import os -import sys import time import threading import logging @@ -152,7 +151,7 @@ class M3U8_Segments: except requests.exceptions.RequestException as req_err: logging.error(f"[M3U8_Segments] Error occurred during request: {req_err}") - sys.exit(1) # Exit with non-zero status to indicate an error + raise except Exception as e: logging.error(f"[M3U8_Segments] Error occurred: {e}") @@ -426,7 +425,7 @@ class M3U8_Segments: # Check if there is file to json if len(ts_files) < MIN_TS_FILES_IN_FOLDER: logging.error(f"No .ts file to join in folder: {self.temp_folder}") - sys.exit(0) + raise # Save files sorted in a txt file with absolute path to fix problem with ( C:\\path (win)) with open(file_list_path, 'w') as file_list: @@ -581,7 +580,7 @@ class Downloader(): console.log(f"[cyan]Found m3u8 index [white]=> [red]{m3u8_index}") else: logging.warning("[download_m3u8] Can't find a valid m3u8 index") - sys.exit(0) + raise # Set m3u8_index self.m3u8_index = m3u8_index @@ -824,9 +823,9 @@ class Downloader(): # Check if there are any downloaded subtitles if len(self.downloaded_subtitle) > 0: + console.log(f"[cyan]Add subtitles.") + if MERGE_SUBTITLES: - # Log adding subtitles - console.log(f"[cyan]Add subtitles.") # If no audio tracks were joined, use the original video path if path_video_and_audio is None: @@ -840,6 +839,7 @@ class Downloader(): ) else: console.log("[cyan]Moving subtitle out of tmp folder.") + for obj_sub in self.downloaded_subtitle: try: language = obj_sub.get('language').lower() @@ -848,6 +848,7 @@ class Downloader(): language = (language.replace("forced-", "") + ".forced") if 'forced-' in language else language sub_path = self.output_filename.replace(".mp4", f".{language}.vtt") os.rename(obj_sub.get('path'), sub_path) + except Exception as e: logging.error(f"Error moving subtitle: {e}. Skipping...") continue diff --git a/Src/Lib/FFmpeg/util/installer.py b/Src/Lib/FFmpeg/util/installer.py index bcb7002..5691e99 100644 --- a/Src/Lib/FFmpeg/util/installer.py +++ b/Src/Lib/FFmpeg/util/installer.py @@ -6,6 +6,9 @@ import os import shutil import subprocess import urllib.request + + +# External libraries from tqdm.rich import tqdm diff --git a/Src/Lib/FFmpeg/util/math_calc.py b/Src/Lib/FFmpeg/util/math_calc.py index 89d919d..8d660f8 100644 --- a/Src/Lib/FFmpeg/util/math_calc.py +++ b/Src/Lib/FFmpeg/util/math_calc.py @@ -1,5 +1,6 @@ # 29.02.24 + # Internal utilities from Src.Util.os import format_size diff --git a/Src/Lib/FFmpeg/util/url_fix.py b/Src/Lib/FFmpeg/util/url_fix.py index f679c80..8db0b57 100644 --- a/Src/Lib/FFmpeg/util/url_fix.py +++ b/Src/Lib/FFmpeg/util/url_fix.py @@ -1,6 +1,5 @@ # 29.03.24 -import sys import logging from urllib.parse import urlparse, urljoin @@ -34,7 +33,7 @@ class M3U8_UrlFix: # Check if m3u8 url playlist is present if self.url_playlist == None: logging.error("[M3U8_UrlFix] Cant generate full url, playlist not present") - sys.exit(0) + raise # Parse the playlist URL to extract the base URL components parsed_playlist_url = urlparse(self.url_playlist)