Lua: support HTTPS and live for Dailymotion
[vlc.git] / share / lua / playlist / dailymotion.lua
blobb985fea90498773e616334b079dca127abb406b8
1 --[[
2 Translate Daily Motion video webpages URLs to the corresponding
3 FLV URL.
5 $Id$
7 Copyright © 2007-2011 the VideoLAN team
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.
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.
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 --]]
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
33 return prefres
34 end
36 -- Probe function.
37 function probe()
38 if vlc.access ~= "http" and vlc.access ~= "https" then
39 return false
40 end
42 return ( string.match( vlc.path, "www.dailymotion.com/video" ) )
43 end
45 -- Parse function.
46 function parse()
47 prefres = get_prefres()
50 while true
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
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 )
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*\"([^\"]*)\"")
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
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("\\/", "/")
102 if prefres < 0 then
103 break
105 height = string.match( video_url_out, "/cdn/%w+%-%d+x(%d+)/video/" )
106 if not height or tonumber(height) <= prefres then
107 break
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 { }