mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-01-01 06:21:09 +01:00
Added RTVE play compatibility
This commit is contained in:
parent
cba7868502
commit
7d27c259ac
2 changed files with 60 additions and 36 deletions
|
@ -1764,6 +1764,7 @@ from .rtve import (
|
||||||
RTVEInfantilIE,
|
RTVEInfantilIE,
|
||||||
RTVELiveIE,
|
RTVELiveIE,
|
||||||
RTVETelevisionIE,
|
RTVETelevisionIE,
|
||||||
|
RTVEPlayIE,
|
||||||
)
|
)
|
||||||
from .rtvs import RTVSIE
|
from .rtvs import RTVSIE
|
||||||
from .rtvslo import (
|
from .rtvslo import (
|
||||||
|
|
|
@ -20,7 +20,7 @@ class RTVEALaCartaIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?rtve\.es/(m/)?(alacarta/videos|filmoteca)/[^/]+/[^/]+/(?P<id>\d+)'
|
_VALID_URL = r'https?://(?:www\.)?rtve\.es/(m/)?(alacarta/videos|filmoteca)/[^/]+/[^/]+/(?P<id>\d+)'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://www.rtve.es/alacarta/videos/balonmano/o-swiss-cup-masculina-final-espana-suecia/2491869/',
|
'url': 'https://www.rtve.es/play/videos/balonmano/liga-guerreras-iberdrola-4-jornada/6974343/',
|
||||||
'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
|
'md5': '1d49b7e1ca7a7502c56a4bf1b60f1b43',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '2491869',
|
'id': '2491869',
|
||||||
|
@ -70,23 +70,31 @@ class RTVEALaCartaIE(InfoExtractor):
|
||||||
def _decrypt_url(png):
|
def _decrypt_url(png):
|
||||||
encrypted_data = io.BytesIO(base64.b64decode(png)[8:])
|
encrypted_data = io.BytesIO(base64.b64decode(png)[8:])
|
||||||
while True:
|
while True:
|
||||||
length = struct.unpack('!I', encrypted_data.read(4))[0]
|
length_data = encrypted_data.read(4)
|
||||||
|
length = struct.unpack('!I', length_data)[0]
|
||||||
chunk_type = encrypted_data.read(4)
|
chunk_type = encrypted_data.read(4)
|
||||||
if chunk_type == b'IEND':
|
if chunk_type == b'IEND':
|
||||||
break
|
break
|
||||||
data = encrypted_data.read(length)
|
data = encrypted_data.read(length)
|
||||||
if chunk_type == b'tEXt':
|
if chunk_type == b'tEXt':
|
||||||
|
if b'%%' in data:
|
||||||
alphabet_data, text = data.split(b'\0')
|
alphabet_data, text = data.split(b'\0')
|
||||||
quality, url_data = text.split(b'%%')
|
quality, url_data = text.split(b'%%')
|
||||||
alphabet = []
|
alphabet = RTVEPlayIE._get_alfabet(alphabet_data)
|
||||||
e = 0
|
url = RTVEPlayIE._get_url(alphabet, url_data)
|
||||||
d = 0
|
quality_str = quality.decode()
|
||||||
for l in alphabet_data.decode('iso-8859-1'):
|
|
||||||
if d == 0:
|
|
||||||
alphabet.append(l)
|
|
||||||
d = e = (e + 1) % 4
|
|
||||||
else:
|
else:
|
||||||
d -= 1
|
data = bytes(filter(None, data))
|
||||||
|
alphabet_data, url_data = data.split(b'#')
|
||||||
|
alphabet = RTVEPlayIE._get_alfabet(alphabet_data)
|
||||||
|
|
||||||
|
url = RTVEPlayIE._get_url(alphabet, url_data)
|
||||||
|
quality_str = ""
|
||||||
|
yield quality_str, url
|
||||||
|
encrypted_data.read(4) # CRC
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_url(alphabet, url_data):
|
||||||
url = ''
|
url = ''
|
||||||
f = 0
|
f = 0
|
||||||
e = 3
|
e = 3
|
||||||
|
@ -104,9 +112,20 @@ class RTVEALaCartaIE(InfoExtractor):
|
||||||
b += 1
|
b += 1
|
||||||
else:
|
else:
|
||||||
e -= 1
|
e -= 1
|
||||||
|
return url
|
||||||
|
|
||||||
yield quality.decode(), url
|
@staticmethod
|
||||||
encrypted_data.read(4) # CRC
|
def _get_alfabet(alphabet_data):
|
||||||
|
alphabet = []
|
||||||
|
e = 0
|
||||||
|
d = 0
|
||||||
|
for l in alphabet_data.decode('iso-8859-1'):
|
||||||
|
if d == 0:
|
||||||
|
alphabet.append(l)
|
||||||
|
d = e = (e + 1) % 4
|
||||||
|
else:
|
||||||
|
d -= 1
|
||||||
|
return alphabet
|
||||||
|
|
||||||
def _extract_png_formats(self, video_id):
|
def _extract_png_formats(self, video_id):
|
||||||
png = self._download_webpage(
|
png = self._download_webpage(
|
||||||
|
@ -141,9 +160,7 @@ class RTVEALaCartaIE(InfoExtractor):
|
||||||
title = info['title'].strip()
|
title = info['title'].strip()
|
||||||
formats = self._extract_png_formats(video_id)
|
formats = self._extract_png_formats(video_id)
|
||||||
|
|
||||||
subtitles = None
|
sbt_file = "https://api2.rtve.es/api/videos/%s/subtitulos.json" % video_id
|
||||||
sbt_file = info.get('sbtFile')
|
|
||||||
if sbt_file:
|
|
||||||
subtitles = self.extract_subtitles(video_id, sbt_file)
|
subtitles = self.extract_subtitles(video_id, sbt_file)
|
||||||
|
|
||||||
is_live = info.get('live') is True
|
is_live = info.get('live') is True
|
||||||
|
@ -161,7 +178,7 @@ class RTVEALaCartaIE(InfoExtractor):
|
||||||
|
|
||||||
def _get_subtitles(self, video_id, sub_file):
|
def _get_subtitles(self, video_id, sub_file):
|
||||||
subs = self._download_json(
|
subs = self._download_json(
|
||||||
sub_file + '.json', video_id,
|
sub_file, video_id,
|
||||||
'Downloading subtitles info')['page']['items']
|
'Downloading subtitles info')['page']['items']
|
||||||
return dict(
|
return dict(
|
||||||
(s['lang'], [{'ext': 'vtt', 'url': s['src']}])
|
(s['lang'], [{'ext': 'vtt', 'url': s['src']}])
|
||||||
|
@ -340,3 +357,9 @@ class RTVETelevisionIE(InfoExtractor):
|
||||||
'The webpage doesn\'t contain any video', expected=True)
|
'The webpage doesn\'t contain any video', expected=True)
|
||||||
|
|
||||||
return self.url_result(alacarta_url, ie=RTVEALaCartaIE.ie_key())
|
return self.url_result(alacarta_url, ie=RTVEALaCartaIE.ie_key())
|
||||||
|
|
||||||
|
|
||||||
|
class RTVEPlayIE(RTVEALaCartaIE):
|
||||||
|
IE_NAME = 'rtve.es:play'
|
||||||
|
IE_DESC = 'RTVE play'
|
||||||
|
_VALID_URL = r'https?://(?:www\.)?rtve\.es/(m/)?play/videos/[^/]+/[^/]+/(?P<id>\d+)'
|
||||||
|
|
Loading…
Reference in a new issue