mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
added missing functions docs
This commit is contained in:
parent
836be2b1bb
commit
cd946a5736
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,6 +2,9 @@
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
.idea/*
|
||||
StreamingCommunity/config.json
|
||||
StreamingCommunity/requirements.txt
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
|
@ -21,6 +21,9 @@ from .call_stack import get_call_stack
|
||||
|
||||
class TVShowManager:
|
||||
def __init__(self, console=Console(), global_search=False):
|
||||
"""
|
||||
Initialize TVShowManager with provided column information.
|
||||
"""
|
||||
self.isGlobal = global_search
|
||||
self.console = console
|
||||
self.tv_shows: List[Dict[str, Any]] = []
|
||||
@ -30,16 +33,40 @@ class TVShowManager:
|
||||
self.column_info = []
|
||||
|
||||
def set_slice_end(self, new_slice: int) -> None:
|
||||
"""
|
||||
Set the end of the slice for displaying TV shows.
|
||||
|
||||
Parameters:
|
||||
- new_slice (int): The new value for the slice end.
|
||||
"""
|
||||
self.slice_end = new_slice
|
||||
self.step = new_slice
|
||||
|
||||
def add_column(self, column_info: Dict[str, Dict[str, str]]) -> None:
|
||||
"""
|
||||
Add column information.
|
||||
|
||||
Parameters:
|
||||
- column_info (Dict[str, Dict[str, str]]): Dictionary containing column names, their colors, and justification.
|
||||
"""
|
||||
self.column_info = column_info
|
||||
|
||||
def add_tv_show(self, tv_show: Dict[str, Any]):
|
||||
"""
|
||||
Add a TV show to the list of TV shows.
|
||||
|
||||
Parameters:
|
||||
- tv_show (Dict[str, Any]): Dictionary containing TV show details.
|
||||
"""
|
||||
self.tv_shows.append(tv_show)
|
||||
|
||||
def display_data(self, data_slice: List[Dict[str, Any]]):
|
||||
"""
|
||||
Display TV show data in a tabular format.
|
||||
|
||||
Parameters:
|
||||
- data_slice (List[Dict[str, Any]]): List of dictionaries containing TV show details to display.
|
||||
"""
|
||||
table = Table(border_style="white")
|
||||
for col_name, col_style in self.column_info.items():
|
||||
color = col_style.get("color", None)
|
||||
@ -51,6 +78,13 @@ class TVShowManager:
|
||||
self.console.print(table)
|
||||
|
||||
def run_back_command(self, research_func: dict):
|
||||
"""
|
||||
Executes a back-end search command by dynamically importing a module and invoking its search function.
|
||||
|
||||
Args:
|
||||
research_func (dict): A dictionary containing:
|
||||
- 'folder' (str): The absolute path to the directory containing the module to be executed.
|
||||
"""
|
||||
try:
|
||||
site_name = os.path.basename(research_func['folder'])
|
||||
current_path = research_func['folder']
|
||||
@ -69,74 +103,18 @@ class TVShowManager:
|
||||
traceback.print_exc()
|
||||
if project_root in sys.path:
|
||||
sys.path.remove(project_root)
|
||||
'''
|
||||
def run(self, force_int_input: bool = False, max_int_input: int = 0) -> str:
|
||||
total_items = len(self.tv_shows)
|
||||
last_command = ""
|
||||
while True:
|
||||
start_message()
|
||||
self.display_data(self.tv_shows[self.slice_start:self.slice_end])
|
||||
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}")
|
||||
if self.slice_end < total_items:
|
||||
self.console.print(f"\n[green]Press [red]Enter [green]for next page, [red]'q' [green]to quit, [red]'back' [green]to search, [red]'next' [green]for next manager, or [red]'prev' [green]for previous manager.")
|
||||
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", "", "back", "next", "prev"])
|
||||
key = Prompt.ask("[cyan]Insert media [red]index", choices=choices, show_choices=False)
|
||||
last_command = key
|
||||
if key.lower() == "q":
|
||||
return "quit"
|
||||
elif key == "":
|
||||
self.slice_start += self.step
|
||||
self.slice_end += self.step
|
||||
if self.slice_end > total_items:
|
||||
self.slice_end = total_items
|
||||
elif key.lower() == "back" and research_func:
|
||||
self.run_back_command(research_func)
|
||||
elif key.lower() == "next":
|
||||
return "next"
|
||||
elif key.lower() == "prev":
|
||||
return "prev"
|
||||
else:
|
||||
break
|
||||
else:
|
||||
self.console.print(f"\n [green]You've reached the end. [red]Enter [green]for first page, [red]'q' [green]to quit, [red]'back' [green]to search, [red]'next' [green]for next manager, or [red]'prev' [green]for previous manager.")
|
||||
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", "", "back", "next", "prev"])
|
||||
key = Prompt.ask("[cyan]Insert media [red]index", choices=choices, show_choices=False)
|
||||
last_command = key
|
||||
if key.lower() == "q":
|
||||
return "quit"
|
||||
elif key == "":
|
||||
self.slice_start = 0
|
||||
self.slice_end = self.step
|
||||
elif key.lower() == "back" and research_func:
|
||||
self.run_back_command(research_func)
|
||||
elif key.lower() == "next":
|
||||
return "next"
|
||||
elif key.lower() == "prev":
|
||||
return "prev"
|
||||
else:
|
||||
break
|
||||
return last_command
|
||||
'''
|
||||
|
||||
def run(self, force_int_input: bool = False, max_int_input: int = 0) -> str:
|
||||
"""
|
||||
Run the TVShowManager to display TV shows and handle user input.
|
||||
|
||||
Parameters:
|
||||
- force_int_input (bool): If True, forces the user to input an integer.
|
||||
- max_int_input (int): The maximum integer input allowed if force_int_input is True.
|
||||
|
||||
Returns:
|
||||
str: The last command entered by the user.
|
||||
"""
|
||||
total_items = len(self.tv_shows)
|
||||
last_command = ""
|
||||
while True:
|
||||
|
@ -27,6 +27,13 @@ CLOSE_CONSOLE = config_manager.get_bool('DEFAULT', 'not_close')
|
||||
|
||||
|
||||
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()
|
||||
@ -35,6 +42,13 @@ def run_function(func: Callable[..., None], close_console: bool = False) -> None
|
||||
|
||||
|
||||
def load_search_functions():
|
||||
"""
|
||||
Load search functions from modules in the 'Api/Site' directory.
|
||||
|
||||
Returns:
|
||||
Dict[str, Tuple[Callable[..., Any], str]]: A dictionary where keys are module aliases and values are tuples
|
||||
containing the search function and its usage category.
|
||||
"""
|
||||
modules = []
|
||||
loaded_functions = {}
|
||||
|
||||
@ -79,6 +93,17 @@ def load_search_functions():
|
||||
|
||||
|
||||
def search_all_sites(loaded_functions, search_string, max_sites=10):
|
||||
"""
|
||||
Search all sites for the given search string and display results.
|
||||
|
||||
Parameters:
|
||||
loaded_functions (Dict[str, Tuple[Callable[..., Any], str]]): Dictionary of loaded search functions and their usage categories.
|
||||
search_string (str): The search string to use for querying the sites.
|
||||
max_sites (int, optional): The maximum number of sites to search. Defaults to 10.
|
||||
|
||||
Returns:
|
||||
int: The total number of results found across all sites.
|
||||
"""
|
||||
total_len_database = 0
|
||||
site_count = 0
|
||||
console = Console()
|
||||
@ -131,6 +156,13 @@ def search_all_sites(loaded_functions, search_string, max_sites=10):
|
||||
|
||||
|
||||
def initialize():
|
||||
"""
|
||||
Initialize the application by displaying the start message, getting the system summary,
|
||||
setting the console mode for Windows 7, checking the Python version, and updating from GitHub.
|
||||
|
||||
Raises:
|
||||
SystemExit: If the Python version is less than 3.7.16.
|
||||
"""
|
||||
start_message()
|
||||
os_summary.get_system_summary()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user