mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-12-23 12:40:11 +09:00
[nrk] improve format extraction and geo-restriction detection (closes #24221)
This commit is contained in:
parent
e91df0c550
commit
5e95e18ce9
@ -24,6 +24,11 @@ from ..utils import (
|
|||||||
class NRKBaseIE(InfoExtractor):
|
class NRKBaseIE(InfoExtractor):
|
||||||
_GEO_COUNTRIES = ['NO']
|
_GEO_COUNTRIES = ['NO']
|
||||||
|
|
||||||
|
def _extract_nrk_formats(self, asset_url, video_id):
|
||||||
|
return self._extract_m3u8_formats(
|
||||||
|
re.sub(r'(?:bw_(?:low|high)=\d+|no_audio_only)&?', '', asset_url),
|
||||||
|
video_id, 'mp4', 'm3u8_native', fatal=False)
|
||||||
|
|
||||||
|
|
||||||
class NRKIE(NRKBaseIE):
|
class NRKIE(NRKBaseIE):
|
||||||
_VALID_URL = r'''(?x)
|
_VALID_URL = r'''(?x)
|
||||||
@ -94,9 +99,7 @@ class NRKIE(NRKBaseIE):
|
|||||||
if not format_url:
|
if not format_url:
|
||||||
continue
|
continue
|
||||||
if asset.get('format') == 'HLS' or determine_ext(format_url) == 'm3u8':
|
if asset.get('format') == 'HLS' or determine_ext(format_url) == 'm3u8':
|
||||||
formats.extend(self._extract_m3u8_formats(
|
formats.extend(self._extract_nrk_formats(format_url, video_id))
|
||||||
format_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
|
||||||
m3u8_id='hls', fatal=False))
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
data = self._download_json(
|
data = self._download_json(
|
||||||
@ -298,6 +301,7 @@ class NRKTVIE(NRKBaseIE):
|
|||||||
title = data.get('fullTitle') or data.get('mainTitle') or data['title']
|
title = data.get('fullTitle') or data.get('mainTitle') or data['title']
|
||||||
video_id = data.get('id') or video_id
|
video_id = data.get('id') or video_id
|
||||||
|
|
||||||
|
urls = []
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
conviva = data.get('convivaStatistics') or {}
|
conviva = data.get('convivaStatistics') or {}
|
||||||
@ -314,19 +318,13 @@ class NRKTVIE(NRKBaseIE):
|
|||||||
else ('%s-%d' % (video_id, idx), '%s (Part %d)' % (title, idx)))
|
else ('%s-%d' % (video_id, idx), '%s (Part %d)' % (title, idx)))
|
||||||
for num, asset in enumerate(media_assets, 1):
|
for num, asset in enumerate(media_assets, 1):
|
||||||
asset_url = asset.get('url')
|
asset_url = asset.get('url')
|
||||||
if not asset_url:
|
if not asset_url or asset_url in urls:
|
||||||
continue
|
continue
|
||||||
formats = self._extract_akamai_formats(asset_url, video_id)
|
formats = extract_nrk_formats(asset_url, video_id)
|
||||||
if not formats:
|
if not formats:
|
||||||
continue
|
continue
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
# Some f4m streams may not work with hdcore in fragments' URLs
|
|
||||||
for f in formats:
|
|
||||||
extra_param = f.get('extra_param_to_segment_url')
|
|
||||||
if extra_param and 'hdcore' in extra_param:
|
|
||||||
del f['extra_param_to_segment_url']
|
|
||||||
|
|
||||||
entry_id, entry_title = video_id_and_title(num)
|
entry_id, entry_title = video_id_and_title(num)
|
||||||
duration = parse_duration(asset.get('duration'))
|
duration = parse_duration(asset.get('duration'))
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
@ -346,8 +344,9 @@ class NRKTVIE(NRKBaseIE):
|
|||||||
|
|
||||||
if not entries:
|
if not entries:
|
||||||
media_url = data.get('mediaUrl')
|
media_url = data.get('mediaUrl')
|
||||||
if media_url:
|
if media_url and media_url not in urls:
|
||||||
formats = self._extract_akamai_formats(media_url, video_id)
|
formats = extract_nrk_formats(media_url, video_id)
|
||||||
|
if formats:
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
duration = parse_duration(data.get('duration'))
|
duration = parse_duration(data.get('duration'))
|
||||||
entries = [{
|
entries = [{
|
||||||
@ -366,7 +365,7 @@ class NRKTVIE(NRKBaseIE):
|
|||||||
}
|
}
|
||||||
message_type = data.get('messageType', '')
|
message_type = data.get('messageType', '')
|
||||||
# Can be ProgramIsGeoBlocked or ChannelIsGeoBlocked*
|
# Can be ProgramIsGeoBlocked or ChannelIsGeoBlocked*
|
||||||
if 'IsGeoBlocked' in message_type:
|
if 'IsGeoBlocked' in message_type or try_get(data, lambda x: x['usageRights']['isGeoBlocked']) is Trues:
|
||||||
self.raise_geo_restricted(
|
self.raise_geo_restricted(
|
||||||
msg=MESSAGES.get('ProgramIsGeoBlocked'),
|
msg=MESSAGES.get('ProgramIsGeoBlocked'),
|
||||||
countries=self._GEO_COUNTRIES)
|
countries=self._GEO_COUNTRIES)
|
||||||
|
Loading…
Reference in New Issue
Block a user