]> git.sesse.net Git - vlc/blob - share/luaplaylist/dailymotion.lua
659b51a41ed5c7526bea3d2a5fcb82cd201e913e
[vlc] / share / luaplaylist / dailymotion.lua
1 --[[
2     Translate Daily Motion video webpages URLs to the corresponding
3     FLV URL.
4
5  $Id$
6
7  Copyright © 2007 the VideoLAN team
8
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 --]]
23
24 -- Probe function.
25 function probe()
26     return vlc.access == "http"
27         and string.match( vlc.path, "dailymotion.com" ) 
28         and string.match( vlc.peek( 256 ), "<!DOCTYPE.*<title>Video " )
29 end
30
31 -- Parse function.
32 function parse()
33     while true
34     do 
35         line = vlc.readline()
36         if not line then break end
37         if string.match( line, "param name=\"flashvars\" value=\".*url=http" )
38         then
39             path = vlc.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\".*url=(http[^&]*).*$", "%1" ) )
40         end
41         --[[ if string.match( line, "<title>" )
42         then
43             title = vlc.decode_uri( string.gsub( line, "^.*<title>([^<]*).*$", "%1" ) )
44         end ]]
45         if string.match( line, "<meta name=\"description\"" )
46         then
47             name = vlc.resolve_xml_special_chars( string.gsub( line, "^.*name=\"description\" content=\"%w+ (.*) %w+ %w+ %w+ %w+ Videos\..*$", "%1" ) )
48             description = vlc.resolve_xml_special_chars( string.gsub( line, "^.*name=\"description\" content=\"%w+ .* %w+ %w+ %w+ %w+ Videos\. ([^\"]*)\".*$", "%1" ) )
49         end
50         if string.match( line, "<link rel=\"thumbnail\"" )
51         then
52             arturl = string.gsub( line, "^.*\"thumbnail\" type=\"([^\"]*)\".*$", "http://%1" ) -- looks like the dailymotion people mixed up type and href here ...
53         end
54         if path and name and description and arturl then break end
55     end
56     return { { path = path; name = name; description = description; url = vlc.path; arturl = arturl } }
57 end