[viewster] extract all http formats

This commit is contained in:
remitamine 2016-04-24 02:32:56 +01:00
parent 5448b781f6
commit 864d5e7231

View File

@ -1,6 +1,8 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import (
compat_HTTPError, compat_HTTPError,
@ -14,6 +16,7 @@ from ..utils import (
parse_iso8601, parse_iso8601,
sanitized_Request, sanitized_Request,
HEADRequest, HEADRequest,
url_basename,
) )
@ -114,6 +117,7 @@ class ViewsterIE(InfoExtractor):
return self.playlist_result(entries, video_id, title, description) return self.playlist_result(entries, video_id, title, description)
formats = [] formats = []
manifest_url = None
for media_type in ('application/f4m+xml', 'application/x-mpegURL', 'video/mp4'): for media_type in ('application/f4m+xml', 'application/x-mpegURL', 'video/mp4'):
media = self._download_json( media = self._download_json(
'https://public-api.viewster.com/movies/%s/video?mediaType=%s' 'https://public-api.viewster.com/movies/%s/video?mediaType=%s'
@ -126,29 +130,37 @@ class ViewsterIE(InfoExtractor):
continue continue
ext = determine_ext(video_url) ext = determine_ext(video_url)
if ext == 'f4m': if ext == 'f4m':
manifest_url = video_url
video_url += '&' if '?' in video_url else '?' video_url += '&' if '?' in video_url else '?'
video_url += 'hdcore=3.2.0&plugin=flowplayer-3.2.0.1' video_url += 'hdcore=3.2.0&plugin=flowplayer-3.2.0.1'
formats.extend(self._extract_f4m_formats( formats.extend(self._extract_f4m_formats(
video_url, video_id, f4m_id='hds')) video_url, video_id, f4m_id='hds'))
elif ext == 'm3u8': elif ext == 'm3u8':
manifest_url = video_url
m3u8_formats = self._extract_m3u8_formats( m3u8_formats = self._extract_m3u8_formats(
video_url, video_id, 'mp4', m3u8_id='hls', video_url, video_id, 'mp4', m3u8_id='hls',
fatal=False) # m3u8 sometimes fail fatal=False) # m3u8 sometimes fail
if m3u8_formats: if m3u8_formats:
formats.extend(m3u8_formats) formats.extend(m3u8_formats)
else: else:
format_id = media.get('Bitrate') qualities_basename = self._search_regex(
f = { '/([^/]+)(?:.csmil/manifest.f4m|.csmil/master.m3u8)',
'url': video_url, manifest_url, 'qualities basename', default=None)
'format_id': 'mp4-%s' % format_id, if qualities_basename:
'height': int_or_none(media.get('Height')), QUALITIES_RE = r'((,\d+k)+,?)'
'width': int_or_none(media.get('Width')), qualities = self._search_regex(
'preference': 1, QUALITIES_RE, qualities_basename,
} 'qualities').strip(',').split(',')
if format_id and not f['height']: http_template = re.sub(QUALITIES_RE, r'%s', qualities_basename)
f['height'] = int_or_none(self._search_regex( http_url_basename = url_basename(video_url)
r'^(\d+)[pP]$', format_id, 'height', default=None)) for q in qualities:
formats.append(f) formats.append({
'url': video_url.replace(http_url_basename, http_template % q),
'ext': 'mp4',
'format_id': 'http-%s' % q,
'tbr': int_or_none(self._search_regex(
r'(\d+)k', q, 'bitrate', default=None)),
})
if not formats and not info.get('LanguageSets') and not info.get('VODSettings'): if not formats and not info.get('LanguageSets') and not info.get('VODSettings'):
self.raise_geo_restricted() self.raise_geo_restricted()