From 3ae7c259f5d3f20f40d7dd03bcb9456fe9fe4b9b Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Mon, 30 Jul 2012 21:53:05 +0300 Subject: [PATCH] Rewrite YouTube.choose_best as YouTube.ch_best The library no longer expects the media scripts to set both 'default' and 'best' media streams. Instead, only the 'best' quality stream is set if there are >1 streams available. The media script is still responsible to determine the best media stream. NOTES: - Format IDs are now "media stream format IDs" ("fmt_id") which are used to identify the media streams (when there are >1) - If there is only one media stream available, it is not necessary to set any media stream format IDs ("fmt_id") - default stream is whatever the media script sets as the first stream in the returned qargs.streams - best is now a flag (boolean) --- share/lua/media/youtube.lua | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/share/lua/media/youtube.lua b/share/lua/media/youtube.lua index 6753b21..9267461 100644 --- a/share/lua/media/youtube.lua +++ b/share/lua/media/youtube.lua @@ -164,6 +164,18 @@ function YouTube.iter_streams(config, U) return r end +-- Picks the stream with the highest video height property +-- as the best in quality. +function YouTube.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 YouTube.get_video_info(self) local config,U = YouTube.get_config(self) @@ -202,29 +214,6 @@ function YouTube.get_video_info(self) return self end -function YouTube.choose_best(formats) -- Highest quality available - local r = {width=0, height=0, url=nil} - local U = require 'quvi/util' - for _,v in pairs(formats) do - if U.is_higher_quality(v,r) then - r = v - end - end --- for k,v in pairs(r) do print(k,v) end - return r -end - -function YouTube.choose_default(formats) - local r = formats[1] -- Either whatever YouTube returns as the first. - for _,v in pairs(formats) do - if v.height == 480 then -- Or, whichever is of 480p and found first. - r = v - break - end - end - return r -end - YouTube.conv_table = { -- Deprecated. -- flv flv_240p = '5', -- 2.11.4.GIT