[tubitv] fix extraction(closes #8741)

This commit is contained in:
remitamine 2016-04-21 20:29:42 +01:00
parent bdbb8530c7
commit 9260cf1d97

View File

@ -1,7 +1,6 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import codecs
import re import re
from .common import InfoExtractor from .common import InfoExtractor
@ -10,22 +9,24 @@
int_or_none, int_or_none,
sanitized_Request, sanitized_Request,
urlencode_postdata, urlencode_postdata,
parse_iso8601,
) )
class TubiTvIE(InfoExtractor): class TubiTvIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?tubitv\.com/video\?id=(?P<id>[0-9]+)' _VALID_URL = r'https?://(?:www\.)?tubitv\.com/video/(?P<id>[0-9]+)'
_LOGIN_URL = 'http://tubitv.com/login' _LOGIN_URL = 'http://tubitv.com/login'
_NETRC_MACHINE = 'tubitv' _NETRC_MACHINE = 'tubitv'
_TEST = { _TEST = {
'url': 'http://tubitv.com/video?id=54411&title=The_Kitchen_Musical_-_EP01', 'url': 'http://tubitv.com/video/283829/the_comedian_at_the_friday',
'info_dict': { 'info_dict': {
'id': '54411', 'id': '283829',
'ext': 'mp4', 'ext': 'mp4',
'title': 'The Kitchen Musical - EP01', 'title': 'The Comedian at The Friday',
'thumbnail': 're:^https?://.*\.png$', 'description': 'A stand up comedian is forced to look at the decisions in his life while on a one week trip to the west coast.',
'description': 'md5:37532716166069b353e8866e71fefae7', 'uploader': 'Indie Rights Films',
'duration': 2407, 'upload_date': '20160111',
'timestamp': 1452555979,
}, },
'params': { 'params': {
'skip_download': 'HLS download', 'skip_download': 'HLS download',
@ -55,27 +56,31 @@ def _real_initialize(self):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
video_data = self._download_json(
'http://tubitv.com/oz/videos/%s/content' % video_id, video_id)
title = video_data['n']
webpage = self._download_webpage(url, video_id) formats = self._extract_m3u8_formats(
if re.search(r"<(?:DIV|div) class='login-required-screen'>", webpage): video_data['mh'], video_id, 'mp4', 'm3u8_native')
self.raise_login_required('This video requires login')
title = self._og_search_title(webpage)
description = self._og_search_description(webpage)
thumbnail = self._og_search_thumbnail(webpage)
duration = int_or_none(self._html_search_meta(
'video:duration', webpage, 'duration'))
apu = self._search_regex(r"apu='([^']+)'", webpage, 'apu')
m3u8_url = codecs.decode(apu, 'rot_13')[::-1]
formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4')
self._sort_formats(formats) self._sort_formats(formats)
subtitles = {}
for sub in video_data.get('sb', []):
sub_url = sub.get('u')
if not sub_url:
continue
subtitles.setdefault(sub.get('l', 'en'), []).append({
'url': sub_url,
})
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'formats': formats, 'formats': formats,
'thumbnail': thumbnail, 'subtitles': subtitles,
'description': description, 'thumbnail': video_data.get('ph'),
'duration': duration, 'description': video_data.get('d'),
'duration': int_or_none(video_data.get('s')),
'timestamp': parse_iso8601(video_data.get('u')),
'uploader': video_data.get('on'),
} }