import json
from .common import InfoExtractor
-from ..compat import compat_urllib_request
from ..utils import (
ExtractorError,
parse_iso8601,
+ sanitized_Request,
)
@staticmethod
def make_json_request(url, data):
payload = json.dumps(data).encode('utf-8')
- req = compat_urllib_request.Request(url, payload)
+ req = sanitized_Request(url, payload)
req.add_header('Content-Type', 'application/json; charset=utf-8')
return req
@staticmethod
- def find_assets(data, asset_type):
+ def find_assets(data, asset_type, asset_id=None):
for asset in data.get('assets', []):
- if asset.get('type') == asset_type:
+ if not asset.get('type') == asset_type:
+ continue
+ elif asset_id is not None and not asset.get('id') == asset_id:
+ continue
+ else:
yield asset
def _check_access_rights(self, data):
access_info = data.get('__view', {})
- if access_info.get('allow_access') == False:
+ if not access_info.get('allow_access', True):
err_code = access_info.get('error_code') or ''
if err_code == 'ITEM_PAID_ONLY':
raise ExtractorError(
req = VesselIE.make_json_request(
self._API_URL_TEMPLATE % asset_id, {'client': 'web'})
data = self._download_json(req, video_id)
+ video_asset_id = data.get('main_video_asset')
self._check_access_rights(data)
try:
- video_asset = next(VesselIE.find_assets(data, 'video'))
+ video_asset = next(
+ VesselIE.find_assets(data, 'video', asset_id=video_asset_id))
except StopIteration:
raise ExtractorError('No video assets found')