]> git.sesse.net Git - vlc/blob - share/lua/playlist/dailymotion.lua
Move lua{intf,playlist,meta} to lua/{intf,playlist,meta}. I haven't been able to...
[vlc] / share / lua / playlist / 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=\".*video=" )
38         then
39             arturl = vlc.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\".*preview=([^&]*).*$", "%1" ) )
40             videos = vlc.decode_uri( string.gsub( line, "^.*param name=\"flashvars\" value=\".*video=([^&]*).*$", "%1" ) )
41        --[[ we get a list of different streams available, at various codecs
42             and resolutions:
43             /A@@spark||/B@@spark-mini||/C@@vp6-hd||/D@@vp6||/E@@h264
44             Not everybody can decode HD, not everybody has a 80x60 screen,
45             H264/MP4 is buggy , so i choose VP6 as the highest priority
46
47             Ideally, VLC would propose the different streams available, codecs
48             and resolutions (the resolutions are part of the URL)
49
50             For now we just built a list of preferred codecs : lowest value
51             means highest priority
52          ]]
53             local pref = { ["vp6"]=0, ["spark"]=1, ["h264"]=2, ["vp6-hd"]=3, ["spark-mini"]=4 }
54             local available = {}
55             for n in string.gmatch(videos, "[^|]+") do
56                 i = string.find(n, "@@")
57                 if i then
58                     available[string.sub(n, i+2)] = string.sub(n, 0, i-1)
59                 end
60             end
61             local score = 666
62             local bestcodec
63             for codec,_ in pairs(available) do
64                 if pref[codec] < score then
65                     bestcodec = codec
66                     score = pref[codec]
67                 end
68             end
69             if bestcodec then
70                 path = "http://dailymotion.com" .. available[bestcodec]
71             end
72         end
73         if string.match( line, "<meta name=\"description\"" )
74         then
75             name = vlc.resolve_xml_special_chars( string.gsub( line, "^.*name=\"description\" content=\"%w+ (.*) %w+ %w+ %w+ %w+ Videos\..*$", "%1" ) )
76             description = vlc.resolve_xml_special_chars( string.gsub( line, "^.*name=\"description\" content=\"%w+ .* %w+ %w+ %w+ %w+ Videos\. ([^\"]*)\".*$", "%1" ) )
77         end
78         if path and name and description and arturl then break end
79     end
80     return { { path = path; name = name; description = description; url = vlc.path; arturl = arturl } }
81 end