feat: Support cookies via yt-dlp & integrate logging#17
Conversation
The original goal of this commit was to add support for exporting
cookies via yt-dlp, but I also added tracing-logging & integrated it
with journald (at least for linux, the windows logging integration is
under a feature-flag and not tested as of this commit).
To support cookies, we look to see if the user has configured a profile
(in yt-dlp syntax) and then execute yt-dlp to export those cookies into
a temporary file (via the tempfile crate). Then, we read from that file
and create an mpv argument including all the headers, filtering it to
only the cookies for the host the user asked for.
|
Hey, thanks for contributing, this is great! Not entirely sure what's the purpose of setting cookies for mpv itself (instead of yt-dlp using Also perhaps having |
allows the windows compilation to build
|
You betchya! 🫡 This helps support streaming content that has access control, ie. Youtube members only content or when a login is required. The built in lua-hook for yt-dlp is hard-coded to The addition of the ...
"player_args": [
"--no-terminal",
"--script-opts=ytdl_hook-ytdl_path=/home/kayo/.local/bin/yt-dlp",
"--ytdl-raw-options-append=cookies-from-browser=firefox::none",
"--"
]
...
For sure! |
|
I had a shower thought and I think your question is valid- we should just be able to pass the ytdlp options in and it "just works" without having to inject the headers to the mpv command. I'll do more testing |
|
@giantcow I took a look at the source code for yt-dlp mpv hook and it does set HTTP headers according to So I don't think we should be doing anything on our side, in fact, as you can see in the source code, it can prevent yt-dlp hook from adding headers by itself. If YouTube at some point starts requiring additional headers (please don't), it should be easy for yt-dlp to add these. |
|
I'll still be happy to merge the logging and yt-dlp options parts of this PR, as these are definitely nice :3 |
|
I was able to verify that yt-dlp-supported websites worked without the extra cookie injections, however it doesn't work with unsupported websites (like my media server at home). I've separated the extra cookie injections into its own flag to differentiate that |
|
What's your media server running? Perhaps the extractor for it in yt-dlp could be modified to support authentication, unless you have a plain HTTP file server? |
|
Hmm, I don't see an extractor for this in yt-dlp codebase, do you just right click the video and open it in ff2mpv with direct link? |
|
I have to right click on the video element and open in ff2mpv, so the input into this native host is the link to an mp4 |
|
I did some testing with mpv and found out a few things. yt-dlp is only used on Twitch and YouTube URLs by default, you can change that using the script option with regex pattern. Also, Lua hook returns early if it detects a direct link, which prevents cookies from being set. I think a better solution would be to make a PR to mpv to expose an option for processing direct links with yt-dlp, this will make mpv work with cookies both from ff2mpv and directly from command line. diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua
index c8d3d71..ddaf9f9 100644
--- a/player/lua/ytdl_hook.lua
+++ b/player/lua/ytdl_hook.lua
@@ -9,6 +9,7 @@ local o = {
use_manifests = false,
all_formats = true,
force_all_formats = true,
+ force_direct_url = false,
thumbnails = "none",
ytdl_path = "",
}
@@ -1008,7 +1009,7 @@ local function run_ytdl_hook(url)
json["proxy"] = json["proxy"] or proxy
-- what did we get?
- if json["direct"] then
+ if json["direct"] and not o.force_direct_url then
-- direct URL, nothing to do
msg.verbose("Got direct URL")
returnThen in your mpv config you could simply do |
The original goal of this commit was to add support for exporting
cookies via yt-dlp, but I also added tracing-logging & integrated it
with journald (at least for linux, the windows logging integration is
under a feature-flag and not tested as of this commit).
To support cookies, we look to see if the user has configured a profile
(in yt-dlp syntax) and then execute yt-dlp to export those cookies into
a temporary file (via the tempfile crate). Then, we read from that file
and create an mpv argument including all the headers, filtering it to
only the cookies for the host the user asked for.
Tested with local-network file, youtube, and twitch:
My ff2mpv-rust config:
Firefox native hosts config:
The added dependencies to increase the binary size, but it seems appropriate to me
Note that I had to apply the following diff to use bloated