[tvplayer] Fix extraction (closes #12908)

This commit is contained in:
Sergey M․ 2017-04-29 03:39:39 +07:00
parent bc8a2ea071
commit b364c87c42
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -2,9 +2,13 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_HTTPError from ..compat import (
compat_HTTPError,
compat_str,
)
from ..utils import ( from ..utils import (
extract_attributes, extract_attributes,
try_get,
urlencode_postdata, urlencode_postdata,
ExtractorError, ExtractorError,
) )
@ -34,25 +38,32 @@ def _real_extract(self, url):
webpage, 'channel element')) webpage, 'channel element'))
title = current_channel['data-name'] title = current_channel['data-name']
resource_id = self._search_regex( resource_id = current_channel['data-id']
r'resourceId\s*=\s*"(\d+)"', webpage, 'resource id')
platform = self._search_regex(
r'platform\s*=\s*"([^"]+)"', webpage, 'platform')
token = self._search_regex( token = self._search_regex(
r'token\s*=\s*"([^"]+)"', webpage, 'token', default='null') r'data-token=(["\'])(?P<token>(?!\1).+)\1', webpage,
validate = self._search_regex( 'token', group='token')
r'validate\s*=\s*"([^"]+)"', webpage, 'validate', default='null')
context = self._download_json(
'https://tvplayer.com/watch/context', display_id,
'Downloading JSON context', query={
'resource': resource_id,
'nonce': token,
})
validate = context['validate']
platform = try_get(
context, lambda x: x['platform']['key'], compat_str) or 'firefox'
try: try:
response = self._download_json( response = self._download_json(
'http://api.tvplayer.com/api/v2/stream/live', 'http://api.tvplayer.com/api/v2/stream/live',
resource_id, headers={ display_id, 'Downloading JSON stream', headers={
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
}, data=urlencode_postdata({ }, data=urlencode_postdata({
'id': resource_id,
'service': 1, 'service': 1,
'platform': platform, 'platform': platform,
'id': resource_id,
'token': token,
'validate': validate, 'validate': validate,
}))['tvplayer']['response'] }))['tvplayer']['response']
except ExtractorError as e: except ExtractorError as e:
@ -63,7 +74,7 @@ def _real_extract(self, url):
'%s said: %s' % (self.IE_NAME, response['error']), expected=True) '%s said: %s' % (self.IE_NAME, response['error']), expected=True)
raise raise
formats = self._extract_m3u8_formats(response['stream'], resource_id, 'mp4') formats = self._extract_m3u8_formats(response['stream'], display_id, 'mp4')
self._sort_formats(formats) self._sort_formats(formats)
return { return {