qml: history.push changes view by default
[vlc.git] / share / lua / playlist / dailymotion.lua
blobc9f58ec0d0a028f746fd698a4feee044a9df95c3
1 --[[
2 Translate Dailymotion video webpages URLs to corresponding
3 video stream URLs.
5 Copyright © 2007-2019 the VideoLAN team
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 --]]
22 -- Probe function.
23 function probe()
24 return ( vlc.access == "http" or vlc.access == "https" )
25 and string.match( vlc.path, "^www%.dailymotion%.com/video/" )
26 end
28 -- Parse function.
29 function parse()
30 while true
32 line = vlc.readline()
33 if not line then break end
34 if string.match( line, "<meta property=\"og:title\"" ) then
35 _,_,name = string.find( line, "content=\"(.-)\"" )
36 name = vlc.strings.resolve_xml_special_chars( name )
37 name = string.gsub( name, " %- Vidéo dailymotion$", "" )
38 end
39 if string.match( line, "<meta name=\"description\"" ) then
40 _,_,description = string.find( line, "content=\"(.-)\"" )
41 if (description ~= nil) then
42 description = vlc.strings.resolve_xml_special_chars( description )
43 end
44 end
45 if string.match( line, "<meta property=\"og:image\"" ) then
46 arturl = string.match( line, "content=\"(.-)\"" )
47 end
48 end
50 local video_id = string.match( vlc.path, "^www%.dailymotion%.com/video/([^/?#]+)" )
51 if video_id then
52 local metadata = vlc.stream( vlc.access.."://www.dailymotion.com/player/metadata/video/"..video_id )
53 if metadata then
54 local line = metadata:readline() -- data is on one line only
56 -- TODO: fetch "title" and resolve \u escape sequences
57 -- FIXME: use "screenname" instead and resolve \u escape sequences
58 artist = string.match( line, '"username":"([^"]+)"' )
60 local poster = string.match( line, '"poster_url":"([^"]+)"' )
61 if poster then
62 arturl = string.gsub( poster, "\\/", "/")
63 end
65 local streams = string.match( line, "\"qualities\":{(.-%])}" )
66 if streams then
67 local prefres = vlc.var.inherit(nil, "preferred-resolution")
68 local file = nil
69 local live = nil
70 for height,stream in string.gmatch( streams, "\"(%w+)\":%[(.-)%]" ) do
71 -- Apparently formats are listed in increasing quality
72 -- order, so we take the first, lowest quality as
73 -- fallback, then pick the last one that matches.
74 if string.match( height, "^(%d+)$" ) and ( ( not file ) or prefres < 0 or tonumber( height ) <= prefres ) then
75 local f = string.match( stream, '"type":"video\\/[^"]+","url":"([^"]+)"' )
76 if f then
77 file = f
78 end
79 end
80 if not live then
81 live = string.match( stream, '"type":"application\\/x%-mpegURL","url":"([^"]+)"' )
82 end
83 end
85 -- Pick live streaming only as a fallback
86 path = file or live
87 if path then
88 path = string.gsub( path, "\\/", "/")
89 end
90 end
91 end
92 end
94 if not path then
95 vlc.msg.err("Couldn't extract dailymotion video URL, please check for updates to this script")
96 return { }
97 end
99 return { { path = path; name = name; description = description; arturl = arturl; artist = artist } }