[onionstudios] fix info extraction

This commit is contained in:
Remita Amine 2016-07-05 18:04:42 +01:00
parent 73c4ac2c95
commit 6c26815d63
1 changed files with 25 additions and 36 deletions

View File

@ -7,6 +7,7 @@ from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
int_or_none, int_or_none,
float_or_none,
) )
@ -15,15 +16,14 @@ class OnionStudiosIE(InfoExtractor):
_TESTS = [{ _TESTS = [{
'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937', 'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
'md5': 'd4851405d31adfadf71cd7a487b765bb', 'md5': 'e49f947c105b8a78a675a0ee1bddedfe',
'info_dict': { 'info_dict': {
'id': '2937', 'id': '2937',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Hannibal charges forward, stops for a cocktail', 'title': 'Hannibal charges forward, stops for a cocktail',
'description': 'md5:e786add7f280b7f0fe237b64cc73df76',
'thumbnail': 're:^https?://.*\.jpg$', 'thumbnail': 're:^https?://.*\.jpg$',
'uploader': 'The A.V. Club', 'uploader': 'The A.V. Club',
'uploader_id': 'TheAVClub', 'uploader_id': 'the-av-club',
}, },
}, { }, {
'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true', 'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true',
@ -40,50 +40,39 @@ class OnionStudiosIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage( video_data = self._download_json(
'http://www.onionstudios.com/embed?id=%s' % video_id, video_id) 'http://www.onionstudios.com/video/%s.json' % video_id, video_id)
title = video_data['title']
formats = [] formats = []
for src in re.findall(r'<source[^>]+src="([^"]+)"', webpage): for source in video_data.get('sources', []):
ext = determine_ext(src) source_url = source.get('url')
if ext == 'm3u8': if not source_url:
continue
content_type = source.get('content_type')
ext = determine_ext(source_url)
if content_type == 'application/x-mpegURL' or ext == 'm3u8':
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)) source_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
else: else:
height = int_or_none(self._search_regex( tbr = int_or_none(source.get('bitrate'))
r'/(\d+)\.%s' % ext, src, 'height', default=None))
formats.append({ formats.append({
'format_id': ext + ('-%sp' % height if height else ''), 'format_id': ext + ('-%d' % tbr if tbr else ''),
'url': src, 'url': source_url,
'height': height, 'width': int_or_none(source.get('width')),
'tbr': tbr,
'ext': ext, 'ext': ext,
'preference': 1,
}) })
self._sort_formats(formats) self._sort_formats(formats)
title = self._search_regex(
r'share_title\s*=\s*(["\'])(?P<title>[^\1]+?)\1',
webpage, 'title', group='title')
description = self._search_regex(
r'share_description\s*=\s*(["\'])(?P<description>[^\'"]+?)\1',
webpage, 'description', default=None, group='description')
thumbnail = self._search_regex(
r'poster\s*=\s*(["\'])(?P<thumbnail>[^\1]+?)\1',
webpage, 'thumbnail', default=False, group='thumbnail')
uploader_id = self._search_regex(
r'twitter_handle\s*=\s*(["\'])(?P<uploader_id>[^\1]+?)\1',
webpage, 'uploader id', fatal=False, group='uploader_id')
uploader = self._search_regex(
r'window\.channelName\s*=\s*(["\'])Embedded:(?P<uploader>[^\1]+?)\1',
webpage, 'uploader', default=False, group='uploader')
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'description': description, 'thumbnail': video_data.get('poster_url'),
'thumbnail': thumbnail, 'uploader': video_data.get('channel_name'),
'uploader': uploader, 'uploader_id': video_data.get('channel_slug'),
'uploader_id': uploader_id, 'duration': float_or_none(video_data.get('duration', 1000)),
'tags': video_data.get('tags'),
'formats': formats, 'formats': formats,
} }