Compare commits

..

2 Commits

Author SHA1 Message Date
SirElderling
263303c5e3 [9News] Add Extractor - apply seproDev suggestions 2023-12-23 20:09:57 +00:00
SirElderling
8c23e06dcd [9News] Add Extractor - fix imports 2023-12-23 19:51:34 +00:00

View File

@ -1,10 +1,7 @@
from .common import InfoExtractor from .common import InfoExtractor
from ._extractors import BrightcoveNewIE from .brightcove import BrightcoveNewIE
from ..utils import ( from ..utils import ExtractorError, traverse_obj
ExtractorError,
traverse_obj,
)
class News9IE(InfoExtractor): class News9IE(InfoExtractor):
@ -59,17 +56,11 @@ class News9IE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
article_id = self._match_id(url) article_id = self._match_id(url)
webpage = self._download_webpage(url, article_id) webpage = self._download_webpage(url, article_id)
initial_state = self._search_json(r'var\s__INITIAL_STATE__\s*=', webpage, 'initial state', article_id) initial_state = self._search_json(r'var\s+__INITIAL_STATE__\s*=', webpage, 'initial state', article_id)
video_id = traverse_obj(
info = traverse_obj(initial_state, { initial_state, ('videoIndex', 'currentVideo', 'brightcoveId'),
'video_id': ('videoIndex', 'currentVideo', 'brightcoveId'), ('article', ..., 'media', lambda _, v: v['type'] == 'video', 'urn'), get_all=False)
'account': ('videoIndex', 'config', 'account'), account = traverse_obj(initial_state, ('videoIndex', 'config', (None, 'video'), 'account'), get_all=False)
}) or traverse_obj(initial_state, {
'video_id': ('article', ..., 'media', lambda _, v: v['type'] == 'video', 'urn'),
'account': ('videoIndex', 'config', 'video', 'account')}, get_all=False)
video_id = info.get('video_id')
account = info.get('account')
if not video_id or not account: if not video_id or not account:
raise ExtractorError('Unable to get the required video data') raise ExtractorError('Unable to get the required video data')