]> git.sesse.net Git - vlc/blob - share/lua/playlist/dailymotion.lua
bpg: add libbpg decoder
[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-2011 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 function get_prefres()
25     local prefres = -1
26     if vlc.var and vlc.var.inherit then
27         prefres = vlc.var.inherit(nil, "preferred-resolution")
28         if prefres == nil then
29             prefres = -1
30         end
31     end
32
33     return prefres
34 end
35
36 -- Probe function.
37 function probe()
38         if vlc.access ~= "http" and vlc.access ~= "https" then
39         return false
40     end
41
42     return ( string.match( vlc.path, "www.dailymotion.com/video" ) )
43 end
44
45 -- Parse function.
46 function parse()
47         prefres = get_prefres()
48
49
50         while true
51     do
52         line = vlc.readline()
53         if not line then break end
54                 if string.match( line, "<meta property=\"og:title\"" ) then
55                         _,_,name = string.find( line, "content=\"(.-)\"" )
56                         name = vlc.strings.resolve_xml_special_chars( name )
57                 end
58                 if string.match( line, "<meta name=\"description\"" ) then
59                         _,_,description = string.find( line, "content=\"(.-)\"" )
60             if (description ~= nil) then
61                 description = vlc.strings.resolve_xml_special_chars( description )
62             end
63                 end
64                 if string.match( line, "<meta name=\"author\"" ) then
65                         _,_,artist = string.find( line, "content=\"(.-)\"" )
66                         artist = vlc.strings.resolve_xml_special_chars( artist )
67                 end
68                 if string.match( line, "<link rel=\"thumbnail\" type=\"image/jpeg\"" ) then
69                         _,_,arturl = string.find( line, "href=\"(.-)\"" )
70                 end
71     end
72
73         page_embed = string.gsub(vlc.path, "dailymotion.com/video/", "dailymotion.com/embed/video/")
74         page_url = vlc.stream(vlc.access .. "://" .. page_embed )
75         if not page_url then return nil end
76     page = page_url:read( 65653 )
77
78
79         hd1080url = string.match( page, "\"stream_h264_hd1080_url\"%s*:%s*\"([^\"]*)\"")
80         hdurl = string.match( page, "\"stream_h264_hd_url\"%s*:%s*\"([^\"]*)\"")
81         hqurl = string.match( page, "\"stream_h264_hq_url\"%s*:%s*\"([^\"]*)\"")
82         baseurl = string.match( page, "\"stream_h264_url\"%s*:%s*\"([^\"]*)\"")
83         ldurl = string.match( page, "\"stream_h264_ld_url\"%s*:%s*\"([^\"]*)\"")
84         livehlsurl = string.match( page, "\"stream_live_hls_url\"%s*:%s*\"([^\"]*)\"")
85
86
87         arr_videos_urls = {}
88         if hd1080url then       table.insert(arr_videos_urls,hd1080url) end
89         if hdurl then table.insert(arr_videos_urls,hdurl) end
90         if hqurl then   table.insert(arr_videos_urls,hqurl)     end
91         if baseurl then table.insert(arr_videos_urls,baseurl) end
92         if ldurl then table.insert(arr_videos_urls,baseurl) end
93
94
95         if livehlsurl then
96                 return { { path = livehlsurl:gsub("\\/", "/"); name = name; description = description; url = vlc.path; arturl = arturl ; artist = artist} }
97         else
98                 if table.getn(arr_videos_urls) > 0 then
99                         for i=1 , table.getn(arr_videos_urls)  do
100                                 video_url_out = arr_videos_urls[i]:gsub("\\/", "/")
101
102                                 if prefres < 0 then
103                                         break
104                                 end
105                                 height = string.match( video_url_out, "/cdn/%w+%-%d+x(%d+)/video/" )
106                                 if not height or tonumber(height) <= prefres then
107                                         break
108                                 end
109                         end
110                         return { { path = video_url_out; name = name; description = description; url = vlc.path; arturl = arturl; artist = artist} }
111                 else
112                         vlc.msg.err("Couldn't extract the video URL from dailymotion")
113                         return { }
114                 end
115         end
116 end