2 Translate Dailymotion video webpages URLs to corresponding
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.
24 return ( vlc
.access
== "http" or vlc
.access
== "https" )
25 and string.match( vlc
.path
, "^www%.dailymotion%.com/video/" )
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$", "" )
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
)
45 if string.match( line
, "<meta property=\"og:image\"" ) then
46 arturl
= string.match( line
, "content=\"(.-)\"" )
50 local video_id
= string.match( vlc
.path
, "^www%.dailymotion%.com/video/([^/?#]+)" )
52 local metadata
= vlc
.stream( vlc
.access
.."://www.dailymotion.com/player/metadata/video/"..video_id
)
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":"([^"]+)"' )
62 arturl
= string.gsub( poster
, "\\/", "/")
65 local streams
= string.match( line
, "\"qualities\":{(.-%])}" )
67 local prefres
= vlc
.var
.inherit(nil, "preferred-resolution")
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":"([^"]+)"' )
81 live
= string.match( stream
, '"type":"application\\/x%-mpegURL","url":"([^"]+)"' )
85 -- Pick live streaming only as a fallback
88 path
= string.gsub( path
, "\\/", "/")
95 vlc
.msg
.err("Couldn't extract dailymotion video URL, please check for updates to this script")
99 return { { path
= path
; name
= name
; description
= description
; arturl
= arturl
; artist
= artist
} }