[hitbox] Minor changes

This commit is contained in:
Sergey M․ 2014-12-30 03:22:07 +06:00
parent e3947e2b7f
commit 0c0a70f4c6

View file

@ -1,14 +1,20 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
unified_strdate, clean_html,
parse_iso8601,
float_or_none,
int_or_none,
compat_str,
) )
class HitboxIE(InfoExtractor): class HitboxIE(InfoExtractor):
IE_NAME = 'hitbox'
_VALID_URL = r'https?://(?:www\.)?hitbox\.tv/video/(?P<id>[0-9]+)' _VALID_URL = r'https?://(?:www\.)?hitbox\.tv/video/(?P<id>[0-9]+)'
_TEST = { _TEST = {
'url': 'http://www.hitbox.tv/video/203213', 'url': 'http://www.hitbox.tv/video/203213',
@ -16,13 +22,14 @@ class HitboxIE(InfoExtractor):
'id': '203213', 'id': '203213',
'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy', 'title': 'hitbox @ gamescom, Sub Button Hype extended, Giveaway - hitbox News Update with Oxy',
'alt_title': 'hitboxlive - Aug 9th #6', 'alt_title': 'hitboxlive - Aug 9th #6',
'description': '\n', 'description': '',
'ext': 'mp4', 'ext': 'mp4',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
'duration': 215, 'duration': 215.1666,
'resolution': 'HD 720p', 'resolution': 'HD 720p',
'uploader_id': 'hitboxlive', 'uploader': 'hitboxlive',
'view_count': int, 'view_count': int,
'timestamp': 1407576133,
'upload_date': '20140809', 'upload_date': '20140809',
'categories': ['Live Show'], 'categories': ['Live Show'],
}, },
@ -35,8 +42,7 @@ class HitboxIE(InfoExtractor):
def _extract_metadata(self, url, video_id): def _extract_metadata(self, url, video_id):
thumb_base = 'https://edge.sf.hitbox.tv' thumb_base = 'https://edge.sf.hitbox.tv'
metadata = self._download_json( metadata = self._download_json(
'%s/%s' % (url, video_id), video_id '%s/%s' % (url, video_id), video_id)
)
date = 'media_live_since' date = 'media_live_since'
media_type = 'livestream' media_type = 'livestream'
@ -47,11 +53,13 @@ class HitboxIE(InfoExtractor):
video_meta = metadata.get(media_type, [])[0] video_meta = metadata.get(media_type, [])[0]
title = video_meta.get('media_status') title = video_meta.get('media_status')
alt_title = video_meta.get('media_title') alt_title = video_meta.get('media_title')
description = video_meta.get('media_description_md') description = clean_html(
duration = int(float(video_meta.get('media_duration'))) video_meta.get('media_description') or
video_meta.get('media_description_md'))
duration = float_or_none(video_meta.get('media_duration'))
uploader = video_meta.get('media_user_name') uploader = video_meta.get('media_user_name')
views = int(video_meta.get('media_views')) views = int_or_none(video_meta.get('media_views'))
upload_date = unified_strdate(video_meta.get(date)) timestamp = parse_iso8601(video_meta.get(date), ' ')
categories = [video_meta.get('category_name')] categories = [video_meta.get('category_name')]
thumbs = [ thumbs = [
{'url': thumb_base + video_meta.get('media_thumbnail'), {'url': thumb_base + video_meta.get('media_thumbnail'),
@ -70,9 +78,9 @@ class HitboxIE(InfoExtractor):
'ext': 'mp4', 'ext': 'mp4',
'thumbnails': thumbs, 'thumbnails': thumbs,
'duration': duration, 'duration': duration,
'uploader_id': uploader, 'uploader': uploader,
'view_count': views, 'view_count': views,
'upload_date': upload_date, 'timestamp': timestamp,
'categories': categories, 'categories': categories,
} }
@ -81,13 +89,11 @@ class HitboxIE(InfoExtractor):
metadata = self._extract_metadata( metadata = self._extract_metadata(
'https://www.hitbox.tv/api/media/video', 'https://www.hitbox.tv/api/media/video',
video_id video_id)
)
player_config = self._download_json( player_config = self._download_json(
'https://www.hitbox.tv/api/player/config/video/%s' % (video_id), 'https://www.hitbox.tv/api/player/config/video/%s' % video_id,
video_id video_id)
)
clip = player_config.get('clip') clip = player_config.get('clip')
video_url = clip.get('url') video_url = clip.get('url')
@ -101,16 +107,18 @@ class HitboxIE(InfoExtractor):
class HitboxLiveIE(HitboxIE): class HitboxLiveIE(HitboxIE):
IE_NAME = 'hitbox:live'
_VALID_URL = r'https?://(?:www\.)?hitbox\.tv/(?!video)(?P<id>.+)' _VALID_URL = r'https?://(?:www\.)?hitbox\.tv/(?!video)(?P<id>.+)'
_TEST = { _TEST = {
'url': 'http://www.hitbox.tv/dimak', 'url': 'http://www.hitbox.tv/dimak',
'info_dict': { 'info_dict': {
'id': 'dimak', 'id': 'dimak',
'ext': 'mp4', 'ext': 'mp4',
'description': str, 'description': 'md5:c9f80fa4410bc588d7faa40003fc7d0e',
'upload_date': str, 'timestamp': int,
'title': str, 'upload_date': compat_str,
'uploader_id': 'Dimak', 'title': compat_str,
'uploader': 'Dimak',
}, },
'params': { 'params': {
# live # live
@ -123,13 +131,11 @@ class HitboxLiveIE(HitboxIE):
metadata = self._extract_metadata( metadata = self._extract_metadata(
'https://www.hitbox.tv/api/media/live', 'https://www.hitbox.tv/api/media/live',
video_id video_id)
)
player_config = self._download_json( player_config = self._download_json(
'https://www.hitbox.tv/api/player/config/live/%s' % (video_id), 'https://www.hitbox.tv/api/player/config/live/%s' % video_id,
video_id video_id)
)
formats = [] formats = []
cdns = player_config.get('cdns') cdns = player_config.get('cdns')