[vlc-commits] youtube.lua: preferred resolution selection
Pierre Ynard
git at videolan.org
Thu Sep 15 20:37:45 CEST 2011
vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Thu Sep 15 20:37:06 2011 +0200| [d11ea1365dcb34ff5447aa15c08ddf3444d4ae55] | committer: Pierre Ynard
youtube.lua: preferred resolution selection
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d11ea1365dcb34ff5447aa15c08ddf3444d4ae55
---
share/lua/playlist/youtube.lua | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index 36cccdf..3e070f6 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -37,6 +37,17 @@ function get_arturl()
return "http://img.youtube.com/vi/"..video_id.."/default.jpg"
end
+function get_prefres()
+ local prefres = -1
+ if vlc.var and vlc.var.inherit then
+ prefres = vlc.var.inherit(nil, "preferred-resolution")
+ if prefres == nil then
+ prefres = -1
+ end
+ end
+ return prefres
+end
+
-- Probe function.
function probe()
if vlc.access ~= "http" and vlc.access ~= "https" then
@@ -87,6 +98,24 @@ function parse()
-- JSON parameters, also formerly known as "swfConfig",
-- "SWF_ARGS", "swfArgs" ...
if string.match( line, "PLAYER_CONFIG" ) then
+ if not fmt then
+ prefres = get_prefres()
+ if prefres >= 0 then
+ fmt_list = string.match( line, "\"fmt_list\": \"(.-)\"" )
+ if fmt_list then
+ for itag,height in string.gmatch( fmt_list, "(%d+)\\/%d+x(%d+)\\/[^,]+" ) do
+ -- Apparently formats are listed in quality
+ -- order, so we take the first one that works,
+ -- or fallback to the lowest quality
+ fmt = itag
+ if tonumber(height) <= prefres then
+ break
+ end
+ end
+ end
+ end
+ end
+
url_map = string.match( line, "\"url_encoded_fmt_stream_map\": \"(.-)\"" )
if url_map then
-- FIXME: do this properly
More information about the vlc-commits
mailing list