[hitbox] add extractor for hitbox vods
[youtube-dl] / youtube_dl / extractor / hitbox.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     unified_strdate,
7 )
8
9
10 class HitboxIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?hitbox\.tv/video/(?P<id>[0-9]+)'
12     _TESTS = [{
13         'url': 'http://www.hitbox.tv/video/358062',
14         'info_dict': {
15             'id': '358062',
16             'title': 'Megaman',
17             'alt_title': 'Megaman',
18             'description': '',
19             'ext': 'mp4',
20             'thumbnail': 're:^https?://.*\.jpg$',
21             'duration': 3834,
22             'resolution': 'SD 480p',
23             'uploader_id': 'supergreatfriend',
24             'view_count': int,
25             'upload_date': '20141225',
26             'categories': [None],
27         },
28         'params': {
29             # m3u8 download
30             'skip_download': True,
31         },
32     }, {
33         'url': 'http://www.hitbox.tv/video/203213',
34         'info_dict': {
35             'id': '203213',
36             'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy',
37             'alt_title': 'hitboxlive - Aug 9th #6',
38             'description': '',
39             'ext': 'mp4',
40             'thumbnail': 're:^https?://.*\.jpg$',
41             'duration': 215,
42             'resolution': 'HD 720p',
43             'uploader_id': 'hitboxlive',
44             'view_count': int,
45             'upload_date': '20140809',
46             'categories': ['Live Show'],
47         },
48         'params': {
49             # m3u8 download
50             'skip_download': True,
51         },
52     }]
53
54     def _real_extract(self, url):
55         video_id = self._match_id(url)
56
57         thumb_base = 'https://edge.sf.hitbox.tv'
58         metadata = self._download_json(
59             'https://www.hitbox.tv/api/media/video/%s' % (video_id), video_id
60         )
61
62         video_meta = metadata.get('video', [])[0]
63         title = video_meta.get('media_status')
64         alt_title = video_meta.get('media_title')
65         description = video_meta.get('media_description')
66         duration = int(float(video_meta.get('media_duration')))
67         uploader = video_meta.get('media_user_name')
68         views = int(video_meta.get('media_views'))
69         upload_date = unified_strdate(video_meta.get('media_date_added'))
70         categories = [video_meta.get('category_name')]
71         thumbs = [
72             {'url': thumb_base + video_meta.get('media_thumbnail'),
73              'width': 320,
74              'height': 180},
75             {'url': thumb_base + video_meta.get('media_thumbnail_large'),
76              'width': 768,
77              'height': 432},
78         ]
79
80         player_config = self._download_json(
81             'https://www.hitbox.tv/api/player/config/video/%s' % (video_id),
82             video_id
83         )
84
85         clip = player_config.get('clip')
86         video_url = clip.get('url')
87         res = clip.get('bitrates', [])[0].get('label')
88
89         return {
90             'id': video_id,
91             'title': title,
92             'alt_title': alt_title,
93             'description': description,
94             'url': video_url,
95             'ext': 'mp4',
96             'thumbnails': thumbs,
97             'duration': duration,
98             'resolution': res,
99             'uploader_id': uploader,
100             'view_count': views,
101             'upload_date': upload_date,
102             'categories': categories,
103             'protocol': 'm3u8',
104         }