Skip to content

Commit

Permalink
Workaround xdg-desktop-portal bug (FileNotFound)
Browse files Browse the repository at this point in the history
Fixes #264
Fixes #249
  • Loading branch information
Unrud committed Mar 31, 2024
1 parent 0dedc28 commit 039f7ae
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/downloader/yt_dlp_monkey_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with Video Downloader. If not, see <http://www.gnu.org/licenses/>.

import io
import os
import subprocess
import sys
import threading
Expand Down Expand Up @@ -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()

0 comments on commit 039f7ae

Please sign in to comment.