]>
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|smashcast)\.tv/(?:[^/]+/)*videos?/(?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,
42 'url': 'https://www.smashcast.tv/hitboxlive/videos/203213',
43 'only_matching': True,
46 def _extract_metadata(self
, url
, video_id
):
47 thumb_base
= 'https://edge.sf.hitbox.tv'
48 metadata
= self
._download
_json
(
49 '%s/%s' % (url
, video_id
), video_id
, 'Downloading metadata JSON')
51 date
= 'media_live_since'
52 media_type
= 'livestream'
53 if metadata
.get('media_type') == 'video':
55 date
= 'media_date_added'
57 video_meta
= metadata
.get(media_type
, [])[0]
58 title
= video_meta
.get('media_status')
59 alt_title
= video_meta
.get('media_title')
60 description
= clean_html(
61 video_meta
.get('media_description') or
62 video_meta
.get('media_description_md'))
63 duration
= float_or_none(video_meta
.get('media_duration'))
64 uploader
= video_meta
.get('media_user_name')
65 views
= int_or_none(video_meta
.get('media_views'))
66 timestamp
= parse_iso8601(video_meta
.get(date
), ' ')
67 categories
= [video_meta
.get('category_name')]
69 'url': thumb_base
+ video_meta
.get('media_thumbnail'),
73 'url': thumb_base
+ video_meta
.get('media_thumbnail_large'),
81 'alt_title': alt_title
,
82 'description': description
,
88 'timestamp': timestamp
,
89 'categories': categories
,
92 def _real_extract(self
, url
):
93 video_id
= self
._match
_id
(url
)
95 player_config
= self
._download
_json
(
96 'https://www.smashcast.tv/api/player/config/video/%s' % video_id
,
97 video_id
, 'Downloading video JSON')
100 for video
in player_config
['clip']['bitrates']:
101 label
= video
.get('label')
104 video_url
= video
.get('url')
107 bitrate
= int_or_none(video
.get('bitrate'))
108 if determine_ext(video_url
) == 'm3u8':
109 if not video_url
.startswith('http'):
115 'format_note': label
,
116 'protocol': 'm3u8_native',
122 'format_note': label
,
124 self
._sort
_formats
(formats
)
126 metadata
= self
._extract
_metadata
(
127 'https://www.smashcast.tv/api/media/video', video_id
)
128 metadata
['formats'] = formats
133 class HitboxLiveIE(HitboxIE
):
134 IE_NAME
= 'hitbox:live'
135 _VALID_URL
= r
'https?://(?:www\.)?(?:hitbox|smashcast)\.tv/(?P<id>[^/?#&]+)'
137 'url': 'http://www.hitbox.tv/dimak',
141 'description': 'md5:c9f80fa4410bc588d7faa40003fc7d0e',
143 'upload_date': compat_str
,
149 'skip_download': True,
152 'url': 'https://www.smashcast.tv/dimak',
153 'only_matching': True,
157 def suitable(cls
, url
):
158 return False if HitboxIE
.suitable(url
) else super(HitboxLiveIE
, cls
).suitable(url
)
160 def _real_extract(self
, url
):
161 video_id
= self
._match
_id
(url
)
163 player_config
= self
._download
_json
(
164 'https://www.smashcast.tv/api/player/config/live/%s' % video_id
,
168 cdns
= player_config
.get('cdns')
171 # Subscribe URLs are not playable
172 if cdn
.get('rtmpSubscribe') is True:
174 base_url
= cdn
.get('netConnectionUrl')
175 host
= re
.search(r
'.+\.([^\.]+\.[^\./]+)/.+', base_url
).group(1)
176 if base_url
not in servers
:
177 servers
.append(base_url
)
178 for stream
in cdn
.get('bitrates'):
179 label
= stream
.get('label')
182 stream_url
= stream
.get('url')
185 bitrate
= int_or_none(stream
.get('bitrate'))
186 if stream
.get('provider') == 'hls' or determine_ext(stream_url
) == 'm3u8':
187 if not stream_url
.startswith('http'):
193 'format_note': label
,
198 'url': '%s/%s' % (base_url
, stream_url
),
204 'player_url': 'http://www.hitbox.tv/static/player/flowplayer/flowplayer.commercial-3.2.16.swf',
206 self
._sort
_formats
(formats
)
208 metadata
= self
._extract
_metadata
(
209 'https://www.smashcast.tv/api/media/live', video_id
)
210 metadata
['formats'] = formats
211 metadata
['is_live'] = True
212 metadata
['title'] = self
._live
_title
(metadata
.get('title'))