[vlc-commits] commit: youtube.lua: fetch HD videos when available by default ( Pierre Ynard )
git at videolan.org
git at videolan.org
Sat Jun 5 19:23:01 CEST 2010
vlc/vlc-1.1 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Fri Jun 4 16:19:14 2010 +0200| [2f54aeae56d5f046bbde50ea2607fd351fd794a6] | committer: Pierre Ynard
youtube.lua: fetch HD videos when available by default
This also saves one HTTP redirect
(cherry picked from commit 09b6b8e32fe1e46e1f69d8dec0df29975a83f649)
Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=2f54aeae56d5f046bbde50ea2607fd351fd794a6
---
share/lua/playlist/youtube.lua | 47 +++++++++++++++++++++++++++------------
1 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index 8823925..3146478 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -59,6 +59,8 @@ end
function parse()
if string.match( vlc.path, "watch%?v=" )
then -- This is the HTML page's URL
+ -- fmt is the format of the video: 18 is HQ (mp4)
+ fmt = get_url_param( vlc.path, "fmt" )
while true do
-- Try to find the video's title
line = vlc.readline()
@@ -84,32 +86,47 @@ function parse()
_,_,t = string.find( line, "\"t\": \"(.-)\"" )
-- vlc.msg.err( t )
-- video_id = string.gsub( line, ".*&video_id:'([^']*)'.*", "%1" )
+ fmt_url_map = string.match( line, "\"fmt_url_map\": \"(.-)\"" )
+ if fmt_url_map then
+ for itag,url in string.gmatch( fmt_url_map, "(%d+)|([^,]+)" ) do
+ -- Apparently formats are listed in quality order,
+ -- so we can afford to simply take the first one
+ if not fmt or tonumber( itag ) == tonumber( fmt ) then
+ path = url
+ break
+ end
+ end
+ end
-- Also available on non-HTML5 pages: var swfHTML = (isIE) ? "<object [...]><param name=\"flashvars\" value=\"rv.2.thumbnailUrl=http%3A%2F%2Fi4.ytimg.com%2Fvi%2F3MLp7YNTznE%2Fdefault.jpg&rv.7.length_seconds=384 [...] &video_id=OHVvVmUNBFc [...] &t=OEgsToPDskK3zO44y0QN8Fr5ZSAZwCQp [...]
elseif string.match( line, "swfHTML" ) and string.match( line, "video_id" ) then
_,_,t = string.find( line, "&t=(.-)&" )
end
if name and description and artist --[[and video_id]] then break end
end
+
if not video_id then
video_id = get_url_param( vlc.path, "v" )
end
- if not base_yt_url then
- base_yt_url = "http://youtube.com/"
- end
arturl = get_arturl( vlc.path, video_id )
- -- fmt is the format of the video: 18 is HQ (mp4)
- fmt = get_url_param( vlc.path, "fmt" )
- if fmt then
- format = "&fmt=" .. fmt
- else
- format = ""
- end
- if t then
- return { { path = base_yt_url .. "get_video?video_id="..video_id.."&t="..t..format; name = name; description = description; artist = artist; arturl = arturl; options = options } }
- else
- -- This shouldn't happen ... but keep it as a backup.
- return { { path = "http://www.youtube.com/v/"..video_id; name = name; description = description; artist = artist; arturl = arturl; options=options } }
+
+ if not path then
+ if not base_yt_url then
+ base_yt_url = "http://youtube.com/"
+ end
+ if fmt then
+ format = "&fmt=" .. fmt
+ else
+ format = ""
+ end
+
+ if t then
+ path = base_yt_url .. "get_video?video_id="..video_id.."&t="..t..format
+ else
+ -- This shouldn't happen ... but keep it as a backup.
+ path = "http://www.youtube.com/v/"..video_id
+ end
end
+ return { { path = path; name = name; description = description; artist = artist; arturl = arturl; options = options } }
else -- This is the flash player's URL
if string.match( vlc.path, "title=" ) then
name = get_url_param( vlc.path, "title" )
More information about the vlc-commits
mailing list