6 from .common
import InfoExtractor
12 get_element_by_attribute
,
19 class VimeoIE(InfoExtractor
):
20 """Information extractor for vimeo.com."""
22 # _VALID_URL matches Vimeo URLs
23 _VALID_URL
= r
'(?P<proto>https?://)?(?:(?:www|(?P<player>player))\.)?vimeo(?P<pro>pro)?\.com/(?:.*?/)?(?P<direct_link>play_redirect_hls\?clip_id=)?(?:videos?/)?(?P<id>[0-9]+)/?(?:[?].*)?(?:#.*)?$'
24 _NETRC_MACHINE
= 'vimeo'
28 u
'url': u
'http://vimeo.com/56015672#at=0',
29 u
'file': u
'56015672.mp4',
30 u
'md5': u
'8879b6cc097e987f02484baf890129e5',
32 u
"upload_date": u
"20121220",
33 u
"description": u
"This is a test case for youtube-dl.\nFor more information, see github.com/rg3/youtube-dl\nTest chars: \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
34 u
"uploader_id": u
"user7108434",
35 u
"uploader": u
"Filippo Valsorda",
36 u
"title": u
"youtube-dl test video - \u2605 \" ' \u5e78 / \\ \u00e4 \u21ad \U0001d550",
40 u
'url': u
'http://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876',
41 u
'file': u
'68093876.mp4',
42 u
'md5': u
'3b5ca6aa22b60dfeeadf50b72e44ed82',
43 u
'note': u
'Vimeo Pro video (#1197)',
45 u
'uploader_id': u
'openstreetmapus',
46 u
'uploader': u
'OpenStreetMap US',
47 u
'title': u
'Andy Allan - Putting the Carto into OpenStreetMap Cartography',
51 u
'url': u
'http://player.vimeo.com/video/54469442',
52 u
'file': u
'54469442.mp4',
53 u
'md5': u
'619b811a4417aa4abe78dc653becf511',
54 u
'note': u
'Videos that embed the url in the player page',
56 u
'title': u
'Kathy Sierra: Building the minimum Badass User, Business of Software',
57 u
'uploader': u
'The BLN & Business of Software',
61 u
'url': u
'http://vimeo.com/68375962',
62 u
'file': u
'68375962.mp4',
63 u
'md5': u
'aaf896bdb7ddd6476df50007a0ac0ae7',
64 u
'note': u
'Video protected with password',
66 u
'title': u
'youtube-dl password protected test video',
67 u
'upload_date': u
'20130614',
68 u
'uploader_id': u
'user18948128',
69 u
'uploader': u
'Jaime Marquínez Ferrándiz',
72 u
'videopassword': u
'youtube-dl',
78 (username
, password
) = self
._get
_login
_info
()
82 login_url
= 'https://vimeo.com/log_in'
83 webpage
= self
._download
_webpage
(login_url
, None, False)
84 token
= re
.search(r
'xsrft: \'(.*?
)\'', webpage).group(1)
85 data = compat_urllib_parse.urlencode({'email
': username,
91 login_request = compat_urllib_request.Request(login_url, data)
92 login_request.add_header('Content
-Type
', 'application
/x
-www
-form
-urlencoded
')
93 login_request.add_header('Cookie
', 'xsrft
=%s' % token)
94 self._download_webpage(login_request, None, False, u'Wrong login info
')
96 def _verify_video_password(self, url, video_id, webpage):
97 password = self._downloader.params.get('videopassword
', None)
99 raise ExtractorError(u'This video
is protected by a password
, use the
--video
-password option
')
100 token = re.search(r'xsrft
: \'(.*?
)\'', webpage).group(1)
101 data = compat_urllib_parse.urlencode({'password
': password,
103 # I didn't manage to use the password
with https
104 if url
.startswith('https'):
105 pass_url
= url
.replace('https','http')
108 password_request
= compat_urllib_request
.Request(pass_url
+'/password', data
)
109 password_request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
110 password_request
.add_header('Cookie', 'xsrft=%s' % token
)
111 self
._download
_webpage
(password_request
, video_id
,
112 u
'Verifying the password',
115 def _real_initialize(self
):
118 def _real_extract(self
, url
):
119 url
, data
= unsmuggle_url(url
)
120 headers
= std_headers
122 headers
= headers
.copy()
125 # Extract ID from URL
126 mobj
= re
.match(self
._VALID
_URL
, url
)
128 raise ExtractorError(u
'Invalid URL: %s' % url
)
130 video_id
= mobj
.group('id')
131 if mobj
.group('pro') or mobj
.group('player'):
132 url
= 'http://player.vimeo.com/video/' + video_id
134 url
= 'https://vimeo.com/' + video_id
136 # Retrieve video webpage to extract further information
137 request
= compat_urllib_request
.Request(url
, None, headers
)
138 webpage
= self
._download
_webpage
(request
, video_id
)
140 # Now we begin extracting as much information as we can from what we
141 # retrieved. First we extract the information common to all extractors,
142 # and latter we extract those that are Vimeo specific.
143 self
.report_extraction(video_id
)
145 # Extract the config JSON
148 config_url
= self
._html
_search
_regex
(
149 r
' data-config-url="(.+?)"', webpage
, u
'config URL')
150 config_json
= self
._download
_webpage
(config_url
, video_id
)
151 config
= json
.loads(config_json
)
152 except RegexNotFoundError
:
153 # For pro videos or player.vimeo.com urls
154 # We try to find out to which variable is assigned the config dic
155 m_variable_name
= re
.search('(\w)\.video\.id', webpage
)
156 if m_variable_name
is not None:
157 config_re
= r
'%s=({.+?});' % re
.escape(m_variable_name
.group(1))
159 config_re
= [r
' = {config:({.+?}),assets:', r
'(?:[abc])=({.+?});']
160 config
= self
._search
_regex
(config_re
, webpage
, u
'info section',
162 config
= json
.loads(config
)
163 except Exception as e
:
164 if re
.search('The creator of this video has not given you permission to embed it on this domain.', webpage
):
165 raise ExtractorError(u
'The author has restricted the access to this video, try with the "--referer" option')
167 if re
.search('<form[^>]+?id="pw_form"', webpage
) is not None:
168 self
._verify
_video
_password
(url
, video_id
, webpage
)
169 return self
._real
_extract
(url
)
171 raise ExtractorError(u
'Unable to extract info section',
175 video_title
= config
["video"]["title"]
177 # Extract uploader and uploader_id
178 video_uploader
= config
["video"]["owner"]["name"]
179 video_uploader_id
= config
["video"]["owner"]["url"].split('/')[-1] if config
["video"]["owner"]["url"] else None
181 # Extract video thumbnail
182 video_thumbnail
= config
["video"].get("thumbnail")
183 if video_thumbnail
is None:
184 _
, video_thumbnail
= sorted((int(width
), t_url
) for (width
, t_url
) in config
["video"]["thumbs"].items())[-1]
186 # Extract video description
187 video_description
= None
189 video_description
= get_element_by_attribute("itemprop", "description", webpage
)
190 if video_description
: video_description
= clean_html(video_description
)
191 except AssertionError as err
:
192 # On some pages like (http://player.vimeo.com/video/54469442) the
193 # html tags are not closed, python 2.6 cannot handle it
194 if err
.args
[0] == 'we should not get here!':
199 # Extract upload date
200 video_upload_date
= None
201 mobj
= re
.search(r
'<meta itemprop="dateCreated" content="(\d{4})-(\d{2})-(\d{2})T', webpage
)
203 video_upload_date
= mobj
.group(1) + mobj
.group(2) + mobj
.group(3)
206 view_count
= int(self
._search
_regex
(r
'UserPlays:(\d+)', webpage
, u
'view count'))
207 like_count
= int(self
._search
_regex
(r
'UserLikes:(\d+)', webpage
, u
'like count'))
208 comment_count
= int(self
._search
_regex
(r
'UserComments:(\d+)', webpage
, u
'comment count'))
209 except RegexNotFoundError
:
210 # This info is only available in vimeo.com/{id} urls
215 # Vimeo specific: extract request signature and timestamp
216 sig
= config
['request']['signature']
217 timestamp
= config
['request']['timestamp']
219 # Vimeo specific: extract video codec and quality information
220 # First consider quality, then codecs, then take everything
221 codecs
= [('vp6', 'flv'), ('vp8', 'flv'), ('h264', 'mp4')]
222 files
= {'hd': [], 'sd': [], 'other': []}
223 config_files
= config
["video"].get("files") or config
["request"].get("files")
224 for codec_name
, codec_extension
in codecs
:
225 for quality
in config_files
.get(codec_name
, []):
226 format_id
= '-'.join((codec_name
, quality
)).lower()
227 key
= quality
if quality
in files
else 'other'
229 if isinstance(config_files
[codec_name
], dict):
230 file_info
= config_files
[codec_name
][quality
]
231 video_url
= file_info
.get('url')
234 if video_url
is None:
235 video_url
= "http://player.vimeo.com/play_redirect?clip_id=%s&sig=%s&time=%s&quality=%s&codecs=%s&type=moogaloop_local&embed_location=" \
236 %(video_id
, sig
, timestamp
, quality
, codec_name
.upper())
239 'ext': codec_extension
,
241 'format_id': format_id
,
242 'width': file_info
.get('width'),
243 'height': file_info
.get('height'),
246 for key
in ('other', 'sd', 'hd'):
247 formats
+= files
[key
]
248 if len(formats
) == 0:
249 raise ExtractorError(u
'No known codec found')
253 'uploader': video_uploader
,
254 'uploader_id': video_uploader_id
,
255 'upload_date': video_upload_date
,
256 'title': video_title
,
257 'thumbnail': video_thumbnail
,
258 'description': video_description
,
261 'view_count': view_count
,
262 'like_count': like_count
,
263 'comment_count': comment_count
,
267 class VimeoChannelIE(InfoExtractor
):
268 IE_NAME
= u
'vimeo:channel'
269 _VALID_URL
= r
'(?:https?://)?vimeo.\com/channels/(?P<id>[^/]+)'
270 _MORE_PAGES_INDICATOR
= r
'<a.+?rel="next"'
271 _TITLE_RE
= r
'<link rel="alternate"[^>]+?title="(.*?)"'
273 def _page_url(self
, base_url
, pagenum
):
274 return '%s/videos/page:%d/' % (base_url
, pagenum
)
276 def _extract_list_title(self
, webpage
):
277 return self
._html
_search
_regex
(self
._TITLE
_RE
, webpage
, u
'list title')
279 def _extract_videos(self
, list_id
, base_url
):
281 for pagenum
in itertools
.count(1):
282 webpage
= self
._download
_webpage
(
283 self
._page
_url
(base_url
, pagenum
) ,list_id
,
284 u
'Downloading page %s' % pagenum
)
285 video_ids
.extend(re
.findall(r
'id="clip_(\d+?)"', webpage
))
286 if re
.search(self
._MORE
_PAGES
_INDICATOR
, webpage
, re
.DOTALL
) is None:
289 entries
= [self
.url_result('http://vimeo.com/%s' % video_id
, 'Vimeo')
290 for video_id
in video_ids
]
291 return {'_type': 'playlist',
293 'title': self
._extract
_list
_title
(webpage
),
297 def _real_extract(self
, url
):
298 mobj
= re
.match(self
._VALID
_URL
, url
)
299 channel_id
= mobj
.group('id')
300 return self
._extract
_videos
(channel_id
, 'http://vimeo.com/channels/%s' % channel_id
)
303 class VimeoUserIE(VimeoChannelIE
):
304 IE_NAME
= u
'vimeo:user'
305 _VALID_URL
= r
'(?:https?://)?vimeo.\com/(?P<name>[^/]+)'
306 _TITLE_RE
= r
'<a[^>]+?class="user">([^<>]+?)</a>'
309 def suitable(cls
, url
):
310 if VimeoChannelIE
.suitable(url
) or VimeoIE
.suitable(url
) or VimeoAlbumIE
.suitable(url
) or VimeoGroupsIE
.suitable(url
):
312 return super(VimeoUserIE
, cls
).suitable(url
)
314 def _real_extract(self
, url
):
315 mobj
= re
.match(self
._VALID
_URL
, url
)
316 name
= mobj
.group('name')
317 return self
._extract
_videos
(name
, 'http://vimeo.com/%s' % name
)
320 class VimeoAlbumIE(VimeoChannelIE
):
321 IE_NAME
= u
'vimeo:album'
322 _VALID_URL
= r
'(?:https?://)?vimeo.\com/album/(?P<id>\d+)'
323 _TITLE_RE
= r
'<header id="page_header">\n\s*<h1>(.*?)</h1>'
325 def _page_url(self
, base_url
, pagenum
):
326 return '%s/page:%d/' % (base_url
, pagenum
)
328 def _real_extract(self
, url
):
329 mobj
= re
.match(self
._VALID
_URL
, url
)
330 album_id
= mobj
.group('id')
331 return self
._extract
_videos
(album_id
, 'http://vimeo.com/album/%s' % album_id
)
334 class VimeoGroupsIE(VimeoAlbumIE
):
335 IE_NAME
= u
'vimeo:group'
336 _VALID_URL
= r
'(?:https?://)?vimeo.\com/groups/(?P<name>[^/]+)'
338 def _extract_list_title(self
, webpage
):
339 return self
._og
_search
_title
(webpage
)
341 def _real_extract(self
, url
):
342 mobj
= re
.match(self
._VALID
_URL
, url
)
343 name
= mobj
.group('name')
344 return self
._extract
_videos
(name
, 'http://vimeo.com/groups/%s' % name
)