Skip to content

Commit

Permalink
[RCTIPlus] Remove PhantomJS dependency (yt-dlp#595)
Browse files Browse the repository at this point in the history
Authored by: MinePlayersPE
  • Loading branch information
MinePlayersPE authored Jul 30, 2021
1 parent 3619f78 commit d9e6e94
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions yt_dlp/extractor/rcti.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from __future__ import unicode_literals

import itertools
import json
import re

from .openload import PhantomJSwrapper
import time

from .common import InfoExtractor
from ..utils import (
Expand Down Expand Up @@ -88,6 +88,16 @@ class RCTIPlusIE(RCTIPlusBaseIE):
'format': 'bestvideo',
},
}]
_CONVIVA_JSON_TEMPLATE = {
't': 'CwsSessionHb',
'cid': 'ff84ae928c3b33064b76dec08f12500465e59a6f',
'clid': '0',
'sid': 0,
'seq': 0,
'caps': 0,
'sf': 7,
'sdk': True,
}

def _search_auth_key(self, webpage):
try:
Expand All @@ -105,15 +115,18 @@ def _real_extract(self, url):
'https://api.rctiplus.com/api/v1/%s/%s/url?appierid=.1' % (video_type, video_id), display_id, 'Downloading video URL JSON')[0]
video_url = video_json['url']
if 'akamaized' in video_url:
# Akamai's CDN requires a session to at least be made via Conviva's API
# TODO: Reverse-engineer Conviva's heartbeat code to avoid phantomJS
phantom = None
try:
phantom = PhantomJSwrapper(self)
phantom.get(url, webpage, display_id, note2='Initiating video session')
except ExtractorError:
self.report_warning('PhantomJS is highly recommended for this video, as it might load incredibly slowly otherwise.'
'You can also try opening the page in this device\'s browser first')
# For some videos hosted on Akamai's CDN (possibly AES-encrypted ones?), a session needs to at least be made via Conviva's API
conviva_json_data = {
**self._CONVIVA_JSON_TEMPLATE,
'url': video_url,
'sst': int(time.time())
}
conviva_json_res = self._download_json(
'https://ff84ae928c3b33064b76dec08f12500465e59a6f.cws.conviva.com/0/wsg', display_id,
'Creating Conviva session', 'Failed to create Conviva session',
fatal=False, data=json.dumps(conviva_json_data).encode('utf-8'))
if conviva_json_res and conviva_json_res.get('err') != 'ok':
self.report_warning('Conviva said: %s' % str(conviva_json_res.get('err')))

video_meta, meta_paths = self._call_api(
'https://api.rctiplus.com/api/v1/%s/%s' % (video_type, video_id), display_id, 'Downloading video metadata')
Expand Down

0 comments on commit d9e6e94

Please sign in to comment.