]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hitbox.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
17 class HitboxIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:www\.)?hitbox\.tv/video/(?P<id>[0-9]+)'
21 'url': 'http://www.hitbox.tv/video/203213',
24 'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy',
25 'alt_title': 'hitboxlive - Aug 9th #6',
28 'thumbnail': r
're:^https?://.*\.jpg$',
30 'resolution': 'HD 720p',
31 'uploader': 'hitboxlive',
33 'timestamp': 1407576133,
34 'upload_date': '20140809',
35 'categories': ['Live Show'],
39 'skip_download': True,
43 def _extract_metadata(self
, url
, video_id
):
44 thumb_base
= 'https://edge.sf.hitbox.tv'
45 metadata
= self
._download
_json
(
46 '%s/%s' % (url
, video_id
), video_id
,
47 'Downloading metadata JSON')
49 date
= 'media_live_since'
50 media_type
= 'livestream'
51 if metadata
.get('media_type') == 'video':
53 date
= 'media_date_added'
55 video_meta
= metadata
.get(media_type
, [])[0]
56 title
= video_meta
.get('media_status')
57 alt_title
= video_meta
.get('media_title')
58 description
= clean_html(
59 video_meta
.get('media_description') or
60 video_meta
.get('media_description_md'))
61 duration
= float_or_none(video_meta
.get('media_duration'))
62 uploader
= video_meta
.get('media_user_name')
63 views
= int_or_none(video_meta
.get('media_views'))
64 timestamp
= parse_iso8601(video_meta
.get(date
), ' ')
65 categories
= [video_meta
.get('category_name')]
67 {'url': thumb_base
+ video_meta
.get('media_thumbnail'),
70 {'url': thumb_base
+ video_meta
.get('media_thumbnail_large'),
78 'alt_title': alt_title
,
79 'description': description
,
85 'timestamp': timestamp
,
86 'categories': categories
,
89 def _real_extract(self
, url
):
90 video_id
= self
._match
_id
(url
)
92 player_config
= self
._download
_json
(
93 'https://www.hitbox.tv/api/player/config/video/%s' % video_id
,
94 video_id
, 'Downloading video JSON')
97 for video
in player_config
['clip']['bitrates']:
98 label
= video
.get('label')
101 video_url
= video
.get('url')
104 bitrate
= int_or_none(video
.get('bitrate'))
105 if determine_ext(video_url
) == 'm3u8':
106 if not video_url
.startswith('http'):
112 'format_note': label
,
113 'protocol': 'm3u8_native',
119 'format_note': label
,
121 self
._sort
_formats
(formats
)
123 metadata
= self
._extract
_metadata
(
124 'https://www.hitbox.tv/api/media/video',
126 metadata
['formats'] = formats
131 class HitboxLiveIE(HitboxIE
):
132 IE_NAME
= 'hitbox:live'
133 _VALID_URL
= r
'https?://(?:www\.)?hitbox\.tv/(?!video)(?P<id>.+)'
135 'url': 'http://www.hitbox.tv/dimak',
139 'description': 'md5:c9f80fa4410bc588d7faa40003fc7d0e',
141 'upload_date': compat_str
,
147 'skip_download': True,
151 def _real_extract(self
, url
):
152 video_id
= self
._match
_id
(url
)
154 player_config
= self
._download
_json
(
155 'https://www.hitbox.tv/api/player/config/live/%s' % video_id
,
159 cdns
= player_config
.get('cdns')
162 # Subscribe URLs are not playable
163 if cdn
.get('rtmpSubscribe') is True:
165 base_url
= cdn
.get('netConnectionUrl')
166 host
= re
.search(r
'.+\.([^\.]+\.[^\./]+)/.+', base_url
).group(1)
167 if base_url
not in servers
:
168 servers
.append(base_url
)
169 for stream
in cdn
.get('bitrates'):
170 label
= stream
.get('label')
173 stream_url
= stream
.get('url')
176 bitrate
= int_or_none(stream
.get('bitrate'))
177 if stream
.get('provider') == 'hls' or determine_ext(stream_url
) == 'm3u8':
178 if not stream_url
.startswith('http'):
184 'format_note': label
,
189 'url': '%s/%s' % (base_url
, stream_url
),
195 'player_url': 'http://www.hitbox.tv/static/player/flowplayer/flowplayer.commercial-3.2.16.swf',
197 self
._sort
_formats
(formats
)
199 metadata
= self
._extract
_metadata
(
200 'https://www.hitbox.tv/api/media/live',
202 metadata
['formats'] = formats
203 metadata
['is_live'] = True
204 metadata
['title'] = self
._live
_title
(metadata
.get('title'))