Make further requested changes.
This commit is contained in:
parent
466f151a76
commit
5da61feddf
@ -566,36 +566,28 @@ class YahooJapanNewsIE(InfoExtractor):
|
|||||||
IE_NAME = 'yahoo:japannews'
|
IE_NAME = 'yahoo:japannews'
|
||||||
IE_DESC = 'Yahoo! Japan News'
|
IE_DESC = 'Yahoo! Japan News'
|
||||||
_VALID_URL = r'https?://(?P<host>(?:news|headlines)\.yahoo\.co\.jp)(/[^\d]*(?P<id>\d[\d-]*\d))?'
|
_VALID_URL = r'https?://(?P<host>(?:news|headlines)\.yahoo\.co\.jp)(/[^\d]*(?P<id>\d[\d-]*\d))?'
|
||||||
_TESTS = [
|
_TESTS = [{
|
||||||
{
|
'url': 'https://headlines.yahoo.co.jp/videonews/ann?a=20190716-00000071-ann-int',
|
||||||
'url': 'https://headlines.yahoo.co.jp/videonews/fnn?a=20190719-00421051-fnn-soci',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '20190719-00421051',
|
'id': '1736242',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': '15階から2歳女児転落死\u3000母は台所「目を離した隙に」(フジテレビ系(FNN)) - Yahoo!ニュース',
|
'title': 'ムン大統領が対日批判を強化“現金化”効果は?(テレビ朝日系(ANN)) - Yahoo!ニュース',
|
||||||
'description': '大阪市で18日夜、マンションの15階から2歳の女の子が転落し病院に運ばれたが、まもな - Yahoo!ニュース(フジテレビ系(FNN))',
|
'description': '韓国の元徴用工らを巡る裁判の原告が弁護士が差し押さえた三菱重工業の資産を売却して - Yahoo!ニュース(テレビ朝日系(ANN))',
|
||||||
'thumbnail': r're:^https?://.*\.[a-zA-Z\d]{3,4}$',
|
'thumbnail': r're:^https?://.*\.[a-zA-Z\d]{3,4}$',
|
||||||
},
|
}, 'params': {'skip_download': True},
|
||||||
'params': {'skip_download': True},
|
}, {
|
||||||
},
|
|
||||||
{
|
|
||||||
'url': 'https://headlines.yahoo.co.jp/videonews/',
|
'url': 'https://headlines.yahoo.co.jp/videonews/',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
'url': 'https://news.yahoo.co.jp',
|
'url': 'https://news.yahoo.co.jp',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
'url': 'https://news.yahoo.co.jp/byline/hashimotojunji/20190628-00131977/',
|
'url': 'https://news.yahoo.co.jp/byline/hashimotojunji/20190628-00131977/',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
'url': 'https://news.yahoo.co.jp/feature/1356',
|
'url': 'https://news.yahoo.co.jp/feature/1356',
|
||||||
'only_matching': True
|
'only_matching': True
|
||||||
},
|
}]
|
||||||
]
|
|
||||||
_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
|
|
||||||
|
|
||||||
def _extract_formats(self, json_data, content_id):
|
def _extract_formats(self, json_data, content_id):
|
||||||
formats = []
|
formats = []
|
||||||
@ -603,8 +595,7 @@ class YahooJapanNewsIE(InfoExtractor):
|
|||||||
video_data = try_get(
|
video_data = try_get(
|
||||||
json_data,
|
json_data,
|
||||||
lambda x: x['ResultSet']['Result'][0]['VideoUrlSet']['VideoUrl'],
|
lambda x: x['ResultSet']['Result'][0]['VideoUrlSet']['VideoUrl'],
|
||||||
list,
|
list)
|
||||||
)
|
|
||||||
for vid in video_data or []:
|
for vid in video_data or []:
|
||||||
delivery = vid.get('delivery')
|
delivery = vid.get('delivery')
|
||||||
url = url_or_none(vid.get('Url'))
|
url = url_or_none(vid.get('Url'))
|
||||||
@ -614,29 +605,21 @@ class YahooJapanNewsIE(InfoExtractor):
|
|||||||
formats.extend(
|
formats.extend(
|
||||||
self._extract_m3u8_formats(
|
self._extract_m3u8_formats(
|
||||||
url, content_id, 'mp4', 'm3u8_native',
|
url, content_id, 'mp4', 'm3u8_native',
|
||||||
m3u8_id='hls', fatal=False,
|
m3u8_id='hls', fatal=False))
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
formats.append(
|
formats.append({
|
||||||
{
|
'url': url,
|
||||||
'url': url,
|
'format_id': 'http-%s' % compat_str(vid.get('bitrate', '')),
|
||||||
'format_id': 'http-%s' % compat_str(vid.get('bitrate', '')),
|
'ext': determine_ext(url),
|
||||||
'ext': determine_ext(url),
|
'height': int_or_none(vid.get('height')),
|
||||||
'height': int_or_none(vid.get('height')),
|
'width': int_or_none(vid.get('width')),
|
||||||
'width': int_or_none(vid.get('width')),
|
'btr': int_or_none(vid.get('bitrate'))
|
||||||
'btr': int_or_none(vid.get('bitrate')),
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
self._remove_duplicate_formats(formats)
|
self._remove_duplicate_formats(formats)
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _get_md5(s):
|
|
||||||
return hashlib.md5(s.encode()).hexdigest()
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
host = mobj.group('host')
|
host = mobj.group('host')
|
||||||
@ -644,46 +627,34 @@ class YahooJapanNewsIE(InfoExtractor):
|
|||||||
display_id = mobj.group('id') or host
|
display_id = mobj.group('id') or host
|
||||||
webpage = self._download_webpage(url, display_id)
|
webpage = self._download_webpage(url, display_id)
|
||||||
|
|
||||||
title = (
|
title = self._html_search_meta(
|
||||||
self._og_search_title(webpage, default=None)
|
['og:title', 'twitter:title'], webpage, 'title', default=None
|
||||||
or self._html_search_meta('twitter:title', webpage, default=None)
|
) or self._html_search_regex('<title>([^<]+)</title>', webpage, 'title')
|
||||||
or self._html_search_regex('<title>([^<]+)</title>', webpage, 'title')
|
description = self._html_search_meta([
|
||||||
)
|
'og:description', 'description', 'twitter:description'
|
||||||
description = (
|
], webpage, 'description', default=None)
|
||||||
self._og_search_description(webpage, default=None)
|
|
||||||
or self._html_search_meta('description', webpage, default=None)
|
|
||||||
or self._html_search_meta('twitter:description', webpage, default=None)
|
|
||||||
)
|
|
||||||
thumbnail = self._og_search_thumbnail(
|
thumbnail = self._og_search_thumbnail(
|
||||||
webpage, default=None
|
webpage, default=None
|
||||||
) or self._html_search_meta('twitter:image', webpage, default=None)
|
) or self._html_search_meta('twitter:image', webpage, 'thumbnail', default=None)
|
||||||
space_id = (
|
space_id = self._search_regex([
|
||||||
self._search_regex(
|
r'<script[^>]+class=["\']yvpub-player["\'][^>]+spaceid=([^&"\']+)',
|
||||||
r'<script[^>]+class=(["\'])yvpub-player\1[^>]+spaceid=(?P<spaceid>[^&"\']+)',
|
r'YAHOO\.JP\.srch\.\w+link\.onLoad[^;]+spaceID["\' ]*:["\' ]+([^"\']+)',
|
||||||
webpage, 'spaceid', group='spaceid', default=None,
|
r'<!--\s+SpaceID=(\d+)'
|
||||||
)
|
], webpage, 'spaceid')
|
||||||
or self._search_regex(
|
|
||||||
r'YAHOO\.JP\.srch\.\w+link\.onLoad[^;]+spaceID["\' ]*:["\' ]+([^"\']+)',
|
|
||||||
webpage, 'spaceid', default=None,
|
|
||||||
)
|
|
||||||
or self._search_regex(r'<!--\s+SpaceID=(\d+)', webpage, 'spaceid')
|
|
||||||
)
|
|
||||||
formats = []
|
formats = []
|
||||||
|
|
||||||
if display_id == host:
|
if display_id == host:
|
||||||
# Headline page (w/ multiple BC playlists)
|
# Headline page (w/ multiple BC playlists)
|
||||||
stream_urls_plists = re.findall(
|
stream_urls_plists = re.findall(
|
||||||
r'YJNEWS\.LIVESTREAM\.SRC.+=(?:\s+)?["\'](?P<streamurl>[^"\']+plist=(?P<plist>\d+)[^"\']+)',
|
r'YJNEWS\.LIVESTREAM\.SRC.+=(?:\s+)?["\'](?P<streamurl>[^"\']+plist=(?P<plist>\d+)[^"\']+)',
|
||||||
webpage,
|
webpage)
|
||||||
)
|
|
||||||
if not stream_urls_plists:
|
if not stream_urls_plists:
|
||||||
# Manually build ('news.yahoo.co.jp', ...)
|
# Manually build ('news.yahoo.co.jp', ...)
|
||||||
sbase_url = 'https://s.yimg.jp/images/media/video/player/html/embed_1.2.5.html?service=news&service_type=video&plist=%s&poster=%s&sp=%s&country=JP'
|
sbase_url = 'https://s.yimg.jp/images/media/video/player/html/embed_1.2.5.html?service=news&service_type=video&plist=%s&poster=%s&sp=%s&country=JP'
|
||||||
|
|
||||||
params = re.findall(
|
params = re.findall(
|
||||||
r'["\']plist["\']:\s*["\'](?P<plist>[^"\']+)[^;]+?["\']poster["\']:\s*["\'](?P<poster>[^"\']+)[^;]+?["\']spaceId["\']:\s*["\'](?P<spaceid>[^"\']+)',
|
r'["\']plist["\']:\s*["\'](?P<plist>[^"\']+)[^;]+?["\']poster["\']:\s*["\'](?P<poster>[^"\']+)[^;]+?["\']spaceId["\']:\s*["\'](?P<spaceid>[^"\']+)',
|
||||||
webpage,
|
webpage)
|
||||||
)
|
|
||||||
for p in params:
|
for p in params:
|
||||||
stream_urls_plists.append((sbase_url % p, p[0]))
|
stream_urls_plists.append((sbase_url % p, p[0]))
|
||||||
|
|
||||||
@ -697,59 +668,51 @@ class YahooJapanNewsIE(InfoExtractor):
|
|||||||
'Authority': 's.yimg.jp',
|
'Authority': 's.yimg.jp',
|
||||||
'Path': '/images/media/video/player/js/embed_1.0.9.min.js',
|
'Path': '/images/media/video/player/js/embed_1.0.9.min.js',
|
||||||
'Referer': url,
|
'Referer': url,
|
||||||
'User-Agent': self._USER_AGENT,
|
}, fatal=False)
|
||||||
},
|
|
||||||
)
|
|
||||||
account = self._search_regex(
|
account = self._search_regex(
|
||||||
r'\w+\.video_attr\[(["\'])data-account\1\]\s*=\s*\1(?P<accountid>[\d]+)',
|
r'\w+\.video_attr\[(["\'])data-account\1\]\s*=\s*\1(?P<accountid>[\d]+)',
|
||||||
embed_page, 'account id', group='accountid',
|
embed_page, 'account id', group='accountid', fatal=False)
|
||||||
)
|
|
||||||
player = self._search_regex(
|
player = self._search_regex(
|
||||||
r'\w+\.video_attr\[(["\'])data-player\1\]\s*=\s*\1(?P<playerid>[^"\']+)',
|
r'\w+\.video_attr\[(["\'])data-player\1\]\s*=\s*\1(?P<playerid>[^"\']+)',
|
||||||
embed_page, 'player id', group='playerid',
|
embed_page, 'player id', group='playerid', fatal=False)
|
||||||
)
|
|
||||||
embed = self._search_regex(
|
embed = self._search_regex(
|
||||||
r'(["\'])data-embed\1\s*:\s*\1(?P<embed>[^"\']+)',
|
r'(["\'])data-embed\1\s*:\s*\1(?P<embed>[^"\']+)',
|
||||||
embed_page, 'embed', group='embed',
|
embed_page, 'embed', group='embed', fatal=False)
|
||||||
)
|
if not all([embed_page, account, player, embed]):
|
||||||
|
continue
|
||||||
entries.append(bc_url % (account, player, embed, plist_id))
|
entries.append(bc_url % (account, player, embed, plist_id))
|
||||||
|
|
||||||
return self.playlist_from_matches(entries, space_id, title, ie='BrightcoveNew')
|
return self.playlist_from_matches(entries, space_id, title, ie='BrightcoveNew')
|
||||||
|
|
||||||
else:
|
# Article page
|
||||||
# Article page
|
app_id = 'dj0zaiZpPVZMTVFJR0FwZWpiMyZzPWNvbnN1bWVyc2VjcmV0Jng9YjU-'
|
||||||
app_id = 'dj0zaiZpPVZMTVFJR0FwZWpiMyZzPWNvbnN1bWVyc2VjcmV0Jng9YjU-'
|
content_id = self._search_regex(
|
||||||
content_id = self._search_regex(
|
r'<script[^>]+class=(["\'])yvpub-player\1[^>]+contentid=(?P<contentid>[^&"\']+)',
|
||||||
r'<script[^>]+class=(["\'])yvpub-player\1[^>]+contentid=(?P<contentid>[^&"\']+)',
|
webpage, 'contentid', group='contentid', default=space_id)
|
||||||
webpage, 'contentid', group='contentid', default=space_id,
|
# md5 hash of space_id + '_headlines.yahoo.co.jp'
|
||||||
)
|
ak = hashlib.md5('_'.join((space_id, host)).encode()).hexdigest()
|
||||||
# md5 hash of space_id + '_headlines.yahoo.co.jp'
|
|
||||||
ak = YahooJapanNewsIE._get_md5('_'.join((space_id, host)))
|
|
||||||
|
|
||||||
json_data = self._download_json(
|
json_data = self._download_json(
|
||||||
'https://feapi-yvpub.yahooapis.jp/v1/content/%s' % content_id,
|
'https://feapi-yvpub.yahooapis.jp/v1/content/%s' % content_id,
|
||||||
content_id,
|
content_id,
|
||||||
headers={
|
headers={
|
||||||
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||||
'Origin': 'https://s.yimg.jp',
|
'Origin': 'https://s.yimg.jp',
|
||||||
'Host': 'feapi-yvpub.yahooapis.jp',
|
'Host': 'feapi-yvpub.yahooapis.jp',
|
||||||
'User-Agent': self._USER_AGENT,
|
'Referer': 'https://s.yimg.jp/images/yvpub/player/vamos/pc/latest/player.html',
|
||||||
'Referer': 'https://s.yimg.jp/images/yvpub/player/vamos/pc/latest/player.html',
|
},
|
||||||
},
|
query={
|
||||||
query={
|
'appid': app_id,
|
||||||
'appid': app_id,
|
'output': 'json',
|
||||||
'output': 'json',
|
'space_id': space_id,
|
||||||
'space_id': space_id,
|
'domain': host,
|
||||||
'domain': host,
|
'ak': ak,
|
||||||
'ak': ak,
|
'device_type': '1100',
|
||||||
'device_type': '1100',
|
})
|
||||||
},
|
formats = self._extract_formats(json_data, content_id)
|
||||||
fatal=False,
|
|
||||||
)
|
|
||||||
formats = self._extract_formats(json_data, content_id)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': display_id,
|
'id': content_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user