]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vzaar.py
Initiate new release.
[youtubedl] / 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 ..compat import compat_str
8 from ..utils import (
9 int_or_none,
10 float_or_none,
11 unified_timestamp,
12 url_or_none,
13 )
14
15
16 class VzaarIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:(?:www|view)\.)?vzaar\.com/(?:videos/)?(?P<id>\d+)'
18 _TESTS = [{
19 # HTTP and HLS
20 'url': 'https://vzaar.com/videos/1152805',
21 'md5': 'bde5ddfeb104a6c56a93a06b04901dbf',
22 'info_dict': {
23 'id': '1152805',
24 'ext': 'mp4',
25 'title': 'sample video (public)',
26 },
27 }, {
28 'url': 'https://view.vzaar.com/27272/player',
29 'md5': '3b50012ac9bbce7f445550d54e0508f2',
30 'info_dict': {
31 'id': '27272',
32 'ext': 'mp3',
33 'title': 'MP3',
34 },
35 }, {
36 # with null videoTitle
37 'url': 'https://view.vzaar.com/20313539/download',
38 'only_matching': True,
39 }]
40
41 @staticmethod
42 def _extract_urls(webpage):
43 return re.findall(
44 r'<iframe[^>]+src=["\']((?:https?:)?//(?:view\.vzaar\.com)/[0-9]+)',
45 webpage)
46
47 def _real_extract(self, url):
48 video_id = self._match_id(url)
49 video_data = self._download_json(
50 'http://view.vzaar.com/v2/%s/video' % video_id, video_id)
51
52 title = video_data.get('videoTitle') or video_id
53
54 formats = []
55
56 source_url = url_or_none(video_data.get('sourceUrl'))
57 if source_url:
58 f = {
59 'url': source_url,
60 'format_id': 'http',
61 }
62 if 'audio' in source_url:
63 f.update({
64 'vcodec': 'none',
65 'ext': 'mp3',
66 })
67 else:
68 f.update({
69 'width': int_or_none(video_data.get('width')),
70 'height': int_or_none(video_data.get('height')),
71 'ext': 'mp4',
72 'fps': float_or_none(video_data.get('fps')),
73 })
74 formats.append(f)
75
76 video_guid = video_data.get('guid')
77 usp = video_data.get('usp')
78 if isinstance(video_guid, compat_str) and isinstance(usp, dict):
79 m3u8_url = ('http://fable.vzaar.com/v4/usp/%s/%s.ism/.m3u8?'
80 % (video_guid, video_id)) + '&'.join(
81 '%s=%s' % (k, v) for k, v in usp.items())
82 formats.extend(self._extract_m3u8_formats(
83 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
84 m3u8_id='hls', fatal=False))
85
86 self._sort_formats(formats)
87
88 return {
89 'id': video_id,
90 'title': title,
91 'thumbnail': self._proto_relative_url(video_data.get('poster')),
92 'duration': float_or_none(video_data.get('videoDuration')),
93 'timestamp': unified_timestamp(video_data.get('ts')),
94 'formats': formats,
95 }