mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 07:40:41 -08:00
feat: added animdl config manager
This commit is contained in:
34
app/Utility/animdl_config_manager.py
Normal file
34
app/Utility/animdl_config_manager.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from typing import TypedDict
|
||||
import plyer
|
||||
import os
|
||||
|
||||
from .yaml_parser import YamlParser
|
||||
|
||||
|
||||
class AnimdlConfig(TypedDict):
|
||||
default_player: str
|
||||
default_provider: str
|
||||
quality_string: str
|
||||
|
||||
|
||||
user_profile_path = plyer.storagepath.get_home_dir() # type: ignore
|
||||
animdl_config_folder_location = os.path.join(user_profile_path, ".animdl")
|
||||
if not os.path.exists(animdl_config_folder_location):
|
||||
os.mkdir(animdl_config_folder_location)
|
||||
|
||||
animdl_config_location = os.path.join(animdl_config_folder_location, "config.yml")
|
||||
animdl_config = YamlParser(
|
||||
animdl_config_location,
|
||||
{"default_player": "mpv", "default_provider": "AllAnime", "quality_string": "best"},
|
||||
AnimdlConfig,
|
||||
)
|
||||
|
||||
|
||||
def update_animdl_config(field_to_update: str, value):
|
||||
current_data = animdl_config.data
|
||||
current_data[f"{field_to_update}"] = value
|
||||
animdl_config.write(current_data)
|
||||
|
||||
|
||||
def get_animdl_config() -> AnimdlConfig:
|
||||
return animdl_config.data
|
||||
@@ -24,6 +24,7 @@ for link in yt_stream_links:
|
||||
Cache.append("yt_stream_links.anime", link[0], tuple(link[1]))
|
||||
|
||||
|
||||
# TODO: Make this process more efficient
|
||||
# for youtube video links gotten from from pytube which is blocking
|
||||
class MediaCardDataLoader(object):
|
||||
"""this class loads an anime media card and gets the trailer url from pytube"""
|
||||
|
||||
34
app/Utility/yaml_parser.py
Normal file
34
app/Utility/yaml_parser.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import yaml
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class YamlParser:
|
||||
"""makes managing yaml files easier"""
|
||||
|
||||
data = {}
|
||||
|
||||
def __init__(self, file_path: str, default, data_type):
|
||||
self.file_path: str = file_path
|
||||
self.data: data_type
|
||||
if os.path.exists(file_path):
|
||||
try:
|
||||
with open(self.file_path, "r") as yaml_file:
|
||||
self.data = yaml.safe_load(yaml_file)
|
||||
except:
|
||||
self.data = default
|
||||
with open(file_path, "w") as yaml_file:
|
||||
yaml.dump(default, yaml_file)
|
||||
else:
|
||||
self.data = default
|
||||
with open(file_path, "w") as yaml_file:
|
||||
yaml.dump(default, yaml_file)
|
||||
|
||||
def read(self):
|
||||
with open(self.file_path, "r") as yaml_file:
|
||||
self.data = yaml.safe_load(yaml_file)
|
||||
return self.data
|
||||
|
||||
def write(self, new_obj):
|
||||
with open(self.file_path, "w") as yaml_file:
|
||||
yaml.dump(new_obj, yaml_file)
|
||||
@@ -1,3 +0,0 @@
|
||||
default_player: mpv
|
||||
default_provider: allanime
|
||||
quality_string: "1080/best"
|
||||
48
app/animdl_config_panel.json
Normal file
48
app/animdl_config_panel.json
Normal file
@@ -0,0 +1,48 @@
|
||||
[
|
||||
{
|
||||
"type": "title",
|
||||
"title": "Providers"
|
||||
},
|
||||
{
|
||||
"type": "options",
|
||||
"title": "Default Provider",
|
||||
"desc": "Sets the default provider animdl should use",
|
||||
"section": "Providers",
|
||||
"key": "default_provider",
|
||||
"options": [
|
||||
"9anime",
|
||||
"AllAnime",
|
||||
"AnimePahe",
|
||||
"AnimeOut",
|
||||
"Animtime",
|
||||
"Kawaifu",
|
||||
"GoGoAnime",
|
||||
"Haho",
|
||||
"Marin",
|
||||
"Zoro"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "title",
|
||||
"title": "Quality"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"title": "Quality String",
|
||||
"desc": "Sets the animdl quality string",
|
||||
"section": "Quality",
|
||||
"key": "quality_string"
|
||||
},
|
||||
{
|
||||
"type": "title",
|
||||
"title": "PlayerSelection"
|
||||
},
|
||||
{
|
||||
"type": "options",
|
||||
"title": "Default Player",
|
||||
"desc": "Sets the animdl default player to use",
|
||||
"section": "PlayerSelection",
|
||||
"key": "default_player",
|
||||
"options": ["mpv", "vlc", "ffpyplayer", "celluloid", "iina"]
|
||||
}
|
||||
]
|
||||
35
app/general_settings_panel.json
Normal file
35
app/general_settings_panel.json
Normal file
@@ -0,0 +1,35 @@
|
||||
[
|
||||
{
|
||||
"type": "title",
|
||||
"title": "Preferences"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"title": "Theme Color",
|
||||
"desc": "Sets the theme color to be used for the app for more info on valid theme names refer to help",
|
||||
"section": "Preferences",
|
||||
"key": "theme_color"
|
||||
},
|
||||
{
|
||||
"type": "options",
|
||||
"title": "Theme Style",
|
||||
"desc": "Sets the app to dark or light theme",
|
||||
"section": "Preferences",
|
||||
"key": "theme_style",
|
||||
"options":["Light","Dark"]
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"title": "Downloads Directory",
|
||||
"desc": "location to download your videos",
|
||||
"section": "Preferences",
|
||||
"key": "downloads_dir"
|
||||
},
|
||||
{
|
||||
"type": "bool",
|
||||
"title": "Show Startup anime",
|
||||
"desc": "whether to show the startup anime, switch it off for faster app startup times",
|
||||
"section": "Preferences",
|
||||
"key": "is_startup_anime_enable"
|
||||
}
|
||||
]
|
||||
48
app/main.py
48
app/main.py
@@ -29,7 +29,12 @@ from kivymd.app import MDApp
|
||||
|
||||
from View.screens import screens
|
||||
from libs.animdl import AnimdlApi
|
||||
from Utility import themes_available, show_notification, user_data_helper
|
||||
from Utility import (
|
||||
themes_available,
|
||||
show_notification,
|
||||
user_data_helper,
|
||||
animdl_config_manager,
|
||||
)
|
||||
|
||||
|
||||
# Ensure the user data fields exist
|
||||
@@ -53,7 +58,7 @@ class AniXStreamApp(MDApp):
|
||||
try:
|
||||
task()
|
||||
except Exception as e:
|
||||
show_notification("An error occured while streaming",f"{e}")
|
||||
show_notification("An error occured while streaming", f"{e}")
|
||||
self.queue.task_done()
|
||||
|
||||
def downloads_worker(self, queue: Queue):
|
||||
@@ -62,7 +67,7 @@ class AniXStreamApp(MDApp):
|
||||
try:
|
||||
download_task()
|
||||
except Exception as e:
|
||||
show_notification("An error occured while downloading",f"{e}")
|
||||
show_notification("An error occured while downloading", f"{e}")
|
||||
self.downloads_queue.task_done()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@@ -116,6 +121,8 @@ class AniXStreamApp(MDApp):
|
||||
self.manager_screens.add_widget(view)
|
||||
|
||||
def build_config(self, config):
|
||||
|
||||
# General settings setup
|
||||
if vid_path := plyer.storagepath.get_videos_dir(): # type: ignore
|
||||
downloads_dir = os.path.join(vid_path, "anixstream")
|
||||
if not os.path.exists(downloads_dir):
|
||||
@@ -134,10 +141,37 @@ class AniXStreamApp(MDApp):
|
||||
},
|
||||
)
|
||||
|
||||
# animdl config settings setup
|
||||
animdl_config = animdl_config_manager.get_animdl_config()
|
||||
config.setdefaults(
|
||||
"Providers",
|
||||
{
|
||||
"default_provider": animdl_config["default_provider"],
|
||||
},
|
||||
)
|
||||
config.setdefaults(
|
||||
"Quality",
|
||||
{
|
||||
"quality_string": animdl_config["quality_string"],
|
||||
},
|
||||
)
|
||||
config.setdefaults(
|
||||
"PlayerSelection",
|
||||
{
|
||||
"default_player": animdl_config["default_player"],
|
||||
},
|
||||
)
|
||||
|
||||
def build_settings(self, settings: Settings):
|
||||
settings.add_json_panel("Settings", self.config, "settings.json")
|
||||
settings.add_json_panel(
|
||||
"Settings", self.config, "./general_settings_panel.json"
|
||||
)
|
||||
settings.add_json_panel(
|
||||
"Animdl Config", self.config, "./animdl_config_panel.json"
|
||||
)
|
||||
|
||||
def on_config_change(self, config, section, key, value):
|
||||
# TODO: Change to match case
|
||||
if section == "Preferences":
|
||||
match key:
|
||||
case "theme_color":
|
||||
@@ -151,6 +185,12 @@ class AniXStreamApp(MDApp):
|
||||
config.write()
|
||||
case "theme_style":
|
||||
self.theme_cls.theme_style = value
|
||||
elif section == "Providers":
|
||||
animdl_config_manager.update_animdl_config("default_provider", value)
|
||||
elif section == "Quality":
|
||||
animdl_config_manager.update_animdl_config("quality_string", value)
|
||||
elif section == "PlayerSelection":
|
||||
animdl_config_manager.update_animdl_config("default_player", value)
|
||||
|
||||
def on_stop(self):
|
||||
del self.downloads_worker_thread
|
||||
|
||||
Reference in New Issue
Block a user