]> git.sesse.net Git - vlc/blob - share/lua/playlist/dailymotion.lua
fixes dailymotion parser
[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." )
28         and string.match( vlc.peek( 2048 ), "<!DOCTYPE.*video_type" )
29 end
30
31 function find( haystack, needle )
32     local _,_,ret = string.find( haystack, needle )
33     return ret
34 end
35
36 -- Parse function.
37 function parse()
38     while true
39     do
40         line = vlc.readline()
41         if not line
42         then
43             vlc.msg.err("Couldn't extract the video URL from dailymotion")
44             return { }
45         end
46         if string.match( line, "\"sequence\",")
47         then
48             line = vlc.strings.decode_uri(line):gsub("\\/", "/")
49
50             arturl = find( line, "\"videoPreviewURL\":\"([^\"]*)\"")
51             name = find( line, "\"videoTitle\":\"([^\"]*)\"")
52             description = find( line, "\"videoDescription\":\"([^\"]*)\"")
53
54            --[[ we get a list of different streams available, at various codecs
55                 and resolutions:
56
57                 Ideally, VLC would propose the different streams available,
58                 codecs and resolutions (the resolutions are part of the URL)
59
60                 For now we just built a list of preferred codecs : lowest value
61                 means highest priority
62              ]]--
63
64             -- FIXME: the hd/hq versions (in mp4) cause a lot of seeks,
65             -- for now we only get the sd (in flv) URL
66
67             -- if not path then path = find( line, "\"hqURL\":\"([^\"]*)\"") end
68             -- if not path then path = find( line, "\"hdURL\":\"([^\"]*)\"") end
69             if not path then path = find( line, "\"sdURL\":\"([^\"]*)\"") end
70
71             return { { path = path; name = name; description = description; url = vlc.path; arturl = arturl } }
72         end
73     end
74 end