mirror of
https://github.com/mpv-player/mpv
synced 2025-02-17 21:27:08 +00:00
ytdl: catch bogous extractor info
Some extractors may claim to have extracted subtitles, but then set the relevant fields to null. Try to catch those cases. Fixes #2254
This commit is contained in:
parent
ba384fffca
commit
3c86bd2bb5
@ -96,12 +96,9 @@ mp.add_hook("on_load", 10, function ()
|
|||||||
local format = mp.get_property("options/ytdl-format")
|
local format = mp.get_property("options/ytdl-format")
|
||||||
local raw_options = mp.get_property_native("options/ytdl-raw-options")
|
local raw_options = mp.get_property_native("options/ytdl-raw-options")
|
||||||
|
|
||||||
-- subformat workaround
|
|
||||||
local subformat = "ass/srt/best"
|
|
||||||
|
|
||||||
local command = {
|
local command = {
|
||||||
ytdl.path, "--no-warnings", "-J", "--flat-playlist", "--all-subs",
|
ytdl.path, "--no-warnings", "-J", "--flat-playlist", "--all-subs",
|
||||||
"--sub-format", subformat, "--no-playlist"
|
"--sub-format", "ass/srt/best", "--no-playlist"
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Checks if video option is "no", change options accordingly
|
-- Checks if video option is "no", change options accordingly
|
||||||
@ -147,7 +144,8 @@ mp.add_hook("on_load", 10, function ()
|
|||||||
-- direct URL, nothing to do
|
-- direct URL, nothing to do
|
||||||
msg.verbose("Got direct URL")
|
msg.verbose("Got direct URL")
|
||||||
return
|
return
|
||||||
elseif not (json["_type"] == nil) and ((json["_type"] == "playlist") or (json["_type"] == "multi_video")) then
|
elseif not (json["_type"] == nil)
|
||||||
|
and ((json["_type"] == "playlist") or (json["_type"] == "multi_video")) then
|
||||||
-- a playlist
|
-- a playlist
|
||||||
|
|
||||||
if (#json.entries == 0) then
|
if (#json.entries == 0) then
|
||||||
@ -244,18 +242,20 @@ mp.add_hook("on_load", 10, function ()
|
|||||||
for lang, sub_info in pairs(json.requested_subtitles) do
|
for lang, sub_info in pairs(json.requested_subtitles) do
|
||||||
msg.verbose("adding subtitle ["..lang.."]")
|
msg.verbose("adding subtitle ["..lang.."]")
|
||||||
|
|
||||||
local slang = lang
|
local sub = nil
|
||||||
if (lang:len() > 3) then
|
|
||||||
slang = lang:sub(1,2)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not (sub_info.data == nil) then
|
if not (sub_info.data == nil) then
|
||||||
sub = "memory://"..sub_info.data
|
sub = "memory://"..sub_info.data
|
||||||
else
|
elseif not (sub_info.url == nil) then
|
||||||
sub = sub_info.url
|
sub = sub_info.url
|
||||||
end
|
end
|
||||||
mp.commandv("sub_add", sub,
|
|
||||||
"auto", lang.." "..sub_info.ext, slang)
|
if not (sub == nil) then
|
||||||
|
mp.commandv("sub_add", sub,
|
||||||
|
"auto", sub_info.ext, lang)
|
||||||
|
else
|
||||||
|
msg.verbose("No subtitle data/url for ["..lang.."]")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user