4 Copyright © 2009-2013 the VideoLAN team
6 Authors: Konstantin Pavlov (thresh@videolan.org)
7 François Revol (revol@free.fr)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
28 path = path:gsub("^www%.", "")
29 return ( vlc.access == "http" or vlc.access == "https" )
30 and ( string.match( path, "^vimeo%.com/%d+$" )
31 or string.match( path, "^vimeo%.com/channels/(.-)/%d+$" )
32 or string.match( path, "^player%.vimeo%.com" ) )
33 -- do not match other addresses,
34 -- else we'll also try to decode the actual video url
39 if not string.match( vlc.path, "player%.vimeo%.com" ) then -- Web page URL
41 local line = vlc.readline()
42 if not line then break end
44 -- Get the appropriate ubiquitous meta tag. It appears twice:
45 -- <meta property="og:video:url" content="https://player.vimeo.com/video/123456789?autoplay=1">
46 -- <meta property="og:video:url" content="https://vimeo.com/moogaloop.swf?clip_id=123456789&autoplay=1">
47 local meta = string.match( line, "(<meta[^>]- property=\"og:video:url\"[^>]->)" )
49 local path = string.match( meta, " content=\"(.-)\"" )
50 -- Exclude moogaloop flash URL
51 if path and string.match( path, "player%.vimeo%.com" ) then
52 path = vlc.strings.resolve_xml_special_chars( path )
53 return { { path = path } }
58 vlc.msg.err( "Couldn't extract vimeo video URL, please check for updates to this script" )
63 local prefres = vlc.var.inherit(nil, "preferred-resolution")
65 local line = vlc.readline() -- data is on one line only
67 for stream in string.gmatch( line, "{([^}]*\"profile\":[^}]*)}" ) do
68 local url = string.match( stream, "\"url\":\"(.-)\"" )
70 -- Apparently the different formats available are listed
71 -- in uncertain order of quality, so compare with what
73 local height = string.match( stream, "\"height\":(%d+)" )
74 height = tonumber( height )
76 -- Better than nothing
77 if not path or ( height and ( not bestres
78 -- Better quality within limits
79 or ( ( prefres < 0 or height <= prefres ) and height > bestres )
80 -- Lower quality more suited to limits
81 or ( prefres > -1 and bestres > prefres and height < bestres )
90 vlc.msg.err( "Couldn't extract vimeo video URL, please check for updates to this script" )
94 local name = string.match( line, "\"title\":\"(.-)\"" )
95 local artist = string.match( line, "\"owner\":{[^}]-\"name\":\"(.-)\"" )
96 local arturl = string.match( line, "\"thumbs\":{\"[^\"]+\":\"(.-)\"" )
97 local duration = string.match( line, "\"duration\":(%d+)[,}]" )
99 return { { path = path; name = name; artist = artist; arturl = arturl; duration = duration } }