From 1b099441a4c81c8fe77ee49aeee6b399f206286d Mon Sep 17 00:00:00 2001 From: Lovi <62809003+Lovi-0@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:31:11 +0100 Subject: [PATCH] Add command back --- .../Api/Site/1337xx/__init__.py | 3 +- .../Api/Site/altadefinizione/__init__.py | 3 +- .../Api/Site/animeunity/__init__.py | 3 +- .../Api/Site/bitsearch/__init__.py | 3 +- .../Api/Site/cb01new/__init__.py | 3 +- .../Api/Site/ddlstreamitaly/__init__.py | 3 +- .../Api/Site/guardaserie/__init__.py | 3 +- .../Api/Site/mostraguarda/__init__.py | 3 +- .../Api/Site/piratebays/__init__.py | 3 +- .../Api/Site/streamingcommunity/__init__.py | 3 +- .../Api/Template/Util/get_domain.py | 10 +- StreamingCommunity/Util/table.py | 112 ++++++++++++++++-- StreamingCommunity/run.py | 4 +- 13 files changed, 129 insertions(+), 27 deletions(-) diff --git a/StreamingCommunity/Api/Site/1337xx/__init__.py b/StreamingCommunity/Api/Site/1337xx/__init__.py index b3631cb..6e3dcd2 100644 --- a/StreamingCommunity/Api/Site/1337xx/__init__.py +++ b/StreamingCommunity/Api/Site/1337xx/__init__.py @@ -18,6 +18,7 @@ _useFor = "film_serie" _deprecate = False _priority = 2 _engineDownload = "tor" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -26,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/altadefinizione/__init__.py b/StreamingCommunity/Api/Site/altadefinizione/__init__.py index a044fdb..d46bfb7 100644 --- a/StreamingCommunity/Api/Site/altadefinizione/__init__.py +++ b/StreamingCommunity/Api/Site/altadefinizione/__init__.py @@ -18,6 +18,7 @@ _useFor = "film" _deprecate = False _priority = 2 _engineDownload = "hls" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -26,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/animeunity/__init__.py b/StreamingCommunity/Api/Site/animeunity/__init__.py index 4ceb359..638e203 100644 --- a/StreamingCommunity/Api/Site/animeunity/__init__.py +++ b/StreamingCommunity/Api/Site/animeunity/__init__.py @@ -18,12 +18,13 @@ _useFor = "anime" _deprecate = False _priority = 2 _engineDownload = "mp4" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/bitsearch/__init__.py b/StreamingCommunity/Api/Site/bitsearch/__init__.py index ec43294..2e43cd8 100644 --- a/StreamingCommunity/Api/Site/bitsearch/__init__.py +++ b/StreamingCommunity/Api/Site/bitsearch/__init__.py @@ -18,6 +18,7 @@ _useFor = "film_serie" _deprecate = False _priority = 2 _engineDownload = "tor" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase:bool = False): @@ -26,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase:bool = False): """ if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/cb01new/__init__.py b/StreamingCommunity/Api/Site/cb01new/__init__.py index d927778..ee01ee0 100644 --- a/StreamingCommunity/Api/Site/cb01new/__init__.py +++ b/StreamingCommunity/Api/Site/cb01new/__init__.py @@ -18,6 +18,7 @@ _useFor = "film" _deprecate = False _priority = 2 _engineDownload = "mp4" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -26,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py b/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py index 123371e..2b6e417 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/__init__.py @@ -19,6 +19,7 @@ _useFor = "serie" _deprecate = False _priority = 2 _engineDownload = "mp4" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -29,7 +30,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if string_to_search is None: # Make request to site to get content that corrsisponde to that string - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/guardaserie/__init__.py b/StreamingCommunity/Api/Site/guardaserie/__init__.py index 059ccb6..7c404d4 100644 --- a/StreamingCommunity/Api/Site/guardaserie/__init__.py +++ b/StreamingCommunity/Api/Site/guardaserie/__init__.py @@ -18,6 +18,7 @@ _useFor = "serie" _deprecate = False _priority = 2 _engineDownload = "hls" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -28,7 +29,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): if string_to_search is None: # Make request to site to get content that corrsisponde to that string - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/mostraguarda/__init__.py b/StreamingCommunity/Api/Site/mostraguarda/__init__.py index a2f87d9..68e489a 100644 --- a/StreamingCommunity/Api/Site/mostraguarda/__init__.py +++ b/StreamingCommunity/Api/Site/mostraguarda/__init__.py @@ -18,6 +18,7 @@ _useFor = "film" _deprecate = False _priority = 2 _engineDownload = "hls" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -26,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Not available for the moment if get_onylDatabase: diff --git a/StreamingCommunity/Api/Site/piratebays/__init__.py b/StreamingCommunity/Api/Site/piratebays/__init__.py index b3631cb..6e3dcd2 100644 --- a/StreamingCommunity/Api/Site/piratebays/__init__.py +++ b/StreamingCommunity/Api/Site/piratebays/__init__.py @@ -18,6 +18,7 @@ _useFor = "film_serie" _deprecate = False _priority = 2 _engineDownload = "tor" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -26,7 +27,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Search on database len_database = title_search(unidecode(string_to_search)) diff --git a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py index fe9ee78..badc78e 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/__init__.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/__init__.py @@ -19,6 +19,7 @@ _useFor = "film_serie" _deprecate = False _priority = 1 _engineDownload = "hls" +from .costant import SITE_NAME def search(string_to_search: str = None, get_onylDatabase: bool = False): @@ -27,7 +28,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False): """ if string_to_search is None: - string_to_search = msg.ask("\n[purple]Insert word to search in all site").strip() + string_to_search = msg.ask(f"\n[purple]Insert word to search in [red]{SITE_NAME}").strip() # Get site domain and version and get result of the search site_version, domain = get_version_and_domain() diff --git a/StreamingCommunity/Api/Template/Util/get_domain.py b/StreamingCommunity/Api/Template/Util/get_domain.py index b6d0101..5e145e2 100644 --- a/StreamingCommunity/Api/Template/Util/get_domain.py +++ b/StreamingCommunity/Api/Template/Util/get_domain.py @@ -50,15 +50,15 @@ def get_final_redirect_url(initial_url, max_timeout): # Create a client with redirects enabled try: with httpx.Client( - follow_redirects=True, - timeout=max_timeout, headers={ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7', 'User-Agent': get_headers() - } + }, + follow_redirects=True, + timeout=max_timeout + ) as client: - response = client.get(initial_url) response.raise_for_status() @@ -97,8 +97,8 @@ def search_domain(site_name: str, base_url: str): }, follow_redirects=True, timeout=max_timeout + ) as client: - response_follow = client.get(f"{base_url}.{domain}") response_follow.raise_for_status() diff --git a/StreamingCommunity/Util/table.py b/StreamingCommunity/Util/table.py index f84442e..bfc6553 100644 --- a/StreamingCommunity/Util/table.py +++ b/StreamingCommunity/Util/table.py @@ -1,5 +1,12 @@ # 03.03.24 +import os +import sys +import logging +import importlib + + +# External library from rich.console import Console from rich.table import Table from rich.prompt import Prompt @@ -9,15 +16,13 @@ from typing import Dict, List, Any # Internal utilities from .message import start_message +from .call_stack import get_call_stack class TVShowManager: def __init__(self): """ Initialize TVShowManager with provided column information. - - Parameters: - - column_info (Dict[str, Dict[str, str]]): Dictionary containing column names, their colors, and justification. """ self.console = Console() self.tv_shows: List[Dict[str, Any]] = [] # List to store TV show data as dictionaries @@ -80,7 +85,6 @@ class TVShowManager: self.console.print(table) # Use self.console.print instead of print - def run(self, force_int_input: bool = False, max_int_input: int = 0) -> str: """ Run the TV show manager application. @@ -101,9 +105,16 @@ class TVShowManager: # Display table self.display_data(self.tv_shows[self.slice_start:self.slice_end]) + # Find research function from call stack + research_func = None + for reverse_fun in get_call_stack(): + if reverse_fun['function'] == 'search' and reverse_fun['script'] == '__init__.py': + research_func = reverse_fun + logging.info(f"Found research_func: {research_func}") + # Handling user input for loading more items or quitting if self.slice_end < total_items: - self.console.print(f"\n\n[yellow][INFO] [green]Press [red]Enter [green]for next page, or [red]'q' [green]to quit.") + self.console.print(f"\n\n[yellow][INFO] [green]Press [red]Enter [green]for next page, [red]'q' [green]to quit, or [red]'back' [green]to search.") if not force_int_input: key = Prompt.ask( @@ -113,7 +124,7 @@ class TVShowManager: else: choices = [str(i) for i in range(0, max_int_input)] - choices.extend(["q", ""]) + choices.extend(["q", "", "back"]) key = Prompt.ask("[cyan]Insert media [red]index", choices=choices, show_choices=False) last_command = key @@ -127,22 +138,62 @@ class TVShowManager: if self.slice_end > total_items: self.slice_end = total_items + elif key.lower() == "back" and research_func: + try: + # Find the project root directory + current_path = research_func['folder'] + while not os.path.exists(os.path.join(current_path, 'StreamingCommunity')): + current_path = os.path.dirname(current_path) + + # Add project root to Python path + project_root = current_path + #print(f"[DEBUG] Project Root: {project_root}") + + if project_root not in sys.path: + sys.path.insert(0, project_root) + + # Import using full absolute import + module_path = 'StreamingCommunity.Api.Site.streamingcommunity' + #print(f"[DEBUG] Importing module: {module_path}") + + # Import the module + module = importlib.import_module(module_path) + + # Get the search function + search_func = getattr(module, 'media_search_manager') + + # Ask for search string + string_to_search = Prompt.ask(f"\n[purple]Insert word to search in [red]{research_func['folder_base']}").strip() + + # Call the search function with the search string + search_func(string_to_search) + + except Exception as e: + self.console.print(f"[red]Error during search: {e}") + + # Print detailed traceback + import traceback + traceback.print_exc() + + # Optionally remove the path if you want to clean up + if project_root in sys.path: + sys.path.remove(project_root) + else: break else: # Last slice, ensure all remaining items are shown - self.console.print(f"\n\n[yellow][INFO] [red]You've reached the end. [green]Press [red]Enter [green]for next page, or [red]'q' [green]to quit.") + self.console.print(f"\n\n[yellow][INFO] [green]You've reached the end. [red]Enter [green]for first page, [red]'q' [green]to quit, or [red]'back' [green]to search.") if not force_int_input: key = Prompt.ask( "\n[cyan]Insert media index [yellow](e.g., 1), [red]* [cyan]to download all media, " "[yellow](e.g., 1-2) [cyan]for a range of media, or [yellow](e.g., 3-*) [cyan]to download from a specific index to the end" ) - else: choices = [str(i) for i in range(0, max_int_input)] - choices.extend(["q", ""]) + choices.extend(["q", "", "back"]) key = Prompt.ask("[cyan]Insert media [red]index", choices=choices, show_choices=False) last_command = key @@ -154,10 +205,51 @@ class TVShowManager: self.slice_start = 0 self.slice_end = self.step + elif key.lower() == "back" and research_func: + try: + # Find the project root directory + current_path = research_func['folder'] + while not os.path.exists(os.path.join(current_path, 'StreamingCommunity')): + current_path = os.path.dirname(current_path) + + # Add project root to Python path + project_root = current_path + #print(f"[DEBUG] Project Root: {project_root}") + + if project_root not in sys.path: + sys.path.insert(0, project_root) + + # Import using full absolute import + module_path = 'StreamingCommunity.Api.Site.streamingcommunity' + #print(f"[DEBUG] Importing module: {module_path}") + + # Import the module + module = importlib.import_module(module_path) + + # Get the search function + search_func = getattr(module, 'media_search_manager') + + # Ask for search string + string_to_search = Prompt.ask(f"\n[purple]Insert word to search in [red]{research_func['folder_base']}").strip() + + # Call the search function with the search string + search_func(string_to_search) + + except Exception as e: + self.console.print(f"[red]Error during search: {e}") + + # Print detailed traceback + import traceback + traceback.print_exc() + + # Optionally remove the path if you want to clean up + if project_root in sys.path: + sys.path.remove(project_root) + else: break return last_command def clear(self): - self.tv_shows = [] + self.tv_shows = [] \ No newline at end of file diff --git a/StreamingCommunity/run.py b/StreamingCommunity/run.py index e58a47f..8cc3e40 100644 --- a/StreamingCommunity/run.py +++ b/StreamingCommunity/run.py @@ -119,12 +119,12 @@ def initialize(): console.log("[red]Install python version > 3.7.16") sys.exit(0) - # Attempting GitHub update + """# Attempting GitHub update try: git_update() print() except: - console.log("[red]Error with loading github.") + console.log("[red]Error with loading github.")""" # Show trending film and series if SHOW_TRENDING: