]> git.sesse.net Git - vlc/blob - share/lua/playlist/metachannels.lua
youtube.lua: descramble signatures by parsing javascript code
[vlc] / share / lua / playlist / metachannels.lua
1 --[[
2  $Id$
3
4  Copyright © 2010 VideoLAN and AUTHORS
5
6  Authors: Rémi Duraffort <ivoire at videolan dot org>
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 --]]
22
23 require "simplexml"
24
25 function probe()
26     return vlc.access == 'http' and string.match( vlc.path, 'metachannels.com' )
27 end
28
29 function parse()
30     local webpage = ''
31     while true do
32         local line = vlc.readline()
33         if line == nil then break end
34         webpage = webpage .. line
35     end
36
37     local feed = simplexml.parse_string( webpage )
38     local channel = feed.children[1]
39
40     -- list all children that are items
41     local tracks = {}
42     for _,item in ipairs( channel.children ) do
43         if( item.name == 'item' ) then
44             simplexml.add_name_maps( item )
45             local url = vlc.strings.resolve_xml_special_chars( item.children_map['link'][1].children[1] )
46             local title = vlc.strings.resolve_xml_special_chars( item.children_map['title'][1].children[1] )
47             local arturl = nil
48             if item.children_map['media:thumbnail'] then
49                 arturl = vlc.strings.resolve_xml_special_chars( item.children_map['media:thumbnail'][1].attributes['url'] )
50             end
51             table.insert( tracks, { path = url,
52                                     title = title,
53                                     arturl = arturl,
54                                     options = {':play-and-pause'} } )
55         end
56     end
57
58     return tracks
59 end
60