]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/azubu.py
011edf128c2a688bc4ef56e487872ff1b15cee66
[youtubedl] / youtube_dl / extractor / azubu.py
1 from __future__ import unicode_literals
2
3 import json
4
5 from .common import InfoExtractor
6 from ..utils import (
7 ExtractorError,
8 float_or_none,
9 sanitized_Request,
10 )
11
12
13 class AzubuIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?azubu\.tv/[^/]+#!/play/(?P<id>\d+)'
15 _TESTS = [
16 {
17 'url': 'http://www.azubu.tv/GSL#!/play/15575/2014-hot6-cup-last-big-match-ro8-day-1',
18 'md5': 'a88b42fcf844f29ad6035054bd9ecaf4',
19 'info_dict': {
20 'id': '15575',
21 'ext': 'mp4',
22 'title': '2014 HOT6 CUP LAST BIG MATCH Ro8 Day 1',
23 'description': 'md5:d06bdea27b8cc4388a90ad35b5c66c01',
24 'thumbnail': 're:^https?://.*\.jpe?g',
25 'timestamp': 1417523507.334,
26 'upload_date': '20141202',
27 'duration': 9988.7,
28 'uploader': 'GSL',
29 'uploader_id': 414310,
30 'view_count': int,
31 },
32 },
33 {
34 'url': 'http://www.azubu.tv/FnaticTV#!/play/9344/-fnatic-at-worlds-2014:-toyz---%22i-love-rekkles,-he-has-amazing-mechanics%22-',
35 'md5': 'b72a871fe1d9f70bd7673769cdb3b925',
36 'info_dict': {
37 'id': '9344',
38 'ext': 'mp4',
39 'title': 'Fnatic at Worlds 2014: Toyz - "I love Rekkles, he has amazing mechanics"',
40 'description': 'md5:4a649737b5f6c8b5c5be543e88dc62af',
41 'thumbnail': 're:^https?://.*\.jpe?g',
42 'timestamp': 1410530893.320,
43 'upload_date': '20140912',
44 'duration': 172.385,
45 'uploader': 'FnaticTV',
46 'uploader_id': 272749,
47 'view_count': int,
48 },
49 },
50 ]
51
52 def _real_extract(self, url):
53 video_id = self._match_id(url)
54
55 data = self._download_json(
56 'http://www.azubu.tv/api/video/%s' % video_id, video_id)['data']
57
58 title = data['title'].strip()
59 description = data['description']
60 thumbnail = data['thumbnail']
61 view_count = data['view_count']
62 uploader = data['user']['username']
63 uploader_id = data['user']['id']
64
65 stream_params = json.loads(data['stream_params'])
66
67 timestamp = float_or_none(stream_params['creationDate'], 1000)
68 duration = float_or_none(stream_params['length'], 1000)
69
70 renditions = stream_params.get('renditions') or []
71 video = stream_params.get('FLVFullLength') or stream_params.get('videoFullLength')
72 if video:
73 renditions.append(video)
74
75 formats = [{
76 'url': fmt['url'],
77 'width': fmt['frameWidth'],
78 'height': fmt['frameHeight'],
79 'vbr': float_or_none(fmt['encodingRate'], 1000),
80 'filesize': fmt['size'],
81 'vcodec': fmt['videoCodec'],
82 'container': fmt['videoContainer'],
83 } for fmt in renditions if fmt['url']]
84 self._sort_formats(formats)
85
86 return {
87 'id': video_id,
88 'title': title,
89 'description': description,
90 'thumbnail': thumbnail,
91 'timestamp': timestamp,
92 'duration': duration,
93 'uploader': uploader,
94 'uploader_id': uploader_id,
95 'view_count': view_count,
96 'formats': formats,
97 }
98
99
100 class AzubuLiveIE(InfoExtractor):
101 _VALID_URL = r'http://www.azubu.tv/(?P<id>[^/]+)$'
102
103 _TEST = {
104 'url': 'http://www.azubu.tv/MarsTVMDLen',
105 'only_matching': True,
106 }
107
108 def _real_extract(self, url):
109 user = self._match_id(url)
110
111 info = self._download_json(
112 'http://api.azubu.tv/public/modules/last-video/{0}/info'.format(user),
113 user)['data']
114 if info['type'] != 'STREAM':
115 raise ExtractorError('{0} is not streaming live'.format(user), expected=True)
116
117 req = sanitized_Request(
118 'https://edge-elb.api.brightcove.com/playback/v1/accounts/3361910549001/videos/ref:' + info['reference_id'])
119 req.add_header('Accept', 'application/json;pk=BCpkADawqM1gvI0oGWg8dxQHlgT8HkdE2LnAlWAZkOlznO39bSZX726u4JqnDsK3MDXcO01JxXK2tZtJbgQChxgaFzEVdHRjaDoxaOu8hHOO8NYhwdxw9BzvgkvLUlpbDNUuDoc4E4wxDToV')
120 bc_info = self._download_json(req, user)
121 m3u8_url = next(source['src'] for source in bc_info['sources'] if source['container'] == 'M2TS')
122 formats = self._extract_m3u8_formats(m3u8_url, user, ext='mp4')
123
124 return {
125 'id': info['id'],
126 'title': self._live_title(info['title']),
127 'uploader_id': user,
128 'formats': formats,
129 'is_live': True,
130 'thumbnail': bc_info['poster'],
131 }