fix: implement another way to get timestamps from mpv due to issues on nixos

This commit is contained in:
benex
2024-11-16 22:06:28 +03:00
parent 7b11e0a301
commit 02e35b66cb
2 changed files with 30 additions and 6 deletions

View File

@@ -35,6 +35,7 @@ class Config(object):
"continue_from_history": "True",
"default_media_list_tracking": "None",
"downloads_dir": USER_VIDEOS_DIR,
"disable_mpv_popen": "True",
"episode_complete_at": "80",
"ffmpegthumbnailer_seek_time": "-1",
"force_forward_tracking": "true",
@@ -80,11 +81,17 @@ class Config(object):
if os.path.exists(USER_CONFIG_PATH):
self.configparser.read(USER_CONFIG_PATH, encoding="utf-8")
# TODO: rewrite all this removing the useless functions
# hate technical debt
# why did i do this lol
self.auto_next = self.get_auto_next()
self.auto_select = self.get_auto_select()
self.cache_requests = self.get_cache_requests()
self.continue_from_history = self.get_continue_from_history()
self.default_media_list_tracking = self.get_default_media_list_tracking()
self.disable_mpv_popen = self.configparser.getboolean(
"stream", "disable_mpv_popen"
)
self.downloads_dir = self.get_downloads_dir()
self.episode_complete_at = self.get_episode_complete_at()
self.ffmpegthumbnailer_seek_time = self.get_ffmpegthumnailer_seek_time()
@@ -514,6 +521,15 @@ episode_complete_at = {self.episode_complete_at}
# or just switch to arch linux
use_python_mpv = {self.use_python_mpv}
# whether to use popen to get the timestamps for continue_from_history
# implemented because popen does not work for some reason in nixos
# if you are on nixos and you have a solution to this problem please share
# i will be glad to hear it 😄
# So for now ignore this option
# and anyways the new method of getting timestamps is better
disable_mpv_popen = {self.disable_mpv_popen}
# force mpv window
# the default 'immediate' just makes mpv to open the window even if the video has not yet loaded
# done for asthetics

View File

@@ -9,11 +9,13 @@ from ...constants import S_PLATFORM
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):
last_time = "0"
total_time = "0"
if os.environ.get("FASTANIME_DISABLE_MPV_POPEN", "0") == "0":
if os.environ.get("FASTANIME_DISABLE_MPV_POPEN", "False") == "False":
process = subprocess.Popen(
[
MPV,
@@ -29,8 +31,6 @@ def stream_video(MPV, url, mpv_args, custom_args):
encoding="utf-8",
)
av_time_pattern = re.compile(r"AV: ([0-9:]*) / ([0-9:]*) \(([0-9]*)%\)")
try:
while True:
if not process.stderr:
@@ -40,11 +40,10 @@ def stream_video(MPV, url, mpv_args, custom_args):
if output:
# Match the timestamp in the output
match = av_time_pattern.search(output.strip())
match = mpv_av_time_pattern.search(output.strip())
if match:
current_time = match.group(1)
total_time = match.group(2)
match.group(3)
last_time = current_time
# Check if the process has terminated
@@ -59,7 +58,16 @@ def stream_video(MPV, url, mpv_args, custom_args):
process.terminate()
process.wait()
else:
subprocess.run([MPV, url, *mpv_args, *custom_args])
proc = subprocess.run(
[MPV, url, *mpv_args, *custom_args], capture_output=True, text=True
)
if proc.stdout:
for line in reversed(proc.stdout.split("\n")):
match = mpv_av_time_pattern.search(line.strip())
if match:
last_time = match.group(1)
total_time = match.group(2)
break
return last_time, total_time