]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/vzaar.py
[vidlii] Add extractor (closes #14472, closes #14512, closes #14779)
[youtube-dl.git] / youtube_dl / extractor / vzaar.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     int_or_none,
9     float_or_none,
10 )
11
12
13 class VzaarIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)'
15     _TESTS = [{
16         'url': 'https://vzaar.com/videos/1152805',
17         'md5': 'bde5ddfeb104a6c56a93a06b04901dbf',
18         'info_dict': {
19             'id': '1152805',
20             'ext': 'mp4',
21             'title': 'sample video (public)',
22         },
23     }, {
24         'url': 'https://view.vzaar.com/27272/player',
25         'md5': '3b50012ac9bbce7f445550d54e0508f2',
26         'info_dict': {
27             'id': '27272',
28             'ext': 'mp3',
29             'title': 'MP3',
30         },
31     }]
32
33     @staticmethod
34     def _extract_urls(webpage):
35         return re.findall(
36             r'<iframe[^>]+src=["\']((?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)',
37             webpage)
38
39     def _real_extract(self, url):
40         video_id = self._match_id(url)
41         video_data = self._download_json(
42             'http://view.vzaar.com/v2/%s/video' % video_id, video_id)
43         source_url = video_data['sourceUrl']
44
45         info = {
46             'id': video_id,
47             'title': video_data['videoTitle'],
48             'url': source_url,
49             'thumbnail': self._proto_relative_url(video_data.get('poster')),
50             'duration': float_or_none(video_data.get('videoDuration')),
51         }
52         if 'audio' in source_url:
53             info.update({
54                 'vcodec': 'none',
55                 'ext': 'mp3',
56             })
57         else:
58             info.update({
59                 'width': int_or_none(video_data.get('width')),
60                 'height': int_or_none(video_data.get('height')),
61                 'ext': 'mp4',
62             })
63         return info