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

How to use youtube-dl with mpv on Windows #4727

Closed
Keith94 opened this issue Aug 7, 2017 · 10 comments
Closed

How to use youtube-dl with mpv on Windows #4727

Keith94 opened this issue Aug 7, 2017 · 10 comments

Comments

@Keith94
Copy link

Keith94 commented Aug 7, 2017

I read on the mpv builds for Windows to place youtube-dl.exe in the install folder. But how does that allow YouTube videos to be played with mpv? Is there a specific command line option or other?

@rossy
Copy link
Member

rossy commented Aug 7, 2017

Passing the URL directly on the command-line is fine, eg. typing something like mpv https://www.youtube.com/watch?v=NAh9oLs67Cw into the command prompt. You can also drag/drop a YouTube URL from your browser to the mpv window.

@Keith94
Copy link
Author

Keith94 commented Aug 7, 2017

Hi,
I tried both options but they don't seem to work for me. Using command prompt results in:

C:\mpv>mpv https://www.youtube.com/watch?v=NAh9oLs67Cw
Playing: https://www.youtube.com/watch?v=NAh9oLs67Cw
[ytdl_hook] ERROR: Unable to download webpage: <urlopen error [SSL: CERTIFICATE_
VERIFY_FAILED] certificate verify failed (_ssl.c:600)> (caused by URLError(SSLEr
ror(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)'
),))
[ytdl_hook] youtube-dl failed, trying to play URL directly ...
Failed to recognize file format.
Exiting... (Errors when loading file)

And if I drop a URL from my bookmarks it doesn't load properly. Any ideas?

@wiiaboo
Copy link
Member

wiiaboo commented Aug 7, 2017

That's a python issue. Either install python 3.6.x and then pip install youtube-dl or add ytdl-raw-options=no-check-certificate= to mpv.conf.

@Hrxn
Copy link
Contributor

Hrxn commented Aug 7, 2017

Also, a Windows specific issue, you can try the steps mentioned here:
ytdl-org/youtube-dl#7309 (comment)

@Keith94
Copy link
Author

Keith94 commented Aug 7, 2017

Thank you both. This fix worked for me:

add ytdl-raw-options=no-check-certificate= to mpv.conf

Why not mention these fixes in the mpv manual/wiki/builds pages? In case it's a common issue.

@CounterPillow
Copy link
Contributor

because disabling the certificate check allows for a man-in-the-middle attack, instead you should figure out why the certificate check is failing

@wiiaboo
Copy link
Member

wiiaboo commented Aug 7, 2017

It's failing because official youtube-dl.exe uses Python 3.4 which hasn't had new binary releases for years. Python 2.7.x could be possible but then introduce unicode errors.

@sleek22
Copy link

sleek22 commented Aug 7, 2017

@Keith94

I use a Firefox add-on called "Watch with MPV". In its settings, there is a pointer to the MPV executable. I just click the button when on YouTube and the video opens up and plays in MPV. (Note: I have youtube-dl in my MPV folder). A link to the add-on is below:

https://addons.mozilla.org/en-US/firefox/addon/watch-with-mpv/

@akash-258
Copy link

Is there a way to see youtube comments in mpv with some scripts or something?

@trapke
Copy link

trapke commented Mar 1, 2021

@sleek22 @Keith94 and to anyone who wants to automatically open videos from YouTube in mpv:
This is possible by creating a custom url scheme, writing an entry in Chrome's settings file 'Preferences' (not necessary when using Firefox) and using a Tampermonkey/Greasemonkey script that stops the video and starts it in mpv.

First we'll create the custom url scheme. This is os-level based. By doing so, we can invoke mpv by using this path:
mpvyoutube://YOUTUBE_URL

mpvyoutube is chosen by me, you can take anything you want.
So let's create the registry entry for that:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\mpvyoutube]
@="URL:mpv Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\mpvyoutube\shell\open\command]
@="\"C:\\Program Files (x86)\\mpv\\mpvyoutube.bat\" \"%1\""

The location of the batch file (which we'll create) doesn't matter, just ensure that you include it in the .reg file.
Save it as .reg and execute it.

We cannot run mpv directly with the URL we want because the argument "%1" also contains the prefix "mpvyoutube://".
That's why we need a .bat which can replace that with nothing, so we're just left with the URL.

This is my batch:

@echo off
SET "argument=%1"
SET URL=%argument:mpvyoutube://=%
start "" "C:\Program Files (x86)\mpv\mpv.exe" %URL%

Now we have to add an entry in the Preferences file of Chrome (skip this step if you use Firefox)
Before that be sure to close Chrome (also by right clicking the tray icon -> Exit)
The location of the file on Windows is: %localappdata%\Google\Chrome\User Data\Default\Preferences
Make a backup of it. Now open the file in notepad and search for the following string:
"protocol_handler"

It should be something like this (in case it's empty):
"protocol_handler":{},

Insert the following into the brackets:
"allowed_origin_protocol_pairs":{"https://www.youtube.com":{"mpvyoutube":true}}

In the end it should look like this:
"protocol_handler":{"allowed_origin_protocol_pairs":{"https://www.youtube.com":{"mpvyoutube":true}}},

Now start Chrome. It should be possible to run the following command:
mpvyoutube://URL_TO_YOUTUBE_VIDEO

A prompt is displayed, which you can ignore. It won't appear when we run it from the context of YouTube.

Now we need a Tampermonkey/Greasemonkey script that can automatically stop the videos and run the custom url to invoke mpv.
I found a script online that I modified. You can find it here:
https://gist.github.com/trapke/b738f20990cb3898b47dd3e17074d03a

Here's the original code:
https://greasyfork.org/de/scripts/370504-youtube-stop-video-autoplay/code

The only change is that I added the following line in the function 'stopPlayback':
window.open('mpvyoutube://' + window.location.href, '_blank')

Just replace "mpvyoutube" with your own prefix.

Save the script and you're good to go. The videos should automatically stop in the browser and open in mpv.

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

No branches or pull requests

8 participants