mux: mp4: fix recording of rtsp
[vlc.git] / share / lua / playlist / vimeo.lua
blobc6362660f464cd3f295a8b100b038165bd5b5d93
1 --[[
2 $Id$
4 Copyright © 2009-2013 the VideoLAN team
6 Authors: Konstantin Pavlov (thresh@videolan.org)
7 François Revol (revol@free.fr)
8 Pierre Ynard
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.
23 --]]
25 -- Probe function.
26 function probe()
27 local path = vlc.path
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
35 end
37 -- Parse function.
38 function parse()
39 if not string.match( vlc.path, "player%.vimeo%.com" ) then -- Web page URL
40 while true do
41 local line = vlc.readline()
42 if not line then break end
44 -- Get the appropriate ubiquitous meta tag
45 -- <meta name="twitter:player" content="https://player.vimeo.com/video/123456789">
46 local meta = string.match( line, "(<meta[^>]- name=\"twitter:player\"[^>]->)" )
47 if meta then
48 local path = string.match( meta, " content=\"(.-)\"" )
49 if path then
50 path = vlc.strings.resolve_xml_special_chars( path )
51 return { { path = path } }
52 end
53 end
54 end
56 vlc.msg.err( "Couldn't extract vimeo video URL, please check for updates to this script" )
57 return { }
59 else -- API URL
61 local prefres = vlc.var.inherit(nil, "preferred-resolution")
62 local bestres = nil
63 local line = vlc.readline() -- data is on one line only
65 for stream in string.gmatch( line, "{([^}]*\"profile\":[^}]*)}" ) do
66 local url = string.match( stream, "\"url\":\"(.-)\"" )
67 if url then
68 -- Apparently the different formats available are listed
69 -- in uncertain order of quality, so compare with what
70 -- we have so far.
71 local height = string.match( stream, "\"height\":(%d+)" )
72 height = tonumber( height )
74 -- Better than nothing
75 if not path or ( height and ( not bestres
76 -- Better quality within limits
77 or ( ( prefres < 0 or height <= prefres ) and height > bestres )
78 -- Lower quality more suited to limits
79 or ( prefres > -1 and bestres > prefres and height < bestres )
80 ) ) then
81 path = url
82 bestres = height
83 end
84 end
85 end
87 if not path then
88 vlc.msg.err( "Couldn't extract vimeo video URL, please check for updates to this script" )
89 return { }
90 end
92 local name = string.match( line, "\"title\":\"(.-)\"" )
93 local artist = string.match( line, "\"owner\":{[^}]-\"name\":\"(.-)\"" )
94 local arturl = string.match( line, "\"thumbs\":{\"[^\"]+\":\"(.-)\"" )
95 local duration = string.match( line, "\"duration\":(%d+)[,}]" )
97 return { { path = path; name = name; artist = artist; arturl = arturl; duration = duration } }
98 end
99 end