diff --git a/StreamingCommunity/Api/Site/mostraguarda/film.py b/StreamingCommunity/Api/Site/mostraguarda/film.py index 507f6d4..d317837 100644 --- a/StreamingCommunity/Api/Site/mostraguarda/film.py +++ b/StreamingCommunity/Api/Site/mostraguarda/film.py @@ -11,10 +11,10 @@ from rich.console import Console # Internal utilities -from StreamingCommunity.Util.os import os_manager +from StreamingCommunity.Util.os import os_manager, get_call_stack from StreamingCommunity.Util.message import start_message from StreamingCommunity.Util.headers import get_userAgent -from StreamingCommunity.Util.table import TVShowManager, get_call_stack +from StreamingCommunity.Util.table import TVShowManager from StreamingCommunity.Lib.Downloader import HLS_Downloader diff --git a/StreamingCommunity/Util/call_stack.py b/StreamingCommunity/Util/call_stack.py deleted file mode 100644 index b0e878b..0000000 --- a/StreamingCommunity/Util/call_stack.py +++ /dev/null @@ -1,42 +0,0 @@ -# 21.06.24 - -import os -import inspect - - -def get_call_stack(): - """ - Retrieves the current call stack with details about each call. - - This function inspects the current call stack and returns a list of dictionaries, - where each dictionary contains details about a function call in the stack. - - Returns: - list: A list of dictionaries, each containing the following keys: - - function (str): The name of the function. - - folder (str): The directory path of the script containing the function. - - folder_base (str): The base name of the directory path. - - script (str): The name of the script file containing the function. - - line (int): The line number in the script where the function is defined. - """ - - stack = inspect.stack() - call_stack = [] - - for frame_info in stack: - function_name = frame_info.function - filename = frame_info.filename - lineno = frame_info.lineno - folder_name = os.path.dirname(filename) - folder_base = os.path.basename(folder_name) - script_name = os.path.basename(filename) - - call_stack.append({ - "function": function_name, - "folder": folder_name, - "folder_base": folder_base, - "script": script_name, - "line": lineno - }) - - return call_stack \ No newline at end of file diff --git a/StreamingCommunity/Util/os.py b/StreamingCommunity/Util/os.py index 2c63dc0..36d2511 100644 --- a/StreamingCommunity/Util/os.py +++ b/StreamingCommunity/Util/os.py @@ -9,6 +9,7 @@ import shutil import hashlib import logging import platform +import inspect import subprocess import contextlib import importlib.metadata @@ -493,20 +494,31 @@ def suppress_output(): yield def compute_sha1_hash(input_string: str) -> str: - """ - Computes the SHA-1 hash of the input string. + """Computes the SHA-1 hash of the input string.""" + return hashlib.sha1(input_string.encode()).hexdigest() - Parameters: - - input_string (str): The string to be hashed. +def get_call_stack(): + """Retrieves the current call stack with details about each call.""" + stack = inspect.stack() + call_stack = [] - Returns: - str: The SHA-1 hash of the input string. - """ - # Compute the SHA-1 hash - hashed_string = hashlib.sha1(input_string.encode()).hexdigest() + for frame_info in stack: + function_name = frame_info.function + filename = frame_info.filename + lineno = frame_info.lineno + folder_name = os.path.dirname(filename) + folder_base = os.path.basename(folder_name) + script_name = os.path.basename(filename) - # Return the hashed string - return hashed_string + call_stack.append({ + "function": function_name, + "folder": folder_name, + "folder_base": folder_base, + "script": script_name, + "line": lineno + }) + + return call_stack def get_ffmpeg_path(): """Returns the path of FFmpeg.""" diff --git a/StreamingCommunity/Util/table.py b/StreamingCommunity/Util/table.py index b4cce96..477fbb5 100644 --- a/StreamingCommunity/Util/table.py +++ b/StreamingCommunity/Util/table.py @@ -16,8 +16,8 @@ from rich.style import Style # Internal utilities +from .os import get_call_stack from .message import start_message -from .call_stack import get_call_stack # Telegram bot instance