]> git.sesse.net Git - vlc/blob - share/lua/playlist/dailymotion.lua
dailymotion.lua: partially decode video title and description
[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             if name then
53                 name = string.gsub( name, "+", " " )
54             end
55             description = find( line, "\"videoDescription\":\"([^\"]*)\"")
56             if description then
57                 description = string.gsub( description, "+", " " )
58             end
59
60            --[[ we get a list of different streams available, at various codecs
61                 and resolutions:
62
63                 Ideally, VLC would propose the different streams available,
64                 codecs and resolutions (the resolutions are part of the URL)
65
66                 For now we just built a list of preferred codecs : lowest value
67                 means highest priority
68              ]]--
69
70             -- FIXME: the hd/hq versions (in mp4) cause a lot of seeks,
71             -- for now we only get the sd (in flv) URL
72
73             -- if not path then path = find( line, "\"hqURL\":\"([^\"]*)\"") end
74             -- if not path then path = find( line, "\"hdURL\":\"([^\"]*)\"") end
75             if not path then path = find( line, "\"sdURL\":\"([^\"]*)\"") end
76
77             return { { path = path; name = name; description = description; url = vlc.path; arturl = arturl } }
78         end
79     end
80 end