From cb6d5837f23ac27301579b9b4bd8e7dac0ee288b Mon Sep 17 00:00:00 2001 From: Ghost <62809003+Ghost6446@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:05:35 +0200 Subject: [PATCH] Fix run and update discord link --- README.md | 3 +- Src/Api/site.py | 2 +- Src/Lib/FFmpeg/my_m3u8.py | 4 +-- Src/Lib/FFmpeg/util/installer.py | 6 ++-- run.py | 49 +++++++++++++++++++++++--------- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a616852..e499d8f 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,10 @@ This repository provide a simple script designed to facilitate the downloading of films and series from a popular streaming community platform. The script allows users to download individual films, entire series, or specific episodes, providing a seamless experience for content consumers. ## Join us -You can chat, help improve this repo, or just hang around for some fun in the **Git_StreamingCommunity** Discord [Server](https://discord.gg/we8n4tfxFs) +You can chat, help improve this repo, or just hang around for some fun in the **Git_StreamingCommunity** Discord [Server](https://discord.gg/PtMX28v5) # Table of Contents * [INSTALLATION](#installation) - * [Requirement](#requirement) * [Usage](#usage) * [Update](#update) diff --git a/Src/Api/site.py b/Src/Api/site.py index c864fca..e720dbe 100644 --- a/Src/Api/site.py +++ b/Src/Api/site.py @@ -149,7 +149,7 @@ def test_site(domain: str) -> str: try: response = requests.get(site_url, headers={'user-agent': get_headers()}) console.print(f"[green]Request response [white]=> [red]{response.status_code} \n") - response.raise_for_status() # Raise an error if request fails + response.raise_for_status() if response.ok: return response.text diff --git a/Src/Lib/FFmpeg/my_m3u8.py b/Src/Lib/FFmpeg/my_m3u8.py index c8b6714..bf0d675 100644 --- a/Src/Lib/FFmpeg/my_m3u8.py +++ b/Src/Lib/FFmpeg/my_m3u8.py @@ -566,7 +566,7 @@ class Downloader(): m3u8_index_obj = parse_class_m3u8.get_best_quality() # Get URI of the best quality and codecs parameters - console.log(f"[cyan]Select resolution: [red]{m3u8_index_obj.get('width')}") + console.log(f"[cyan]Find resolution: [red]{m3u8_index_obj.get('width')}") m3u8_index = m3u8_index_obj.get('uri') # Fix URL if it is not complete with http:\\site_name.domain\... @@ -588,7 +588,7 @@ class Downloader(): # Get obj codec self.codec: M3U8_Codec = parse_class_m3u8.codec logging.info(f"Get codeds: {self.codec}") - console.log(f"[cyan]Use codecs: [red]({self.codec.video_codec_name};{self.codec.audio_codec_name})") + console.log(f"[cyan]Find codecs: [red]({self.codec.video_codec_name};{self.codec.audio_codec_name})") def manage_subtitle(self): """ diff --git a/Src/Lib/FFmpeg/util/installer.py b/Src/Lib/FFmpeg/util/installer.py index 5691e99..02c9d6c 100644 --- a/Src/Lib/FFmpeg/util/installer.py +++ b/Src/Lib/FFmpeg/util/installer.py @@ -170,7 +170,7 @@ def download_ffmpeg(): # Generate install directory path install_dir = os.path.join(INSTALL_DIR, 'FFMPEG') - console.print(f"[cyan]f'Making install directory: [red]{install_dir!r}") + console.print(f"[cyan]Making install directory: [red]{install_dir!r}") logging.info(f'Making install directory {install_dir!r}') os.makedirs(install_dir, exist_ok=True) @@ -210,6 +210,7 @@ def check_ffmpeg() -> bool: console.print("[green]Checking FFmpeg...") try: + # Try running the FFmpeg command to check if it exists subprocess.run(["ffmpeg", "-version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) console.print("[blue]FFmpeg is installed. \n") @@ -235,6 +236,5 @@ def check_ffmpeg() -> bool: # If unable to download or add FFmpeg to the PATH console.print("[red]Unable to download or add FFmpeg to the PATH.[/red]") console.print(f"Error: {e}") - raise - return False \ No newline at end of file + return False \ No newline at end of file diff --git a/run.py b/run.py index c8311ae..c52d71c 100644 --- a/run.py +++ b/run.py @@ -4,6 +4,7 @@ import sys import logging import platform import argparse +from typing import Callable # Internal utilities @@ -91,9 +92,9 @@ def initialize(): temp_config_manager.add_variable('Requirements', 'ffmpeg', True) -def main(): +def main_film_series(): """ - Main function of the application. + Main function of the application for film and series. """ # Get site domain and version @@ -134,9 +135,9 @@ def main(): console.print("\n[red]Done") -def main_switch(): +def main_anime(): """ - Main function for anime unity + Main function of the application for anime unity """ # Get site domain and version @@ -169,7 +170,15 @@ def main_switch(): else: console.print("[red]Cant find a single element") -def run_function(func, close_console=False): + +def run_function(func: Callable[..., None], close_console: bool = False) -> None: + """ + Run a given function indefinitely or once, depending on the value of close_console. + + Parameters: + func (Callable[..., None]): The function to run. + close_console (bool, optional): Whether to close the console after running the function once. Defaults to False. + """ if close_console: while 1: func() @@ -177,7 +186,9 @@ def run_function(func, close_console=False): func() -if __name__ == '__main__': +def main(): + + # Create instance of logger logger = Logger() # Parse command line arguments @@ -187,16 +198,26 @@ if __name__ == '__main__': args = parser.parse_args() if args.anime: - run_function(main_switch, CLOSE_CONSOLE) + run_function(main_anime, CLOSE_CONSOLE) + elif args.film: - run_function(main, CLOSE_CONSOLE) + run_function(main_film_series, CLOSE_CONSOLE) + else: - # If no arguments are provided, ask the user to input the category - category = input("Insert category (0: Film/series, 1: Anime) : ") + + # If no arguments are provided, ask the user to input the category, if nothing insert return 0 + category = msg.ask("[cyan]Insert category [white]([red]0[white]: [bold magenta]Film/Series[white], [red]1[white]: [bold magenta]Anime[white])[white]:[/cyan]", choices={"0": "", "1": ""}, default="0") + if category == '0': - run_function(main, CLOSE_CONSOLE) + run_function(main_film_series, CLOSE_CONSOLE) + elif category == '1': - run_function(main_switch, CLOSE_CONSOLE) + run_function(main_anime, CLOSE_CONSOLE) + else: - console.print("[red]Invalid category") - sys.exit(0) \ No newline at end of file + console.print("[red]Invalid category, you need to insert 0 or 1.") + sys.exit(0) + + +if __name__ == '__main__': + main() \ No newline at end of file