From 0a340949732fd9c167c46df39a8a85ed5b9cdbc2 Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Tue, 1 Oct 2013 23:42:09 +0300 Subject: [PATCH] media/liveleak.lua: Add support for >1 streams Signed-off-by: Toni Gundogdu --- share/media/liveleak.lua | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/share/media/liveleak.lua b/share/media/liveleak.lua index 8b2f763..3c0abfc 100644 --- a/share/media/liveleak.lua +++ b/share/media/liveleak.lua @@ -77,10 +77,51 @@ function LiveLeak.can_parse_url(qargs) end end +function LiveLeak.stream_new(S, t) + local v_enc, v_h, c = t['file']:match('%.(%w+)_(%d+)p%.(%w+)%?') + local s = S.stream_new(t['file'] or error('no match: media stream URL')) + s.video.height = tonumber(v_h or 0) + s.video.encoding = v_enc or '' + s.container = c or '' + LiveLeak.to_id(s,t) + return s +end + function LiveLeak.iter_streams(j) - local u = j['file'] or error('no match: media stream URL') local S = require 'quvi/stream' - return {S.stream_new(u)} + if j['sources'] then -- >1 streams + local r = {} + for _,v in pairs(j['sources']) do + table.insert(r, LiveLeak.stream_new(S,v)) + end + if #r >1 then -- Pick one stream as the 'best' quality. + LiveLeak.ch_best(S, r) + end + return r + else + local u = j['file'] or error('no match: media stream URL') + return {S.stream_new(u)} + end +end + +function LiveLeak.ch_best(S, t) + local r = t[1] -- Make the first one the 'best' by default. + r.flags.best = true + for _,v in pairs(t) do + if v.video.height > r.video.height then + r = S.swap_best(r, v) + end + end +end + +function LiveLeak.to_id(s,t) + if s.container then + local q = t['label']:match('(%w%w)$'):lower() + local r = {q, s.container, s.video.encoding, s.video.height .. 'p'} + s.id = table.concat(r, '_') + else -- Fallback to 'label'. + s.id = t['label']:gsub('%W',''):lower() + end end -- vim: set ts=2 sw=2 tw=72 expandtab: -- 2.11.4.GIT