mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-09-01 10:55:08 +02:00
Compare commits
15 Commits
baf5375c22
...
8f982d5671
Author | SHA1 | Date | |
---|---|---|---|
|
8f982d5671 | ||
|
e1b3fa242c | ||
|
451046d62a | ||
|
526ef898bf | ||
|
31595de72b | ||
|
5a7243b741 | ||
|
d30180d4f3 | ||
|
ff47d11269 | ||
|
7f40887b29 | ||
|
c1a696ee40 | ||
|
b955e0a5dc | ||
|
030a5713e6 | ||
|
a85625977d | ||
|
fd733f52f5 | ||
|
35779eda7a |
@ -166,6 +166,14 @@ _NSIG_TESTS = [
|
||||
'https://www.youtube.com/s/player/b22ef6e7/player_ias.vflset/en_US/base.js',
|
||||
'b6HcntHGkvBLk_FRf', 'kNPW6A7FyP2l8A',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/3400486c/player_ias.vflset/en_US/base.js',
|
||||
'lL46g3XifCKUZn1Xfw', 'z767lhet6V2Skl',
|
||||
),
|
||||
(
|
||||
'https://www.youtube.com/s/player/5604538d/player_ias.vflset/en_US/base.js',
|
||||
'7X-he4jjvMx7BCX', 'sViSydX8IHtdWA',
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
@ -3,25 +3,38 @@ from __future__ import unicode_literals
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
determine_ext,
|
||||
js_to_json,
|
||||
)
|
||||
from ..compat import (
|
||||
compat_b64decode,
|
||||
compat_urllib_parse_unquote,
|
||||
)
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def decode_b64_url(code):
|
||||
decoded_url = re.match(r"[^[]*\[([^]]*)\]", code).groups()[0]
|
||||
return compat_b64decode(
|
||||
compat_urllib_parse_unquote(
|
||||
decoded_url.replace('"', '').replace('\'', '').replace(',', ''))).decode('utf-8')
|
||||
|
||||
|
||||
class RTPIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/p(?P<program_id>[0-9]+)/(?P<id>[^/?#]+)/?'
|
||||
_VALID_URL = r'https?://(?:(?:(?:www\.)?rtp\.pt/play/(?P<subarea>.*/)?p(?P<program_id>[0-9]+)/(?P<episode_id>e[0-9]+/)?)|(?:arquivos\.rtp\.pt/conteudos/))(?P<id>[^/?#]+)/?'
|
||||
_TESTS = [{
|
||||
'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas',
|
||||
'md5': 'e736ce0c665e459ddb818546220b4ef8',
|
||||
'url': 'https://www.rtp.pt/play/p9165/e562949/por-do-sol',
|
||||
'info_dict': {
|
||||
'id': 'e174042',
|
||||
'ext': 'mp3',
|
||||
'title': 'Paixões Cruzadas',
|
||||
'description': 'As paixões musicais de António Cartaxo e António Macedo',
|
||||
'id': 'por-do-sol',
|
||||
'ext': 'mp4',
|
||||
'title': 'PĂ´r do Sol EpisĂłdio 1 - de 16 Ago 2021',
|
||||
'description': 'Madalena Bourbon de Linhaça vive atormentada pelo segredo que esconde desde 1990. Matilde Bourbon de Linhaça sonha fugir com o seu amor proibido. O en',
|
||||
'thumbnail': r're:^https?://.*\.jpg',
|
||||
},
|
||||
}, {
|
||||
'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
|
||||
'url': 'https://www.rtp.pt/play/p510/aleixo-fm',
|
||||
'only_matching': True,
|
||||
}]
|
||||
|
||||
@ -29,30 +42,61 @@ class RTPIE(InfoExtractor):
|
||||
video_id = self._match_id(url)
|
||||
|
||||
webpage = self._download_webpage(url, video_id)
|
||||
title = self._html_search_meta(
|
||||
'twitter:title', webpage, display_name='title', fatal=True)
|
||||
|
||||
config = self._parse_json(self._search_regex(
|
||||
r'(?s)RTPPlayer\(({.+?})\);', webpage,
|
||||
'player config'), video_id, js_to_json)
|
||||
file_url = config['file']
|
||||
ext = determine_ext(file_url)
|
||||
if ext == 'm3u8':
|
||||
file_key = config.get('fileKey')
|
||||
formats = self._extract_m3u8_formats(
|
||||
file_url, video_id, 'mp4', 'm3u8_native',
|
||||
m3u8_id='hls', fatal=file_key)
|
||||
if file_key:
|
||||
formats.append({
|
||||
'url': 'https://cdn-ondemand.rtp.pt' + file_key,
|
||||
'preference': 1,
|
||||
})
|
||||
# Remove JS multi-line comments from webpage source
|
||||
webpage = re.sub(r'(\/\*.*\*\/)', '', webpage, flags=re.DOTALL)
|
||||
|
||||
title = self._html_search_regex(r'<title>(.+?)</title>', webpage, 'title')
|
||||
|
||||
# Replace irrelevant text in title
|
||||
title = title.replace(' - RTP Play - RTP', '')
|
||||
|
||||
# Check if it's a video split in parts, if so add part number to title
|
||||
part = self._html_search_regex(r'section\-parts.*<span.*>(.+?)</span>.*</ul>', webpage, 'part', default=None)
|
||||
if part:
|
||||
title = f'{title} {part}'
|
||||
|
||||
# Get JS object
|
||||
js_object = self._search_regex(r'(?s)RTPPlayer *\( *({.+?}) *\);', webpage, 'player config')
|
||||
json_string_for_config = ''
|
||||
full_url = None
|
||||
|
||||
# Verify JS object since it isn't pure JSON and maybe it needs some tuning
|
||||
for line in js_object.splitlines():
|
||||
stripped_line = line.strip()
|
||||
|
||||
# key == 'fileKey', then we found what we wanted
|
||||
if re.match(r'fileKey:', stripped_line):
|
||||
if re.match(r'fileKey: *""', stripped_line):
|
||||
raise ExtractorError("Episode not found (probably removed)", expected=True)
|
||||
url = decode_b64_url(stripped_line)
|
||||
if 'mp3' in url:
|
||||
full_url = 'https://cdn-ondemand.rtp.pt' + url
|
||||
else:
|
||||
full_url = 'https://streaming-vod.rtp.pt/dash{}/manifest.mpd'.format(url)
|
||||
|
||||
elif not stripped_line.startswith("//") and not re.match('file *:', stripped_line) and not re.match('.*extraSettings ?:', stripped_line):
|
||||
# Ignore commented lines, `extraSettings` and `f`. The latter seems to some random unrelated video.
|
||||
json_string_for_config += '\n' + line
|
||||
|
||||
if not full_url:
|
||||
raise ExtractorError("No valid media source found in page")
|
||||
|
||||
# Finally send pure JSON string for JSON parsing
|
||||
config = self._parse_json(json_string_for_config, video_id, js_to_json)
|
||||
full_url = full_url.replace('drm-dash', 'dash')
|
||||
ext = determine_ext(full_url)
|
||||
|
||||
if ext == 'mpd':
|
||||
# Download via mpd file
|
||||
formats = self._extract_mpd_formats(full_url, video_id)
|
||||
self._sort_formats(formats)
|
||||
else:
|
||||
formats = [{
|
||||
'url': file_url,
|
||||
'url': full_url,
|
||||
'ext': ext,
|
||||
}]
|
||||
|
||||
if config.get('mediaType') == 'audio':
|
||||
for f in formats:
|
||||
f['vcodec'] = 'none'
|
||||
|
@ -1647,7 +1647,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
except JSInterpreter.Exception as e:
|
||||
self.report_warning(
|
||||
'%s (%s %s)' % (
|
||||
'Unable to decode n-parameter: download likely to be throttled',
|
||||
'Unable to decode n-parameter: expect download to be blocked or throttled',
|
||||
error_to_compat_str(e),
|
||||
traceback.format_exc()),
|
||||
video_id=video_id)
|
||||
@ -1659,18 +1659,22 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
||||
def _extract_n_function_name(self, jscode):
|
||||
func_name, idx = self._search_regex(
|
||||
# new: (b=String.fromCharCode(110),c=a.get(b))&&c=nfunc[idx](c)
|
||||
# or: (b="nn"[+a.D],c=a.get(b))&&(c=nfunc[idx](c)s
|
||||
# old: .get("n"))&&(b=nfunc[idx](b)
|
||||
# older: .get("n"))&&(b=nfunc(b)
|
||||
r'''(?x)
|
||||
(?:\(\s*(?P<b>[a-z])\s*=\s*String\s*\.\s*fromCharCode\s*\(\s*110\s*\)\s*,(?P<c>[a-z])\s*=\s*[a-z]\s*)?
|
||||
\.\s*get\s*\(\s*(?(b)(?P=b)|"n")(?:\s*\)){2}\s*&&\s*\(\s*(?(c)(?P=c)|b)\s*=\s*
|
||||
(?:\(\s*(?P<b>[a-z])\s*=\s*(?:
|
||||
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
||||
"n+"\[\s*\+?s*[\w$.]+\s*]
|
||||
)\s*,(?P<c>[a-z])\s*=\s*[a-z]\s*)?
|
||||
\.\s*get\s*\(\s*(?(b)(?P=b)|"n{1,2}")(?:\s*\)){2}\s*&&\s*\(\s*(?(c)(?P=c)|b)\s*=\s*
|
||||
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
||||
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
|
||||
if not idx:
|
||||
return func_name
|
||||
|
||||
return self._parse_json(self._search_regex(
|
||||
r'var {0}\s*=\s*(\[.+?\])\s*[,;]'.format(re.escape(func_name)), jscode,
|
||||
r'var\s+{0}\s*=\s*(\[.+?\])\s*[,;]'.format(re.escape(func_name)), jscode,
|
||||
'Initial JS player n function list ({0}.{1})'.format(func_name, idx)),
|
||||
func_name, transform_source=js_to_json)[int(idx)]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user