mirror of https://github.com/mpv-player/mpv
options: add --ytdl-format option for youtube-dl format
It's passed with the '--format' option to youtube-dl. If it isn't set, we don't pass '--format best' so that youtube-dl can use the options from its configuration file. Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
parent
bf2eb51d68
commit
cf8efe3235
|
@ -435,6 +435,12 @@ Program Behavior
|
|||
|
||||
(Note: this is the replacement for the now removed libquvi support.)
|
||||
|
||||
``--ytdl-format=<best|worst|mp4|webm|...>``
|
||||
Video format/quality that is directly passed to youtube-dl. The possible
|
||||
values are specific to the website and the video, for a given url the
|
||||
available formats can be found with the command
|
||||
``youtube-dl --list-formats URL``.
|
||||
|
||||
Video
|
||||
-----
|
||||
|
||||
|
|
|
@ -131,6 +131,7 @@ const m_option_t mp_opts[] = {
|
|||
OPT_KEYVALUELIST("lua-opts", lua_opts, M_OPT_GLOBAL),
|
||||
OPT_FLAG("osc", lua_load_osc, CONF_GLOBAL),
|
||||
OPT_FLAG("ytdl", lua_load_ytdl, CONF_GLOBAL),
|
||||
OPT_STRING("ytdl-format", lua_ytdl_format, CONF_GLOBAL),
|
||||
OPT_FLAG("load-scripts", auto_load_scripts, CONF_GLOBAL),
|
||||
#endif
|
||||
|
||||
|
@ -612,6 +613,7 @@ const struct MPOpts mp_default_opts = {
|
|||
#if HAVE_LUA
|
||||
.lua_load_osc = 1,
|
||||
.lua_load_ytdl = 0,
|
||||
.lua_ytdl_format = NULL,
|
||||
#endif
|
||||
.auto_load_scripts = 1,
|
||||
.loop_times = -1,
|
||||
|
|
|
@ -62,6 +62,8 @@ typedef struct MPOpts {
|
|||
char **lua_opts;
|
||||
int lua_load_osc;
|
||||
int lua_load_ytdl;
|
||||
char *lua_ytdl_format;
|
||||
|
||||
int auto_load_scripts;
|
||||
|
||||
struct m_obj_settings *audio_driver_list, *ao_defs;
|
||||
|
|
|
@ -55,16 +55,25 @@ mp.add_hook("on_load", 10, function ()
|
|||
url = url:sub(8)
|
||||
end
|
||||
|
||||
local format = mp.get_property("options/ytdl-format")
|
||||
|
||||
-- subformat workaround
|
||||
local subformat = "srt"
|
||||
if url:find("crunchyroll.com") then
|
||||
subformat = "ass"
|
||||
end
|
||||
|
||||
local es, json = exec({
|
||||
local command = {
|
||||
ytdl.path, "-J", "--flat-playlist", "--all-subs",
|
||||
"--sub-format", subformat, "--no-playlist", "--", url
|
||||
})
|
||||
"--sub-format", subformat, "--no-playlist"
|
||||
}
|
||||
if (format ~= "") then
|
||||
table.insert(command, "--format")
|
||||
table.insert(command, format)
|
||||
end
|
||||
table.insert(command, "--")
|
||||
table.insert(command, url)
|
||||
local es, json = exec(command)
|
||||
|
||||
if (es < 0) or (json == nil) or (json == "") then
|
||||
msg.warn("youtube-dl failed, trying to play URL directly ...")
|
||||
|
|
Loading…
Reference in New Issue