Skip to content

Commit

Permalink
feat: minor ui and ux improvements plus add edit config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Benex254 committed Jul 16, 2024
1 parent 73ce357 commit 6d077fd
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 145 deletions.
4 changes: 0 additions & 4 deletions fa
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
#! /usr/bin/bash
cd $HOME/code/python/kivy_apps/FastAnime
poetry install
clear
poetry run fastanime $*

1 change: 0 additions & 1 deletion fastanime/Utility/user_data_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(self):
with open(USER_DATA_PATH, "r") as f:
user_data = json.load(f)
self.user_data.update(user_data)
print(user_data, self.user_data)
except Exception as e:
logger.error(e)

Expand Down
5 changes: 4 additions & 1 deletion fastanime/Utility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import re
import shutil
from datetime import datetime
from functools import lru_cache

# TODO: make it use color_text instead of fixed vals
# from .kivy_markup_helper import color_text


def remove_html_tags(text):
@lru_cache()
def remove_html_tags(text: str):
clean = re.compile("<.*?>")
return re.sub(clean, "", text)

Expand Down Expand Up @@ -42,6 +44,7 @@ def move_file(source_path, dest_path):
return (0, e)


@lru_cache()
def sanitize_filename(filename: str):
"""
Sanitize a string to be safe for use as a file name.
Expand Down
9 changes: 3 additions & 6 deletions fastanime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
APP_CACHE_DIR = dirs.user_cache_dir

# video dir
USER_DOWNLOADS_DIR = dirs.user_videos_dir

print(f"USER_DOWNLOADS_DIR: {USER_DOWNLOADS_DIR}")

USER_VIDEOS_DIR = dirs.user_videos_dir

# web dirs

Expand Down Expand Up @@ -82,9 +79,9 @@ def FastAnime(gui=False, web=False):

run_gui()
elif web:
from .web import run_web
from .api import run_api

run_web()
run_api()
else:
from .cli import run_cli

Expand Down
30 changes: 23 additions & 7 deletions fastanime/cli/config.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import os
from configparser import ConfigParser
from rich import print

from .. import USER_CONFIG_PATH, USER_DOWNLOADS_DIR
from .. import USER_CONFIG_PATH, USER_VIDEOS_DIR
from ..Utility.user_data_helper import user_data_helper


class Config(object):
anime_list: list
watch_history: dict

def __init__(self) -> None:
self.load_config()

def load_config(self):
self.configparser = ConfigParser(
{
"server": "",
"continue_from_history": "False",
"quality": "0",
"auto_next": "True",
"sort_by": "search match",
"downloads_dir": USER_DOWNLOADS_DIR,
"downloads_dir": USER_VIDEOS_DIR,
"translation_type": "sub",
"preferred_language": "romaji",
}
Expand All @@ -38,16 +45,25 @@ def __init__(self) -> None:
self.preferred_language = self.get_preferred_language()

# ---- setup user data ------
self.watch_history = user_data_helper.user_data.get("watch_history", {})
self.anime_list = user_data_helper.user_data.get("animelist", [])
self.watch_history: dict = user_data_helper.user_data.get("watch_history", {})
self.anime_list: list = user_data_helper.user_data.get("animelist", [])

def update_watch_history(self, anime_id: int, episode: str | None):
self.watch_history.update({str(anime_id): episode})
user_data_helper.update_watch_history(self.watch_history)

def update_anime_list(self, anime_id: int):
self.anime_list.append(anime_id)
user_data_helper.update_animelist(self.anime_list)
def update_anime_list(self, anime_id: int, remove=False):
if remove:
try:
self.anime_list.remove(anime_id)
print("Succesfully removed :cry:")
except Exception:
print(anime_id, "Nothing to remove :confused:")
else:
self.anime_list.append(anime_id)
user_data_helper.update_animelist(self.anime_list)
print("Succesfully added :smile:")
input("Enter to continue...")

def get_downloads_dir(self):
return self.configparser.get("general", "downloads_dir")
Expand Down
Loading

0 comments on commit 6d077fd

Please sign in to comment.