Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/rtve.py (Python)

Code before:
        encrypted_data = io.BytesIO(base64.b64decode(png)[8:])
        while True:
            length_data = encrypted_data.read(4)
            length = struct.unpack('!I', length_data)[0]
            chunk_type = encrypted_data.read(4)
            if chunk_type == b'IEND':
                break
            data = encrypted_data.read(length)
            if chunk_type == b'tEXt':
                if b'%%' in data:
                    alphabet_data, text = data.split(b'\0')
                    quality, url_data = text.split(b'%%')
                    alphabet = RTVEALaCartaIE._get_alfabet(alphabet_data)
                    url = RTVEALaCartaIE._get_url(alphabet, url_data)
                    quality_str = quality.decode()
                else:
                    data = bytes(filter(None, data))
                    alphabet_data, url_data = data.split(b'#')
                    alphabet = RTVEALaCartaIE._get_alfabet(alphabet_data)

                    url = RTVEALaCartaIE._get_url(alphabet, url_data)
                    quality_str = ''
                yield quality_str, url
            encrypted_data.read(4)  # CRC

    @staticmethod
    def _get_url(alphabet, url_data):
        url = ''
        f = 0
        e = 3
        b = 1
        for letter in url_data.decode('iso-8859-1'):
            if f == 0:
                l = int(letter) * 10
                f = 1
            else:
                if e == 0:
                    l += int(letter)
                    url += alphabet[l]
                    e = (b + 3) % 4
                    f = 0
                    b += 1
                else:
                    e -= 1
        return url

    @staticmethod
    def _get_alfabet(alphabet_data):
        alphabet = []
        e = 0
        d = 0

Review comment (suggestion):
Lets leave a comment.
```suggestion
    # Reimplementation of https://js2.rtve.es/pages/app-player/3.5.1/js/pf_video.js
    @staticmethod
```

Code after:
                    fmts, subs = self._extract_m3u8_formats_and_subtitles(
                        video_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
                    formats.extend(fmts)
                    self._merge_subtitles(subs, target=subtitles)
                elif ext == 'mpd':
                    fmts, subs = self._extract_mpd_formats_and_subtitles(
                        video_url, video_id, 'dash', fatal=False)
                    formats.extend(fmts)
                    self._merge_subtitles(subs, target=subtitles)
                else:
                    formats.append({
                        'format_id': quality,
                        'quality': q(quality),
                        'url': video_url,
                    })
        return formats, subtitles

    def _parse_metadata(self, metadata):
        return traverse_obj(metadata, {
            'title': ('title', {str.strip}),
            'alt_title': ('alt', {str.strip}),
            'description': ('description', {clean_html}),
            'timestamp': ('dateOfEmission', {parse_iso8601(delimiter=' ')}),
            'release_timestamp': ('publicationDate', {parse_iso8601(delimiter=' ')}),
            'modified_timestamp': ('modificationDate', {parse_iso8601(delimiter=' ')}),
            'thumbnail': (('thumbnail', 'image', 'imageSEO'), {url_or_none}, any),
            'duration': ('duration', {float_or_none(scale=1000)}),
            'is_live': ('live', {bool}),
            'series': (('programTitle', ('programInfo', 'title')), {clean_html}, any),
        })


class RTVEALaCartaIE(RTVEBaseIE):
    IE_NAME = 'rtve.es:alacarta'
    IE_DESC = 'RTVE a la carta and Play'
    _VALID_URL = [
        r'https?://(?:www\.)?rtve\.es/(?:m/)?(?:(?:alacarta|play)/videos|filmoteca)/(?!directo)(?:[^/?#]+/){2}(?P<id>\d+)',
        r'https?://(?:www\.)?rtve\.es/infantil/serie/[^/?#]+/video/[^/?#]+/(?P<id>\d+)',
    ]

    _TESTS = [{
        'url': 'http://www.rtve.es/alacarta/videos/la-aventura-del-saber/aventuraentornosilla/3088905/',
        'md5': 'a964547824359a5753aef09d79fe984b',
        'info_dict': {
            'id': '3088905',
            'ext': 'mp4',
            'title': 'En torno a la silla',
            'duration': 1216.981,
            'series': 'La aventura del Saber',
            'thumbnail': 'https://img2.rtve.es/v/aventuraentornosilla_3088905.png',
        },