mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-31 23:15:51 -08:00
feat: use click where necessary
This commit is contained in:
@@ -20,8 +20,9 @@ commands = {
|
||||
|
||||
# handle keyboard interupt
|
||||
def handle_exit(signum, frame):
|
||||
from click import clear
|
||||
|
||||
from .utils.tools import exit_app
|
||||
from .utils.utils import clear
|
||||
|
||||
clear()
|
||||
|
||||
@@ -38,6 +39,10 @@ signal.signal(signal.SIGINT, handle_exit)
|
||||
short_help="Stream Anime",
|
||||
)
|
||||
@click.version_option(__version__, "--version")
|
||||
@click.option("--log", help="Allow logging to stdout", is_flag=True)
|
||||
@click.option("--log-file", help="Allow logging to a file", is_flag=True)
|
||||
@click.option("--rich-traceback", help="Use rich to output tracebacks", is_flag=True)
|
||||
@click.option("--update", help="Update fastanime to the latest version", is_flag=True)
|
||||
@click.option(
|
||||
"-p",
|
||||
"--provider",
|
||||
@@ -124,6 +129,10 @@ signal.signal(signal.SIGINT, handle_exit)
|
||||
@click.pass_context
|
||||
def run_cli(
|
||||
ctx: click.Context,
|
||||
log,
|
||||
log_file,
|
||||
rich_traceback,
|
||||
update,
|
||||
provider,
|
||||
server,
|
||||
format,
|
||||
@@ -150,6 +159,41 @@ def run_cli(
|
||||
from .config import Config
|
||||
|
||||
ctx.obj = Config()
|
||||
if log:
|
||||
import logging
|
||||
|
||||
from rich.logging import RichHandler
|
||||
|
||||
FORMAT = "%(message)s"
|
||||
|
||||
logging.basicConfig(
|
||||
level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("logging has been initialized")
|
||||
elif log_file:
|
||||
import logging
|
||||
|
||||
from ..constants import NOTIFIER_LOG_FILE_PATH
|
||||
|
||||
format = "%(asctime)s%(levelname)s: %(message)s"
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
filename=NOTIFIER_LOG_FILE_PATH,
|
||||
format=format,
|
||||
datefmt="[%d/%m/%Y@%H:%M:%S]",
|
||||
filemode="w",
|
||||
)
|
||||
if rich_traceback:
|
||||
from rich.traceback import install
|
||||
|
||||
install()
|
||||
if update and None:
|
||||
from .app_updater import update_app
|
||||
|
||||
update_app()
|
||||
return
|
||||
|
||||
if provider:
|
||||
ctx.obj.provider = provider
|
||||
ctx.obj.load_config()
|
||||
|
||||
@@ -10,8 +10,7 @@ if TYPE_CHECKING:
|
||||
@click.option("--status", "-s", help="Whether you are logged in or not", is_flag=True)
|
||||
@click.pass_obj
|
||||
def login(config: "Config", status):
|
||||
import webbrowser
|
||||
|
||||
from click import launch
|
||||
from rich import print
|
||||
from rich.prompt import Confirm, Prompt
|
||||
|
||||
@@ -34,7 +33,7 @@ def login(config: "Config", status):
|
||||
print(
|
||||
f"A browser session will be opened ( [link]{config.fastanime_anilist_app_login_url}[/link] )",
|
||||
)
|
||||
webbrowser.open(config.fastanime_anilist_app_login_url)
|
||||
launch(config.fastanime_anilist_app_login_url, wait=True)
|
||||
print("Please paste the token provided here")
|
||||
token = Prompt.ask("Enter token")
|
||||
user = AniList.login_user(token)
|
||||
|
||||
@@ -32,7 +32,7 @@ def notifier(config: "Config"):
|
||||
print("Run the following to get started: fastanime anilist loggin")
|
||||
return
|
||||
run = True
|
||||
# NOTE: Mess around with this value at your own risk
|
||||
# WARNING: Mess around with this value at your own risk
|
||||
timeout = 2 # time is in minutes
|
||||
if os.path.exists(notified):
|
||||
with open(notified, "r") as f:
|
||||
@@ -113,6 +113,7 @@ def notifier(config: "Config"):
|
||||
app_icon=notification_image_path,
|
||||
hints={
|
||||
"image-path": notification_image_path,
|
||||
"desktop-entry": f"{APP_NAME}.desktop",
|
||||
},
|
||||
timeout=notification_duration,
|
||||
)
|
||||
|
||||
@@ -14,14 +14,12 @@ import click
|
||||
)
|
||||
# @click.pass_obj
|
||||
def config(path, desktop_entry):
|
||||
import os
|
||||
import subprocess
|
||||
pass
|
||||
|
||||
from pyshortcuts import make_shortcut
|
||||
from rich import print
|
||||
|
||||
from ...constants import APP_NAME, ICON_PATH, USER_CONFIG_PATH
|
||||
from ..utils.tools import exit_app
|
||||
|
||||
if path:
|
||||
print(USER_CONFIG_PATH)
|
||||
@@ -45,11 +43,6 @@ def config(path, desktop_entry):
|
||||
else:
|
||||
print("Failed")
|
||||
else:
|
||||
if EDITOR := os.environ.get("EDITOR"):
|
||||
subprocess.run([EDITOR, USER_CONFIG_PATH])
|
||||
exit_app()
|
||||
else:
|
||||
print("$EDITOR environment variable missing :confused:")
|
||||
print(
|
||||
"Please Set the $EDITOR environment variable to enable editing of config"
|
||||
)
|
||||
import click
|
||||
|
||||
click.edit(filename=USER_CONFIG_PATH)
|
||||
|
||||
@@ -27,6 +27,7 @@ if TYPE_CHECKING:
|
||||
)
|
||||
@click.pass_obj
|
||||
def download(config: "Config", anime_title, episode_range, highest_priority):
|
||||
from click import clear
|
||||
from rich import print
|
||||
from rich.progress import Progress
|
||||
from thefuzz import fuzz
|
||||
@@ -36,7 +37,7 @@ def download(config: "Config", anime_title, episode_range, highest_priority):
|
||||
from ...libs.fzf import fzf
|
||||
from ...Utility.downloader.downloader import downloader
|
||||
from ..utils.tools import exit_app
|
||||
from ..utils.utils import clear, fuzzy_inquirer
|
||||
from ..utils.utils import fuzzy_inquirer
|
||||
|
||||
anime_provider = AnimeProvider(config.provider)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from ...cli.config import Config
|
||||
@click.argument("anime_title", required=True, type=str)
|
||||
@click.pass_obj
|
||||
def search(config: Config, anime_title: str, episode_range: str):
|
||||
from click import clear
|
||||
from rich import print
|
||||
from rich.progress import Progress
|
||||
from thefuzz import fuzz
|
||||
@@ -25,7 +26,7 @@ def search(config: Config, anime_title: str, episode_range: str):
|
||||
from ...libs.rofi import Rofi
|
||||
from ..utils.mpv import run_mpv
|
||||
from ..utils.tools import exit_app
|
||||
from ..utils.utils import clear, fuzzy_inquirer
|
||||
from ..utils.utils import fuzzy_inquirer
|
||||
|
||||
anime_provider = AnimeProvider(config.provider)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import random
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from click import clear
|
||||
from InquirerPy import inquirer
|
||||
from InquirerPy.validator import EmptyInputValidator
|
||||
from rich import print
|
||||
@@ -19,7 +20,7 @@ from ...Utility.data import anime_normalizer
|
||||
from ...Utility.utils import anime_title_percentage_match, sanitize_filename
|
||||
from ..utils.mpv import run_mpv
|
||||
from ..utils.tools import QueryDict, exit_app
|
||||
from ..utils.utils import clear, fuzzy_inquirer
|
||||
from ..utils.utils import fuzzy_inquirer
|
||||
from .utils import aniskip
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from InquirerPy import inquirer
|
||||
from thefuzz import fuzz
|
||||
|
||||
from ...constants import PLATFORM
|
||||
from ...Utility.data import anime_normalizer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -41,14 +39,9 @@ def get_true_bg(string, r: int, g: int, b: int) -> str:
|
||||
return f"\033[48;2;{r};{g};{b};m{string}{RESET}"
|
||||
|
||||
|
||||
def clear():
|
||||
if PLATFORM == "Windows":
|
||||
os.system("cls")
|
||||
else:
|
||||
os.system("clear")
|
||||
|
||||
|
||||
def fuzzy_inquirer(prompt: str, choices, **kwargs):
|
||||
from click import clear
|
||||
|
||||
clear()
|
||||
action = inquirer.fuzzy(
|
||||
prompt,
|
||||
|
||||
Reference in New Issue
Block a user