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

Code before:
            except ExtractorError:
                self.report_warning('PhantomJS is highly recommended for this video, as it might load incredibly slowly otherwise.'
                                    'You can also try opening the page in this device\'s browser first')

        video_meta, meta_paths = self._call_api(
            'https://api.rctiplus.com/api/v1/%s/%s' % (video_type, video_id), display_id, 'Downloading video metadata')

        thumbnails, image_path = [], meta_paths.get('image_path', 'https://rstatic.akamaized.net/media/')
        if video_meta.get('portrait_image'):
            thumbnails.append({
                'id': 'portrait_image',
                'url': image_path + '2000' + video_meta['portrait_image']
            })
        if video_meta.get('landscape_image'):
            thumbnails.append({
                'id': 'landscape_image',
                'url': image_path + '2000' + video_meta['landscape_image']
            })

        formats = self._extract_m3u8_formats(video_url, display_id, 'mp4', headers={'Referer': 'https://www.rctiplus.com/'})
        self._sort_formats(formats)

        for f in formats:
            if 'akamaized' in f['url']:
                f.setdefault('http_headers', {})['Referer'] = 'https://www.rctiplus.com/'  # Referer header is required for akamai CDNs

        return {
            'id': video_meta.get('product_id') or video_json.get('product_id'),
            'title': video_meta.get('title') or video_json.get('content_name'),
            'display_id': display_id,
            'description': video_meta.get('summary'),
            'timestamp': video_meta.get('release_date'),
            'duration': video_meta.get('duration'),
            'categories': [video_meta.get('genre')],
            'average_rating': video_meta.get('star_rating'),
            'series': video_meta.get('program_title') or video_json.get('program_title'),
            'season_number': video_meta.get('season'),
            'episode_number': video_meta.get('episode'),
            'channel': video_json.get('tv_name'),
            'channel_id': video_json.get('tv_id'),
            'formats': formats,
            'thumbnails': thumbnails
        }


class RCTIPlusSeriesIE(RCTIPlusBaseIE):
    _VALID_URL = r'https://www\.rctiplus\.com/programs/(?P<id>\d+)/(?P<display_id>[^/?#&]+)(?:\W)*$'
    _TESTS = [{
        'url': 'https://www.rctiplus.com/programs/540/upin-ipin',
        'playlist_mincount': 417,
        'info_dict': {

Review comment (suggestion):
```suggestion
        for f in formats:
            if 'akamaized' in f['url']:
                f.setdefault('http_headers', {})['Referer'] = 'https://www.rctiplus.com/'

        self._sort_formats(formats)
```

Don't edit `formats` after sorting

Code after:
                phantom.get(url, webpage, display_id, note2='Initiating video session')
            except ExtractorError:
                self.report_warning('PhantomJS is highly recommended for this video, as it might load incredibly slowly otherwise.'
                                    'You can also try opening the page in this device\'s browser first')

        video_meta, meta_paths = self._call_api(
            'https://api.rctiplus.com/api/v1/%s/%s' % (video_type, video_id), display_id, 'Downloading video metadata')

        thumbnails, image_path = [], meta_paths.get('image_path', 'https://rstatic.akamaized.net/media/')
        if video_meta.get('portrait_image'):
            thumbnails.append({
                'id': 'portrait_image',
                'url': '%s%d%s' % (image_path, 2000, video_meta['portrait_image'])  # 2000px seems to be the highest resolution that can be given
            })
        if video_meta.get('landscape_image'):
            thumbnails.append({
                'id': 'landscape_image',
                'url': '%s%d%s' % (image_path, 2000, video_meta['landscape_image'])
            })

        formats = self._extract_m3u8_formats(video_url, display_id, 'mp4', headers={'Referer': 'https://www.rctiplus.com/'})
        for f in formats:
            if 'akamaized' in f['url']:
                f.setdefault('http_headers', {})['Referer'] = 'https://www.rctiplus.com/'  # Referer header is required for akamai CDNs

        self._sort_formats(formats)

        return {
            'id': video_meta.get('product_id') or video_json.get('product_id'),
            'title': video_meta.get('title') or video_json.get('content_name'),
            'display_id': display_id,
            'description': video_meta.get('summary'),
            'timestamp': video_meta.get('release_date'),
            'duration': video_meta.get('duration'),
            'categories': [video_meta.get('genre')],
            'average_rating': video_meta.get('star_rating'),
            'series': video_meta.get('program_title') or video_json.get('program_title'),
            'season_number': video_meta.get('season'),
            'episode_number': video_meta.get('episode'),
            'channel': video_json.get('tv_name'),
            'channel_id': video_json.get('tv_id'),
            'formats': formats,
            'thumbnails': thumbnails
        }


class RCTIPlusSeriesIE(RCTIPlusBaseIE):
    _VALID_URL = r'https://www\.rctiplus\.com/programs/(?P<id>\d+)/(?P<display_id>[^/?#&]+)(?:\W)*$'
    _TESTS = [{
        'url': 'https://www.rctiplus.com/programs/540/upin-ipin',
        'playlist_mincount': 417,