jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
554 stars 69 forks source link

Add Youtube DL options support #58

Closed LawrenceJGD closed 6 years ago

LawrenceJGD commented 6 years ago

You could add Youtube DL options such as changing the video format or even give options using --ytdl-raw-options, it would be very useful for certain scripts to choose predefined formats.

Sorry for my bad English.

McSinyx commented 6 years ago

That's already supported under the name of option access. You could either do it at initation (e.g. mp = MPV(ytdl_format='best')) or like in the given link.

LawrenceJGD commented 6 years ago

Oh, I had not seen it, but is it possible to do something similar to --ytdl-format=244+bestaudio? because I can not make it work well.

Excuse me if I ask silly questions, I'm a novice in programming.

McSinyx commented 6 years ago

I'm afraid that 244+bestaudio is not a valid format. It can only be either a format code (244), or an expression describing the format (bestaudio), not both.

Edit: Accept my apology, 244+bestaudio does work because the format 244 is video only. Does this work for you:

from mpv import MPV

mp = MPV(ytdl=True, ytdl_format='244+bestaudio', input_default_bindings=True,
         input_vo_keyboard=True)
mp.play('https://www.youtube.com/watch?v=n5PvkLg8LQk')
mp.wait_for_playback()
mp.quit()
LawrenceJGD commented 6 years ago

Now it works, thanks for the help.

McSinyx commented 6 years ago

I'm glad to hear so. If everything runs fine, please close the issue. Thanks.

arrudagates commented 4 years ago

Apparently ytdl_raw_options doesn't work, i'm trying to use --no-cache-dir because that's a fix from their issues section. Edit: it actually works, and just for the sake of people like me that can't find any information about this heres what you do: player = mpv.MPV(ytdl=True,ytdl_raw_options="no-cache-dir=" if you have a no argument flag you have to end with '=', that was my problem.

jaseg commented 4 years ago

The following works:

import mpv                                                                                                              
player = mpv.MPV(ytdl = True, log_handler=print, loglevel='debug', ytdl_raw_options='foo=bar,baz=23')
player.play('https://www.youtube.com/watch?v=SkgTxQm9DWM')

You can see that the correct options are passed to youtube-dl in the console debug output. Direct passthrough of python dicts as MPV node objects indeed seems to be broken, but the fall-back to passing command-line strings is ok I think.

You can also change this option at runtime, AFAICT with the updated arguments being used for the next youtube-dl invocation:

player['ytdl-raw-options'] = 'foo=bar,baz=42'