]> git.sesse.net Git - vlc/blob - share/luaplaylist/youtube_homepage.lua
4119ccd1ee545b31eef8bfc83943045ddb6df2a5
[vlc] / share / luaplaylist / youtube_homepage.lua
1 --[[
2     Parse YouTube homepage and browse pages. Next step is to recode firefox
3     in VLC ... using Lua of course ;)
4 --]]
5
6 function probe()
7     return vlc.access == "http" and ( string.match( vlc.path, "youtube.com/%?$" ) or string.match( vlc.path, "youtube.com/browse" ) )
8 end
9
10 function parse()
11     p = {}
12     while true
13     do
14         line = vlc.readline()
15         if not line then break end
16         for _path, _artist, _name in string.gmatch( line, "href=\"(/watch%?v=[^\"]*)\" onclick=\"_hbLink%('([^']*)','Vid[^\']*'%);\">([^<]*)</a><br/>" )
17         do
18             path = "http://www.youtube.com" .. _path
19             name = vlc.resolve_xml_special_chars( _name )
20             artist = _artist
21         end
22         for _min, _sec in string.gmatch( line, "<span class=\"runtime\">(%d*):(%d*)</span>" )
23         do
24             duration = 60 * _min + _sec
25         end
26         if path and name and artist and duration then
27             table.insert( p, { path = path; name = name; artist = artist; duration = duration } )
28             path = nil
29             name = nil
30             artist = nil
31             duration = nil
32         end
33     end
34     return p
35 end