Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ytdl_hook-ytdl_path does not expand-path ~~/ #15558

Open
6 tasks done
ahaoboy opened this issue Dec 22, 2024 · 7 comments
Open
6 tasks done

ytdl_hook-ytdl_path does not expand-path ~~/ #15558

ahaoboy opened this issue Dec 22, 2024 · 7 comments
Labels

Comments

@ahaoboy
Copy link

ahaoboy commented Dec 22, 2024

mpv Information

mpv v0.39.0-521-g96bebf09 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
 built on Dec 21 2024 00:07:25
libplacebo version: v7.350.0 (v7.349.0-30-g056b852-dirty)
FFmpeg version: N-118098-gc90e0777d
FFmpeg library versions:
   libavcodec      61.27.101
   libavdevice     61.4.100
   libavfilter     10.6.101
   libavformat     61.9.101
   libavutil       59.51.100
   libswresample   5.4.100
   libswscale      8.12.100

Other Information

- Windows version: win11
- GPU model, driver and version:
- Source of mpv:
- Latest known working version:
- Issue started after the following happened:

Reproduction Steps

I want to set ytdl_hook-ytdl_path to a path relative to the mpv installation directory or config directory, but it doesn't seem to work

There is the following directory structure, yt-dlp.exe is placed in the portable_config directory

.
├── mpv.com
├── mpv.exe
├── portable_config
│   ├── cookies.txt
│   ├── input.conf
│   ├── mpv.conf
│   └── yt-dlp.exe
└── updater.bat

When setting both screenshot-template and ytdl_hook-ytdl_path, only ~~/ in screenshot-template is processed correctly

screenshot-template="~~/MPV-%P-N%n"
script-opts=ytdl_hook-ytdl_path="~~/yt-dlp.exe"

log

[   4.416][d][cplayer] Run command: subprocess, flags=64, args=[args="~~/yt-dlp.exe,--no-warnings,-J,--flat-playlist,--sub-format,ass/srt/best,--format,bestvideo+bestaudio/best,--cookies,~~/cookies.txt,--mark-watched,--sub-langs,all,--write-srt,--no-playlist,--,https://www.youtube.com/watch?v=L949-42Pcjw", playback_only="yes", capture_size="67108864", capture_stdout="yes", capture_stderr="yes", detach="no", env="", stdin_data="", passthrough_stdin="no"]
[   4.416][v][ytdl_hook] Starting subprocess: [~~/yt-dlp.exe, --no-warnings, -J, --flat-playlist, --sub-format, ass/srt/best, --format, bestvideo+bestaudio/best, --cookies, ~~/cookies.txt, --mark-watched, --sub-langs, all, --write-srt, --no-playlist, --, https://www.youtube.com/watch?v=L949-42Pcjw]
[   4.417][e][ytdl_hook] Subprocess failed: init
[   4.417][v][ytdl_hook] youtube-dl with path ~~/yt-dlp.exe not found in PATH or not enough permissions
[   4.417][v][cplayer] Set property: user-data/mpv/ytdl/path="" -> 1
[   4.417][v][cplayer] Set property: user-data/mpv/ytdl/json-subprocess-result={"status":-3,"error_string":"init","killed_by_us":false,"stdout":"","stderr":""} -> 1
[   4.417][v][ytdl_hook] status: -3
[   4.417][v][ytdl_hook] reason: init
[   4.417][v][ytdl_hook] stdout: 
[   4.417][v][ytdl_hook] stderr: 
[   4.417][e][ytdl_hook] 
[   4.417][e][ytdl_hook] youtube-dl failed: not found or not enough permissions

The source code seems to use the passed string directly without using expand-path

    local command = {
        ytdl.path, "--no-warnings", "-J", "--flat-playlist",
        "--sub-format", "ass/srt/best"
    }

The cookie path may also contain ~~/

ytdl-raw-options=cookies=~~/cookies.txt,mark-watched=

Expected Behavior

~~/ in ytdl_hook-ytdl_path is handled by expand-path

Actual Behavior

ytdl_hook-ytdl_path is treated as a normal string

Log File

log.txt

Sample Files

No response

I carefully read all instruction and confirm that I did the following:

  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
@ahaoboy ahaoboy added the os:win label Dec 22, 2024
@guidocella
Copy link
Contributor

ytdl_hook.lua already calls mp.find_config_file on ytdl_path so you can just use script-opt=ytdl_hook-ytdl_path=yt-dlp (which is already searched by default).

@ahaoboy
Copy link
Author

ahaoboy commented Dec 22, 2024

ytdl_hook.lua already calls mp.find_config_file on ytdl_path so you can just use script-opt=ytdl_hook-ytdl_path=yt-dlp (which is already searched by default).

Thanks, I tested it and it works even without adding configuration as long as yt-dlp is placed in the portable_config directory
But the logic of cookies is a little different, I want to put cookies and yt-dlp in the portable_config directory

This will be in the mpv.exe directory instead of the portable_config directory.

ytdl-raw-options=cookies="cookies.txt",mark-watched=

Using ~~/ will give an error

ytdl-raw-options=cookies="~~/cookies.txt",mark-watched=
[ytdl_hook] Traceback (most recent call last):
[ytdl_hook]   File "yt_dlp\__main__.py", line 17, in <module>
[ytdl_hook]   File "yt_dlp\__init__.py", line 1093, in main
[ytdl_hook]   File "yt_dlp\__init__.py", line 991, in _real_main
[ytdl_hook]   File "yt_dlp\YoutubeDL.py", line 990, in __exit__
[ytdl_hook]   File "yt_dlp\YoutubeDL.py", line 993, in close
[ytdl_hook]   File "yt_dlp\YoutubeDL.py", line 986, in save_cookies
[ytdl_hook]   File "yt_dlp\cookies.py", line 1317, in save
[ytdl_hook]   File "contextlib.py", line 135, in __enter__
[ytdl_hook]   File "yt_dlp\cookies.py", line 1272, in open
[ytdl_hook] FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\~/cookies.txt'
[ytdl_hook] [PYI-38012:ERROR] Failed to execute script '__main__' due to unhandled exception!
[ytdl_hook] youtube-dl failed: unexpected error occurred
AV: 00:00:01 / 03:47:00 (0%) A-V:  0.000
Failed to recognize file format.

@guidocella
Copy link
Contributor

You can use this script

mp.set_property('ytdl-raw-options', 'cookies=' .. mp.command_native({'expand-path', '~~/cookies.txt'}))

or you can just use --cookies-from-browser.

@ahaoboy
Copy link
Author

ahaoboy commented Dec 22, 2024

or you can just use --cookies-from-browser.

Does not work on Windows

ytdl-raw-options=cookies-from-browser=edge,mark-watched=
[ytdl_hook] ERROR: Could not copy Chrome cookie database. See  https://github.com/yt-dlp/yt-dlp/issues/7271  for more info
[ytdl_hook] ERROR: Could not copy Chrome cookie database. See  https://github.com/yt-dlp/yt-dlp/issues/7271  for more info
[ytdl_hook] youtube-dl failed: unexpected error occurred
Failed to recognize file format.
Exiting... (Errors when loading file)

It seems that the simplest way is to put yt-dlp and cookies in the directory where mpv.exe is located.

@Samillion
Copy link
Contributor

Samillion commented Dec 22, 2024

For cookies, try to set an absolute path. See my config as example: mpv.conf/ytdl

ytdl-raw-options=cookies="C:\Program Files\mpv\ytdl_cookies.txt"

Extract cookies as described in the issue with an extension such as this one.

@ahaoboy
Copy link
Author

ahaoboy commented Dec 22, 2024

For cookies, try to set an absolute path. See my config as example: mpv.conf/ytdl

Thanks, I know that using absolute paths for yt-dlp and cookies will work, but for a script developer, if all configurations and dependent programs can be placed in the portable_config directory, it will be easy for users to install and remove.

@verygoodlee
Copy link
Contributor

cookies path also support environment variables.

On linux, ~~/ is usually the same directory as ~/.config/mpv/, and ~/ is equivalent to $HOME/, so you can use ytdl-raw-options-append=cookies=$HOME/.config/mpv/cookies.txt.

In the same way, you can use ytdl-raw-options-append=cookies=%APPDATA%\mpv\cookies.txt on Windows.

But portable config is more popular with users on Windows, there's no good solution for it, you can set a MPV_HOME environment variable and use ytdl-raw-options-append=cookies=%MPV_HOME%\cookies.txt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants