]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/hitbox.py
3 from .common
import InfoExtractor
4 from ..compat
import compat_str
14 class HitboxIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:www\.)?(?:hitbox|smashcast)\.tv/(?:[^/]+/)*videos?/(?P<id>[0-9]+)'
18 'url': 'http://www.hitbox.tv/video/203213',
21 'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy',
22 'alt_title': 'hitboxlive - Aug 9th #6',
25 'thumbnail': r
're:^https?://.*\.jpg$',
27 'resolution': 'HD 720p',
28 'uploader': 'hitboxlive',
30 'timestamp': 1407576133,
31 'upload_date': '20140809',
32 'categories': ['Live Show'],
36 'skip_download': True,
39 'url': 'https://www.smashcast.tv/hitboxlive/videos/203213',
40 'only_matching': 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
, 'Downloading metadata JSON')
48 date
= 'media_live_since'
49 media_type
= 'livestream'
50 if metadata
.get('media_type') == 'video':
52 date
= 'media_date_added'
54 video_meta
= metadata
.get(media_type
, [])[0]
55 title
= video_meta
.get('media_status')
56 alt_title
= video_meta
.get('media_title')
57 description
= clean_html(
58 video_meta
.get('media_description')
59 or video_meta
.get('media_description_md'))
60 duration
= float_or_none(video_meta
.get('media_duration'))
61 uploader
= video_meta
.get('media_user_name')
62 views
= int_or_none(video_meta
.get('media_views'))
63 timestamp
= parse_iso8601(video_meta
.get(date
), ' ')
64 categories
= [video_meta
.get('category_name')]
66 '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.smashcast.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
,
122 metadata
= self
._extract
_metadata
(
123 'https://www.smashcast.tv/api/media/video', video_id
)
124 metadata
['formats'] = formats
129 class HitboxLiveIE(HitboxIE
): # XXX: Do not subclass from concrete IE
130 IE_NAME
= 'hitbox:live'
131 _VALID_URL
= r
'https?://(?:www\.)?(?:hitbox|smashcast)\.tv/(?P<id>[^/?#&]+)'
133 'url': 'http://www.hitbox.tv/dimak',
137 'description': 'md5:c9f80fa4410bc588d7faa40003fc7d0e',
139 'upload_date': compat_str
,
145 'skip_download': True,
148 'url': 'https://www.smashcast.tv/dimak',
149 'only_matching': True,
153 def suitable(cls
, url
):
154 return False if HitboxIE
.suitable(url
) else super(HitboxLiveIE
, cls
).suitable(url
)
156 def _real_extract(self
, url
):
157 video_id
= self
._match
_id
(url
)
159 player_config
= self
._download
_json
(
160 'https://www.smashcast.tv/api/player/config/live/%s' % video_id
,
164 cdns
= player_config
.get('cdns')
167 # Subscribe URLs are not playable
168 if cdn
.get('rtmpSubscribe') is True:
170 base_url
= cdn
.get('netConnectionUrl')
171 host
= re
.search(r
'.+\.([^\.]+\.[^\./]+)/.+', base_url
).group(1)
172 if base_url
not in servers
:
173 servers
.append(base_url
)
174 for stream
in cdn
.get('bitrates'):
175 label
= stream
.get('label')
178 stream_url
= stream
.get('url')
181 bitrate
= int_or_none(stream
.get('bitrate'))
182 if stream
.get('provider') == 'hls' or determine_ext(stream_url
) == 'm3u8':
183 if not stream_url
.startswith('http'):
189 'format_note': label
,
194 'url': '%s/%s' % (base_url
, stream_url
),
200 'player_url': 'http://www.hitbox.tv/static/player/flowplayer/flowplayer.commercial-3.2.16.swf',
203 metadata
= self
._extract
_metadata
(
204 'https://www.smashcast.tv/api/media/live', video_id
)
205 metadata
['formats'] = formats
206 metadata
['is_live'] = True
207 metadata
['title'] = metadata
.get('title')