]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vzaar.py
b270f08d1e8796889ac54e4885c2234e4e7eb46b
[youtubedl] / youtube_dl / extractor / vzaar.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 float_or_none,
8 )
9
10
11 class VzaarIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)'
13 _TESTS = [{
14 'url': 'https://vzaar.com/videos/1152805',
15 'md5': 'bde5ddfeb104a6c56a93a06b04901dbf',
16 'info_dict': {
17 'id': '1152805',
18 'ext': 'mp4',
19 'title': 'sample video (public)',
20 },
21 }, {
22 'url': 'https://view.vzaar.com/27272/player',
23 'md5': '3b50012ac9bbce7f445550d54e0508f2',
24 'info_dict': {
25 'id': '27272',
26 'ext': 'mp3',
27 'title': 'MP3',
28 },
29 }]
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 video_data = self._download_json(
34 'http://view.vzaar.com/v2/%s/video' % video_id, video_id)
35 source_url = video_data['sourceUrl']
36
37 info = {
38 'id': video_id,
39 'title': video_data['videoTitle'],
40 'url': source_url,
41 'thumbnail': self._proto_relative_url(video_data.get('poster')),
42 'duration': float_or_none(video_data.get('videoDuration')),
43 }
44 if 'audio' in source_url:
45 info.update({
46 'vcodec': 'none',
47 'ext': 'mp3',
48 })
49 else:
50 info.update({
51 'width': int_or_none(video_data.get('width')),
52 'height': int_or_none(video_data.get('height')),
53 'ext': 'mp4',
54 })
55 return info