akiirui / mpv-handler

A protocol handler for mpv. Use mpv and yt-dlp to play video and music from the websites.
MIT License
259 stars 22 forks source link

Support title parameter #62

Closed ycs77 closed 1 month ago

ycs77 commented 1 month ago

Could you support the title parameter for mpv-handler from mpv --title? Because the title sometimes always shows the playlist.m3u8 from the URL, I want to customize it. And thanks for your package helping me🥰

The --title option reference: https://github.com/mpv-player/mpv/blob/53f2619dbd740b71bdd4277f096d077ffb8d571b/DOCS/man/options.rst#window

akiirui commented 1 month ago

mpv-handler doesn't do this work. The title is obtained by yt-dlp parsing the URL or mpv parsing the video file. I am not sure about your use case. If you play a video from the website supported by yt-dlp but do not get the correct title, please go to yt-dlp to give feedback.

ycs77 commented 1 month ago

I don't use yt-dlp.

I have a playlist containing the video's m3u8 URL, the title now only gets from the video path, and each video is shown the title playlist.m3u8:

https://example.com/aaa/playlist.m3u8
https://example.com/bbb/playlist.m3u8
https://example.com/other/playlist.m3u8

Now open the video basic example mpv command like this:

mpv https://example.com/aaa/playlist.m3u8
mpv https://example.com/bbb/playlist.m3u8
mpv https://example.com/other/playlist.m3u8

Screenshot 2024-09-29 011612

And the custom video title of the mpv command like this

mpv https://example.com/aaa/playlist.m3u8 --title="A custom title"
mpv https://example.com/bbb/playlist.m3u8 --title="B custom title"
mpv https://example.com/other/playlist.m3u8 --title="My custom title"

Screenshot 2

So I want to support the custom title parameter for the mpv-handler.

akiirui commented 1 month ago

So, you have a self maintenance userscript to support some special sites?

ycs77 commented 1 month ago

So, you have a self maintenance userscript to support some special sites?

Yes.

akiirui commented 1 month ago

I have implemented this feature, but when testing it I found that --title does not work. It always shows filename.

Screenshot From 2024-09-29 05-29-26

And I'm wondering if this feature is necessary. If the m3u8 file is created by yourself, it is better to try adding #EXTINF:.

ycs77 commented 1 month ago

I implemented this feature in #64, but this is my first writing the Rust, I have some shortcomings, please adjust them better 😅.

This worked in Windows 11 (my work OS), but I don't know if Linux is work possible.

akiirui commented 1 month ago

Done, please try v_title option. You should encode title by url-safe base64.

ycs77 commented 1 month ago

Thanks!

And now is have another bug. If the v_title contains Chinese characters will throw the error InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range., so I'll use the other method instead the btoa() function, final I require the package js-base64 into my user script to solve this problem.

// ==UserScript==
// ...
// @require      https://cdn.jsdelivr.net/npm/js-base64@3.7.7/base64.min.js
// ==/UserScript==

// this will throw `InvalidCharacterError`
let data = btoa("你好,世界");

// change to this will be solved
let data = Base64.encode("你好,世界");

let safe = data.replace(/\//g, "_").replace(/\+/g, "-").replace(/\=/g, "");

I think adding this solution to README will be better, let others know about this situation.

akiirui commented 1 month ago

It's just a simple example. You can use the js-base64 library, but it's not the only way.

And js-base64 provides a url-safe encoding method Base64.encodeURI

ycs77 commented 1 month ago

I see. Thanks for your reply!