ytdl: Adapt to new subtitles structure

The requested formats can be sorted by preference and the result gives now an url or the subtitles file content

(cherry picked from commit 7281a72fab)
This commit is contained in:
Jaime Marquínez Ferrándiz
2015-02-25 11:00:55 +09:00
committed by Diogo Franco (Kovensky)
parent 6bf46eae23
commit edf0b93703
+11 -9
View File
@@ -3,7 +3,7 @@ local msg = require 'mp.msg'
local ytdl = {
path = "youtube-dl",
minver = "2014.11.26",
minver = "2015.02.23.1",
vercheck = nil,
}
@@ -82,10 +82,7 @@ mp.add_hook("on_load", 10, function ()
local format = mp.get_property("options/ytdl-format")
-- subformat workaround
local subformat = "srt"
if url:find("crunchyroll.com") then
subformat = "ass"
end
local subformat = "ass/srt/best"
local command = {
ytdl.path, "-J", "--flat-playlist", "--all-subs",
@@ -209,8 +206,8 @@ mp.add_hook("on_load", 10, function ()
mp.set_property("file-local-options/media-title", json.title)
-- add subtitles
if not (json.subtitles == nil) then
for lang, script in pairs(json.subtitles) do
if not (json.requested_subtitles == nil) then
for lang, sub_info in pairs(json.requested_subtitles) do
msg.verbose("adding subtitle ["..lang.."]")
local slang = lang
@@ -218,8 +215,13 @@ mp.add_hook("on_load", 10, function ()
slang = lang:sub(1,2)
end
mp.commandv("sub_add", "memory://"..script,
"auto", lang.." "..subformat, slang)
if not (sub_info.data == nil) then
sub = "memory://"..sub_info.data
else
sub = sub_info.url
end
mp.commandv("sub_add", sub,
"auto", lang.." "..sub_info.ext, slang)
end
end