diff --git a/src/downloader/yt_dlp_monkey_patch.py b/src/downloader/yt_dlp_monkey_patch.py index e4d3f4e..213d79c 100644 --- a/src/downloader/yt_dlp_monkey_patch.py +++ b/src/downloader/yt_dlp_monkey_patch.py @@ -16,6 +16,7 @@ # along with Video Downloader. If not, see . import io +import os import subprocess import sys import threading @@ -54,8 +55,26 @@ def communicate(self, *args, **kwargs): return outs, errs_buf.getvalue() +def patch_getcwd(): + def patched_chdir(path): + nonlocal cwd + chdir(path) + if os.path.isabs(path): + cwd = os.path.normpath(path) + else: + cwd = os.path.normpath(os.path.join(cwd, path)) + chdir = os.chdir + cwd = os.getcwd() + os.getcwd = lambda: cwd + os.getcwdb = lambda: os.fsencode(cwd) + os.chdir = patched_chdir + + def install_monkey_patches(): # ffmpeg writes progress information to stderr, but yt-dlp captures it # by default. Overriding this behavior allows us to show activity while # converting audio to MP3 or finishing videos. subprocess.Popen = PatchedPopen + # getcwd is broken inside of xdg-desktop-portal FUSE for documents + if os.name == 'posix': + patch_getcwd()