mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-12-22 16:08:58 +00:00
[ntvcojp] fix extractor
This commit is contained in:
@@ -1,9 +1,13 @@
|
|||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..networking.exceptions import HTTPError
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
smuggle_url,
|
clean_html,
|
||||||
traverse_obj,
|
int_or_none,
|
||||||
|
unified_timestamp,
|
||||||
|
urljoin,
|
||||||
)
|
)
|
||||||
|
from ..utils.traversal import find_element, traverse_obj
|
||||||
|
|
||||||
|
|
||||||
class NTVCoJpCUIE(InfoExtractor):
|
class NTVCoJpCUIE(InfoExtractor):
|
||||||
@@ -11,45 +15,70 @@ class NTVCoJpCUIE(InfoExtractor):
|
|||||||
IE_DESC = 'Nippon Television Network'
|
IE_DESC = 'Nippon Television Network'
|
||||||
_VALID_URL = r'https?://cu\.ntv\.co\.jp/(?!program)(?P<id>[^/?&#]+)'
|
_VALID_URL = r'https?://cu\.ntv\.co\.jp/(?!program)(?P<id>[^/?&#]+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'https://cu.ntv.co.jp/televiva-chill-gohan_181031/',
|
'url': 'https://cu.ntv.co.jp/gaki_20250525/',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '5978891207001',
|
'title': '放送開始36年!方正ココリコが選ぶ神回&地獄回!',
|
||||||
|
'id': 'gaki_20250525',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': '桜エビと炒り卵がポイント! 「中華風 エビチリおにぎり」──『美虎』五十嵐美幸',
|
'categories': ['ダウンタウンのガキの使いやあらへんで!'],
|
||||||
'upload_date': '20181213',
|
'description': '神回地獄回座談会!レギュラー放送1756回の中からココリコと方正が神回と地獄回をそれぞれ選んで発表!若手時代の遠藤がガキ使メンバーに振り回される!?田中が好きな懐かしの番組名物キャラに爆笑!?方正が思い出に残っている持ち込み回とは?笑ってはいけないシリーズから遠藤が大汗をかくほど追い詰められる企画が誕生していた!?3人のトラウマになっている過酷罰ゲームを振り返り!方正記念企画のはずがまさかの展開で涙!?',
|
||||||
'description': 'md5:1985b51a9abc285df0104d982a325f2a',
|
'timestamp': 1748145124,
|
||||||
'uploader_id': '3855502814001',
|
'release_timestamp': 1748145539,
|
||||||
'timestamp': 1544669941,
|
'duration': 1450,
|
||||||
},
|
'episode_number': 255,
|
||||||
'params': {
|
'episode': '放送開始36年!方正ココリコが選ぶ神回&地獄回!',
|
||||||
# m3u8 download
|
'upload_date': '20250525',
|
||||||
'skip_download': True,
|
'release_date': '20250525',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
display_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, display_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
player_config = self._search_nuxt_data(webpage, display_id)
|
meta = self._search_json(r'window\.app\s*=', webpage, 'episode info', video_id, fatal=False)
|
||||||
video_id = traverse_obj(player_config, ('movie', 'video_id'))
|
episode = traverse_obj(meta, ('falcorCache', 'catalog', 'episode', video_id, 'value'))
|
||||||
if not video_id:
|
|
||||||
raise ExtractorError('Failed to extract video ID for Brightcove')
|
nt_path = self._search_regex(r'<script[^>]+src=["\'](/assets/nt\.[^"\']+\.js)["\']', webpage, 'stream API config')
|
||||||
account_id = traverse_obj(player_config, ('player', 'account')) or '3855502814001'
|
nt_js = self._download_webpage(urljoin(url, nt_path), video_id, note='Downloading stream API config')
|
||||||
title = traverse_obj(player_config, ('movie', 'name'))
|
video_url = self._search_regex(r'videoPlaybackUrl:\s*[\'"]([^\'"]+)[\'"]', nt_js, 'stream API url')
|
||||||
if not title:
|
api_key = self._search_regex(r'api_key:\s*[\'"]([^\'"]+)[\'"]', nt_js, 'stream API key')
|
||||||
og_title = self._og_search_title(webpage, fatal=False) or traverse_obj(player_config, ('player', 'title'))
|
|
||||||
if og_title:
|
try:
|
||||||
title = og_title.split('(', 1)[0].strip()
|
source_meta = self._download_json(
|
||||||
description = (traverse_obj(player_config, ('movie', 'description'))
|
f'{video_url}ref:{video_id}',
|
||||||
or self._html_search_meta(['description', 'og:description'], webpage))
|
video_id,
|
||||||
|
headers={'X-Streaks-Api-Key': api_key},
|
||||||
|
note='Downloading stream metadata',
|
||||||
|
)
|
||||||
|
except ExtractorError as e:
|
||||||
|
if isinstance(e.cause, HTTPError) and e.cause.status == 403:
|
||||||
|
self.raise_geo_restricted(countries=['JP'])
|
||||||
|
raise
|
||||||
|
|
||||||
|
formats, subtitles = [], {}
|
||||||
|
for src in traverse_obj(source_meta, ('sources', ..., 'src')):
|
||||||
|
fmts, subs = self._extract_m3u8_formats_and_subtitles(src, video_id, fatal=False)
|
||||||
|
formats.extend(fmts)
|
||||||
|
self._merge_subtitles(subs, target=subtitles)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'_type': 'url_transparent',
|
'title': traverse_obj(webpage, ({find_element(tag='h3')}, {clean_html})),
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'display_id': display_id,
|
**traverse_obj(
|
||||||
'title': title,
|
episode,
|
||||||
'description': description,
|
{
|
||||||
'url': smuggle_url(self.BRIGHTCOVE_URL_TEMPLATE % (account_id, video_id), {'geo_countries': ['JP']}),
|
'categories': ('keywords', {list}),
|
||||||
'ie_key': 'BrightcoveNew',
|
'id': ('content_id', {str}),
|
||||||
|
'description': ('description', 0, 'value'),
|
||||||
|
'timestamp': ('created_at', {unified_timestamp}),
|
||||||
|
'release_timestamp': ('pub_date', {unified_timestamp}),
|
||||||
|
'duration': ('tv_episode_info', 'duration', {int_or_none}),
|
||||||
|
'episode_number': ('tv_episode_info', 'episode_number', {int_or_none}),
|
||||||
|
'episode': ('title', lambda _, v: not v.get('is_phonetic'), 'value'),
|
||||||
|
'series': ('custom_data', 'program_name'),
|
||||||
|
},
|
||||||
|
get_all=False,
|
||||||
|
),
|
||||||
|
'formats': formats,
|
||||||
|
'subtitles': subtitles,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user