]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hitbox.py
84bd7c0804eb2966c7062288a1a190c8509f62fc
   2 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
  16 class HitboxIE(InfoExtractor
): 
  18     _VALID_URL 
= r
'https?://(?:www\.)?hitbox\.tv/video/(?P<id>[0-9]+)' 
  20         'url': 'http://www.hitbox.tv/video/203213', 
  23             'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy', 
  24             'alt_title': 'hitboxlive - Aug 9th #6', 
  27             'thumbnail': 're:^https?://.*\.jpg$', 
  29             'resolution': 'HD 720p', 
  30             'uploader': 'hitboxlive', 
  32             'timestamp': 1407576133, 
  33             'upload_date': '20140809', 
  34             'categories': ['Live Show'], 
  38             'skip_download': True, 
  42     def _extract_metadata(self
, url
, video_id
): 
  43         thumb_base 
= 'https://edge.sf.hitbox.tv' 
  44         metadata 
= self
._download
_json
( 
  45             '%s/%s' % (url
, video_id
), video_id
) 
  47         date 
= 'media_live_since' 
  48         media_type 
= 'livestream' 
  49         if metadata
.get('media_type') == 'video': 
  51             date 
= 'media_date_added' 
  53         video_meta 
= metadata
.get(media_type
, [])[0] 
  54         title 
= video_meta
.get('media_status') 
  55         alt_title 
= video_meta
.get('media_title') 
  56         description 
= clean_html( 
  57             video_meta
.get('media_description') or 
  58             video_meta
.get('media_description_md')) 
  59         duration 
= float_or_none(video_meta
.get('media_duration')) 
  60         uploader 
= video_meta
.get('media_user_name') 
  61         views 
= int_or_none(video_meta
.get('media_views')) 
  62         timestamp 
= parse_iso8601(video_meta
.get(date
), ' ') 
  63         categories 
= [video_meta
.get('category_name')] 
  65             {'url': thumb_base 
+ video_meta
.get('media_thumbnail'), 
  68             {'url': thumb_base 
+ video_meta
.get('media_thumbnail_large'), 
  76             'alt_title': alt_title
, 
  77             'description': description
, 
  83             'timestamp': timestamp
, 
  84             'categories': categories
, 
  87     def _real_extract(self
, url
): 
  88         video_id 
= self
._match
_id
(url
) 
  90         metadata 
= self
._extract
_metadata
( 
  91             'https://www.hitbox.tv/api/media/video', 
  94         player_config 
= self
._download
_json
( 
  95             'https://www.hitbox.tv/api/player/config/video/%s' % video_id
, 
  98         clip 
= player_config
.get('clip') 
  99         video_url 
= clip
.get('url') 
 100         res 
= clip
.get('bitrates', [])[0].get('label') 
 102         metadata
['resolution'] = res
 
 103         metadata
['url'] = video_url
 
 104         metadata
['protocol'] = 'm3u8' 
 109 class HitboxLiveIE(HitboxIE
): 
 110     IE_NAME 
= 'hitbox:live' 
 111     _VALID_URL 
= r
'https?://(?:www\.)?hitbox\.tv/(?!video)(?P<id>.+)' 
 113         'url': 'http://www.hitbox.tv/dimak', 
 117             'description': 'md5:c9f80fa4410bc588d7faa40003fc7d0e', 
 119             'upload_date': compat_str
, 
 125             'skip_download': True, 
 129     def _real_extract(self
, url
): 
 130         video_id 
= self
._match
_id
(url
) 
 132         metadata 
= self
._extract
_metadata
( 
 133             'https://www.hitbox.tv/api/media/live', 
 136         player_config 
= self
._download
_json
( 
 137             'https://www.hitbox.tv/api/player/config/live/%s' % video_id
, 
 141         cdns 
= player_config
.get('cdns') 
 144             base_url 
= cdn
.get('netConnectionUrl') 
 145             host 
= re
.search('.+\.([^\.]+\.[^\./]+)/.+', base_url
).group(1) 
 146             if base_url 
not in servers
: 
 147                 servers
.append(base_url
) 
 148                 for stream 
in cdn
.get('bitrates'): 
 149                     label 
= stream
.get('label') 
 152                             'url': '%s/%s' % (base_url
, stream
.get('url')), 
 154                             'vbr': stream
.get('bitrate'), 
 159                             'player_url': 'http://www.hitbox.tv/static/player/flowplayer/flowplayer.commercial-3.2.16.swf', 
 162         self
._sort
_formats
(formats
) 
 163         metadata
['formats'] = formats
 
 164         metadata
['is_live'] = True 
 165         metadata
['title'] = self
._live
_title
(metadata
.get('title'))