mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
Merge branch 'master' into use_preffered_history_config_option
This commit is contained in:
@@ -133,10 +133,14 @@ def update_app(force=False):
|
||||
if sys.prefix == sys.base_prefix:
|
||||
# ensure NOT in a venv, where --user flag can cause an error.
|
||||
# TODO: Get value of 'include-system-site-packages' in pyenv.cfg.
|
||||
args.append('--user')
|
||||
args.append("--user")
|
||||
|
||||
process = subprocess.run(args)
|
||||
if process.returncode == 0:
|
||||
print(
|
||||
"[green]Its recommended to run the following after updating:\n\tfastanime config --update (to get the latest config docs)\n\tfastanime cache --clean (to get rid of any potential issues)[/]",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return True, release_json
|
||||
else:
|
||||
return False, release_json
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from configparser import ConfigParser
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from rich import print
|
||||
|
||||
from ..constants import (
|
||||
ASSETS_DIR,
|
||||
S_PLATFORM,
|
||||
@@ -60,6 +64,8 @@ class Config(object):
|
||||
"normalize_titles": "True",
|
||||
"notification_duration": "120",
|
||||
"max_cache_lifetime": "03:00:00",
|
||||
"mpv_args": "",
|
||||
"mpv_pre_args": "",
|
||||
"per_page": "15",
|
||||
"player": "mpv",
|
||||
"preferred_history": "local",
|
||||
@@ -96,8 +102,16 @@ class Config(object):
|
||||
self.configparser.add_section("anilist")
|
||||
|
||||
# --- set config values from file or using defaults ---
|
||||
if os.path.exists(USER_CONFIG_PATH) and not no_config:
|
||||
self.configparser.read(USER_CONFIG_PATH, encoding="utf-8")
|
||||
try:
|
||||
if os.path.exists(USER_CONFIG_PATH) and not no_config:
|
||||
self.configparser.read(USER_CONFIG_PATH, encoding="utf-8")
|
||||
except Exception as e:
|
||||
print(
|
||||
"[yellow]Warning[/]: Failed to read config file using default configuration",
|
||||
file=sys.stderr,
|
||||
)
|
||||
logger.error(f"Failed to read config file: {e}")
|
||||
time.sleep(5)
|
||||
|
||||
# get the configuration
|
||||
self.auto_next = self.configparser.getboolean("stream", "auto_next")
|
||||
@@ -149,6 +163,8 @@ class Config(object):
|
||||
+ max_cache_lifetime[1] * 3600
|
||||
+ max_cache_lifetime[2] * 60
|
||||
)
|
||||
self.mpv_args = self.configparser.get("general", "mpv_args")
|
||||
self.mpv_pre_args = self.configparser.get("general", "mpv_pre_args")
|
||||
self.per_page = self.configparser.get("anilist", "per_page")
|
||||
self.player = self.configparser.get("stream", "player")
|
||||
self.preferred_history = self.configparser.get("stream", "preferred_history")
|
||||
@@ -198,7 +214,10 @@ class Config(object):
|
||||
def set_fastanime_config_environs(self):
|
||||
current_config = []
|
||||
for key in self.default_config:
|
||||
current_config.append((f"FASTANIME_{key.upper()}", str(getattr(self, key))))
|
||||
if not os.environ.get(f"FASTANIME_{key.upper()}"):
|
||||
current_config.append(
|
||||
(f"FASTANIME_{key.upper()}", str(getattr(self, key)))
|
||||
)
|
||||
os.environ.update(current_config)
|
||||
|
||||
def update_user(self, user):
|
||||
@@ -448,6 +467,14 @@ recent = {self.recent}
|
||||
# https://discord.com/oauth2/authorize?client_id=1292070065583165512
|
||||
discord = {self.discord}
|
||||
|
||||
# comma separated list of args that will be passed to mpv
|
||||
# example: --vo=kitty,--fullscreen,--volume=50
|
||||
mpv_args = {self.mpv_args}
|
||||
|
||||
# command line options passed before the mpv command
|
||||
# example: kitty
|
||||
# useful incase of wanting to run sth like: kitty mpv --vo=kitty <url>
|
||||
mpv_pre_args = {self.mpv_pre_args}
|
||||
|
||||
[stream]
|
||||
# the quality of the stream [1080,720,480,360]
|
||||
|
||||
@@ -12,12 +12,13 @@ logger = logging.getLogger(__name__)
|
||||
mpv_av_time_pattern = re.compile(r"AV: ([0-9:]*) / ([0-9:]*) \(([0-9]*)%\)")
|
||||
|
||||
|
||||
def stream_video(MPV, url, mpv_args, custom_args):
|
||||
def stream_video(MPV, url, mpv_args, custom_args, pre_args=[]):
|
||||
last_time = "0"
|
||||
total_time = "0"
|
||||
if os.environ.get("FASTANIME_DISABLE_MPV_POPEN", "False") == "False":
|
||||
process = subprocess.Popen(
|
||||
[
|
||||
pre_args
|
||||
+ [
|
||||
MPV,
|
||||
url,
|
||||
*mpv_args,
|
||||
@@ -59,7 +60,7 @@ def stream_video(MPV, url, mpv_args, custom_args):
|
||||
process.wait()
|
||||
else:
|
||||
proc = subprocess.run(
|
||||
[MPV, url, *mpv_args, *custom_args],
|
||||
pre_args + [MPV, url, *mpv_args, *custom_args],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
@@ -208,5 +209,14 @@ def run_mpv(
|
||||
mpv_args.append(f"--title={title}")
|
||||
if ytdl_format:
|
||||
mpv_args.append(f"--ytdl-format={ytdl_format}")
|
||||
stop_time, total_time = stream_video(MPV, link, mpv_args, custom_args)
|
||||
|
||||
if user_args := os.environ.get("FASTANIME_MPV_ARGS"):
|
||||
mpv_args.extend(user_args.split(","))
|
||||
|
||||
pre_args = []
|
||||
if user_args := os.environ.get("FASTANIME_MPV_PRE_ARGS"):
|
||||
pre_args = user_args.split(",")
|
||||
stop_time, total_time = stream_video(
|
||||
MPV, link, mpv_args, custom_args, pre_args
|
||||
)
|
||||
return stop_time, total_time
|
||||
|
||||
Reference in New Issue
Block a user