]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/azubu.py
debian/gbp.conf: Change to new git-buildpackage syntax.
[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 float_or_none
7
8
9 class AzubuIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?azubu\.tv/[^/]+#!/play/(?P<id>\d+)'
11 _TESTS = [
12 {
13 'url': 'http://www.azubu.tv/GSL#!/play/15575/2014-hot6-cup-last-big-match-ro8-day-1',
14 'md5': 'a88b42fcf844f29ad6035054bd9ecaf4',
15 'info_dict': {
16 'id': '15575',
17 'ext': 'mp4',
18 'title': '2014 HOT6 CUP LAST BIG MATCH Ro8 Day 1',
19 'description': 'md5:d06bdea27b8cc4388a90ad35b5c66c01',
20 'thumbnail': 're:^https?://.*\.jpe?g',
21 'timestamp': 1417523507.334,
22 'upload_date': '20141202',
23 'duration': 9988.7,
24 'uploader': 'GSL',
25 'uploader_id': 414310,
26 'view_count': int,
27 },
28 },
29 {
30 'url': 'http://www.azubu.tv/FnaticTV#!/play/9344/-fnatic-at-worlds-2014:-toyz---%22i-love-rekkles,-he-has-amazing-mechanics%22-',
31 'md5': 'b72a871fe1d9f70bd7673769cdb3b925',
32 'info_dict': {
33 'id': '9344',
34 'ext': 'mp4',
35 'title': 'Fnatic at Worlds 2014: Toyz - "I love Rekkles, he has amazing mechanics"',
36 'description': 'md5:4a649737b5f6c8b5c5be543e88dc62af',
37 'thumbnail': 're:^https?://.*\.jpe?g',
38 'timestamp': 1410530893.320,
39 'upload_date': '20140912',
40 'duration': 172.385,
41 'uploader': 'FnaticTV',
42 'uploader_id': 272749,
43 'view_count': int,
44 },
45 },
46 ]
47
48 def _real_extract(self, url):
49 video_id = self._match_id(url)
50
51 data = self._download_json(
52 'http://www.azubu.tv/api/video/%s' % video_id, video_id)['data']
53
54 title = data['title'].strip()
55 description = data['description']
56 thumbnail = data['thumbnail']
57 view_count = data['view_count']
58 uploader = data['user']['username']
59 uploader_id = data['user']['id']
60
61 stream_params = json.loads(data['stream_params'])
62
63 timestamp = float_or_none(stream_params['creationDate'], 1000)
64 duration = float_or_none(stream_params['length'], 1000)
65
66 renditions = stream_params.get('renditions') or []
67 video = stream_params.get('FLVFullLength') or stream_params.get('videoFullLength')
68 if video:
69 renditions.append(video)
70
71 formats = [{
72 'url': fmt['url'],
73 'width': fmt['frameWidth'],
74 'height': fmt['frameHeight'],
75 'vbr': float_or_none(fmt['encodingRate'], 1000),
76 'filesize': fmt['size'],
77 'vcodec': fmt['videoCodec'],
78 'container': fmt['videoContainer'],
79 } for fmt in renditions if fmt['url']]
80 self._sort_formats(formats)
81
82 return {
83 'id': video_id,
84 'title': title,
85 'description': description,
86 'thumbnail': thumbnail,
87 'timestamp': timestamp,
88 'duration': duration,
89 'uploader': uploader,
90 'uploader_id': uploader_id,
91 'view_count': view_count,
92 'formats': formats,
93 }