summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-21 16:27:56 +0100
committerwm4 <wm4@nowhere>2020-02-21 16:27:56 +0100
commit2b9b77fcf363df70a231083351abfef31e42ab1a (patch)
treeb82d7630502eb63fe5f75d2d42b418f38226973a /player/lua
parentc1f7b0c5359ff06e823f2d7cb00846b2b9f3c590 (diff)
downloadmpv-2b9b77fcf363df70a231083351abfef31e42ab1a.tar.bz2
mpv-2b9b77fcf363df70a231083351abfef31e42ab1a.tar.xz
ytdl_hook: fix audio codec with some extractors
E.g. soundcloud. While it still worked, not having the audio codec was pretty annoying.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/ytdl_hook.lua16
1 files changed, 11 insertions, 5 deletions
diff --git a/player/lua/ytdl_hook.lua b/player/lua/ytdl_hook.lua
index a67a39555e..6eadcc29a6 100644
--- a/player/lua/ytdl_hook.lua
+++ b/player/lua/ytdl_hook.lua
@@ -39,6 +39,12 @@ local safe_protos = Set {
"data"
}
+-- For some sites, youtube-dl returns the audio codec (?) only in the "ext" field.
+local ext_map = {
+ ["mp3"] = "mp3",
+ ["opus"] = "opus",
+}
+
local codec_map = {
-- src pattern = mpv codec
["vtt"] = "webvtt",
@@ -379,15 +385,16 @@ local function formats_to_edl(json, formats, use_all_formats)
if track.vcodec and track.vcodec ~= "none" then
tracks[#tracks + 1] = {
media_type = "video",
- codec = track.vcodec,
+ codec = map_codec_to_mpv(track.vcodec),
}
end
-- Tries to follow the strange logic that vcodec unset means it's
- -- an audio stream, even if acodec is (supposedly) sometimes unset.
+ -- an audio stream, even if acodec is sometimes unset.
if (#tracks == 0) or (track.acodec and track.acodec ~= "none") then
tracks[#tracks + 1] = {
media_type = "audio",
- codec = track.acodec,
+ codec = map_codec_to_mpv(track.acodec) or
+ ext_map[track.ext],
}
end
if #tracks == 0 then
@@ -402,7 +409,6 @@ local function formats_to_edl(json, formats, use_all_formats)
if use_all_formats then
for _, sub in ipairs(tracks) do
-- A single track that is either audio or video. Delay load it.
- local codec = map_codec_to_mpv(sub.codec)
local props = ""
if sub.media_type == "video" then
props = props .. ",w=" .. as_integer(track.width)
@@ -412,7 +418,7 @@ local function formats_to_edl(json, formats, use_all_formats)
props = props .. ",samplerate=" .. as_integer(track.asr)
end
hdr[#hdr + 1] = "!delay_open,media_type=" .. sub.media_type ..
- ",codec=" .. (codec or "null") .. props
+ ",codec=" .. (sub.codec or "null") .. props
-- Add bitrate information etc. for better user selection.
local byterate = 0