Compare commits

...

5 Commits

Author SHA1 Message Date
somini
89e7f01a46
Merge 10eeaa6bfd into b83ca24eb7 2024-11-10 09:19:38 +05:30
sepro
b83ca24eb7
[core] Catch broken Cryptodome installations (#11486)
Authored by: seproDev
2024-11-10 00:53:49 +01:00
bashonly
240a7d43c8
[build] Pin websockets version to >=13.0,<14 (#11488)
websockets 14.0 causes CI test failures (a lot more of them)

Authored by: bashonly
2024-11-09 23:46:47 +00:00
bashonly
f13df591d4
[build] Enable attestations for trusted publishing (#11420)
Reverts 428ffb75aa

Authored by: bashonly
2024-11-09 23:26:02 +00:00
somini
10eeaa6bfd
[RTP] Fixup RTP Play support
See #4661
See https://github.com/ytdl-org/youtube-dl/pull/29824

See #10787
2024-10-03 01:35:25 +01:00
7 changed files with 124 additions and 69 deletions

View File

@ -504,7 +504,8 @@ jobs:
- windows32 - windows32
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/download-artifact@v4 - name: Download artifacts
uses: actions/download-artifact@v4
with: with:
path: artifact path: artifact
pattern: build-bin-* pattern: build-bin-*

View File

@ -28,3 +28,20 @@ jobs:
actions: write # For cleaning up cache actions: write # For cleaning up cache
id-token: write # mandatory for trusted publishing id-token: write # mandatory for trusted publishing
secrets: inherit secrets: inherit
publish_pypi:
needs: [release]
if: vars.MASTER_PYPI_PROJECT != ''
runs-on: ubuntu-latest
permissions:
id-token: write # mandatory for trusted publishing
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
name: build-pypi
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true

View File

@ -41,3 +41,20 @@ jobs:
actions: write # For cleaning up cache actions: write # For cleaning up cache
id-token: write # mandatory for trusted publishing id-token: write # mandatory for trusted publishing
secrets: inherit secrets: inherit
publish_pypi:
needs: [release]
if: vars.NIGHTLY_PYPI_PROJECT != ''
runs-on: ubuntu-latest
permissions:
id-token: write # mandatory for trusted publishing
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
name: build-pypi
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true

View File

@ -2,10 +2,6 @@ name: Release
on: on:
workflow_call: workflow_call:
inputs: inputs:
prerelease:
required: false
default: true
type: boolean
source: source:
required: false required: false
default: '' default: ''
@ -18,6 +14,10 @@ on:
required: false required: false
default: '' default: ''
type: string type: string
prerelease:
required: false
default: true
type: boolean
workflow_dispatch: workflow_dispatch:
inputs: inputs:
source: source:
@ -278,11 +278,20 @@ jobs:
make clean-cache make clean-cache
python -m build --no-isolation . python -m build --no-isolation .
- name: Upload artifacts
if: github.event_name != 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: build-pypi
path: |
dist/*
compression-level: 0
- name: Publish to PyPI - name: Publish to PyPI
if: github.event_name == 'workflow_dispatch'
uses: pypa/gh-action-pypi-publish@release/v1 uses: pypa/gh-action-pypi-publish@release/v1
with: with:
verbose: true verbose: true
attestations: false # Currently doesn't work w/ reusable workflows (breaks nightly)
publish: publish:
needs: [prepare, build] needs: [prepare, build]

View File

@ -52,7 +52,7 @@ default = [
"pycryptodomex", "pycryptodomex",
"requests>=2.32.2,<3", "requests>=2.32.2,<3",
"urllib3>=1.26.17,<3", "urllib3>=1.26.17,<3",
"websockets>=13.0", "websockets>=13.0,<14",
] ]
curl-cffi = [ curl-cffi = [
"curl-cffi==0.5.10; os_name=='nt' and implementation_name=='cpython'", "curl-cffi==0.5.10; os_name=='nt' and implementation_name=='cpython'",

View File

@ -24,7 +24,7 @@ try:
from Crypto.Cipher import AES, PKCS1_OAEP, Blowfish, PKCS1_v1_5 # noqa: F401 from Crypto.Cipher import AES, PKCS1_OAEP, Blowfish, PKCS1_v1_5 # noqa: F401
from Crypto.Hash import CMAC, SHA1 # noqa: F401 from Crypto.Hash import CMAC, SHA1 # noqa: F401
from Crypto.PublicKey import RSA # noqa: F401 from Crypto.PublicKey import RSA # noqa: F401
except ImportError: except (ImportError, OSError):
__version__ = f'broken {__version__}'.strip() __version__ = f'broken {__version__}'.strip()

View File

@ -1,22 +1,27 @@
import base64 import base64
import json
import re import re
import urllib.parse import urllib.parse
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import js_to_json from ..utils import ExtractorError, determine_ext, join_nonempty
def decode_b64_url(code):
decoded_url = re.match(r'[^[]*\[([^]]*)\]', code).groups()[0]
return base64.b64decode(
urllib.parse.unquote(re.sub(r'[\s"\',]', '', decoded_url)),
).decode('utf-8')
class RTPIE(InfoExtractor): class RTPIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?rtp\.pt/play/(?:(?:estudoemcasa|palco|zigzag)/)?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 = [{ _TESTS = [{
'url': 'http://www.rtp.pt/play/p405/e174042/paixoes-cruzadas', 'url': 'https://www.rtp.pt/play/p9165/e562949/por-do-sol',
'md5': 'e736ce0c665e459ddb818546220b4ef8',
'info_dict': { 'info_dict': {
'id': 'e174042', 'id': 'por-do-sol',
'ext': 'mp3', 'ext': 'mp4',
'title': 'Paixões Cruzadas', 'title': 'Pôr do Sol Episódio 1 - de 16 Ago 2021',
'description': 'As paixões musicais de António Cartaxo e António Macedo', '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', 'thumbnail': r're:^https?://.*\.jpg',
}, },
}, { }, {
@ -30,76 +35,82 @@ class RTPIE(InfoExtractor):
'thumbnail': r're:^https?://.*\.jpg', 'thumbnail': r're:^https?://.*\.jpg',
}, },
}, { }, {
'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas', 'url': 'https://www.rtp.pt/play/p831/e205093/a-quimica-das-coisas',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'https://www.rtp.pt/play/estudoemcasa/p7776/portugues-1-ano', 'url': 'https://www.rtp.pt/play/estudoemcasa/p7776/e500050/portugues-1-ano',
'only_matching': True, 'only_matching': True,
}, { }, {
'url': 'https://www.rtp.pt/play/palco/p13785/l7nnon', 'url': 'https://www.rtp.pt/play/palco/p9138/jose-afonso-traz-um-amigo-tambem',
'only_matching': True,
}, {
'url': 'https://www.rtp.pt/play/p510/e798152/aleixo-fm',
'only_matching': True, 'only_matching': True,
}] }]
_RX_OBFUSCATION = re.compile(r'''(?xs)
atob\s*\(\s*decodeURIComponent\s*\(\s*
(\[[0-9A-Za-z%,'"]*\])
\s*\.\s*join\(\s*(?:""|'')\s*\)\s*\)\s*\)
''')
def __unobfuscate(self, data, *, video_id):
if data.startswith('{'):
data = self._RX_OBFUSCATION.sub(
lambda m: json.dumps(
base64.b64decode(urllib.parse.unquote(
''.join(self._parse_json(m.group(1), video_id)),
)).decode('iso-8859-1')),
data)
return js_to_json(data)
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
title = self._html_search_meta(
'twitter:title', webpage, display_name='title', fatal=True)
f, config = self._search_regex( # Remove comments from webpage source
r'''(?sx) webpage = re.sub(r'(?s)/\*.*\*/', '', webpage)
(?:var\s+f\s*=\s*(?P<f>".*?"|{[^;]+?});\s*)? webpage = re.sub(r'(?m)(?:^|\s)//.*$', '', webpage)
var\s+player1\s+=\s+new\s+RTPPlayer\s*\((?P<config>{(?:(?!\*/).)+?})\);(?!\s*\*/)
''', webpage,
'player config', group=('f', 'config'))
config = self._parse_json( title = self._html_search_regex(r'<title>(.+?)</title>', webpage, 'title', default='')
config, video_id, # Replace irrelevant text in title
lambda data: self.__unobfuscate(data, video_id=video_id)) title = title.replace(' - RTP Play - RTP', '') or self._html_search_meta('twitter:title', webpage)
f = config['file'] if not f else self._parse_json(
f, video_id,
lambda data: self.__unobfuscate(data, video_id=video_id))
formats = [] if 'Este episódio não se encontra disponí' in title:
if isinstance(f, dict): raise ExtractorError('Episode unavailable', expected=True)
f_hls = f.get('hls')
if f_hls is not None:
formats.extend(self._extract_m3u8_formats(
f_hls, video_id, 'mp4', 'm3u8_native', m3u8_id='hls'))
f_dash = f.get('dash') part = self._html_search_regex(r'section\-parts.*<span.*>(.+?)</span>.*</ul>', webpage, 'part', default=None)
if f_dash is not None: title = join_nonempty(title, part, delim=' ')
formats.extend(self._extract_mpd_formats(f_dash, video_id, mpd_id='dash'))
# Get file key
file_key = self._search_regex(r'\s*fileKey: "([^"]+)",', webpage, 'file key - open', default=None)
if file_key is None:
self.write_debug('url: obfuscated')
file_key = self._search_regex(r'\s*fileKey: atob\( decodeURIComponent\((.*)\)\)\),', webpage, 'file key')
url = decode_b64_url(file_key) or ''
else: else:
formats.append({ self.write_debug('url: clean')
'format_id': 'f', url = file_key
'url': f,
'vcodec': 'none' if config.get('mediaType') == 'audio' else None, if 'mp3' in url:
}) full_url = 'https://cdn-ondemand.rtp.pt' + url
elif 'mp4' in url:
full_url = f'https://streaming-vod.rtp.pt/dash{url}/manifest.mpd'
else:
full_url = None
if not full_url:
raise ExtractorError('No valid media source found in page')
poster = self._search_regex(r'\s*poster: "([^"]+)"', webpage, 'poster', fatal=False)
# Finally send pure JSON string for JSON parsing
full_url = full_url.replace('drm-dash', 'dash')
ext = determine_ext(full_url)
if ext == 'mpd':
# Download via mpd file
self.write_debug('formats: mpd')
formats = self._extract_mpd_formats(full_url, video_id)
else:
self.write_debug('formats: ext={ext}')
formats = [{
'url': full_url,
'ext': ext,
}]
subtitles = {} subtitles = {}
vtt = self._search_regex(r'\s*vtt: (.*]]),\s+', webpage, 'vtt', default=None)
vtt = config.get('vtt')
if vtt is not None: if vtt is not None:
for lcode, lname, url in vtt: vtt_object = self._parse_json(vtt.replace("'", '"'), full_url)
subtitles.setdefault(lcode, []).append({ self.write_debug(f'vtt: {len(vtt_object)} subtitles')
for lcode, lname, url in vtt_object:
subtitles.setdefault(lcode.lower(), []).append({
'name': lname, 'name': lname,
'url': url, 'url': url,
}) })
@ -109,6 +120,6 @@ class RTPIE(InfoExtractor):
'title': title, 'title': title,
'formats': formats, 'formats': formats,
'description': self._html_search_meta(['description', 'twitter:description'], webpage), 'description': self._html_search_meta(['description', 'twitter:description'], webpage),
'thumbnail': config.get('poster') or self._og_search_thumbnail(webpage), 'thumbnail': poster or self._og_search_thumbnail(webpage),
'subtitles': subtitles, 'subtitles': subtitles,
} }