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

Code before:

                series_id = try_get(episode, lambda x: x['contentMeta']['displayMeta']['seriesID'])
                season_id = try_get(episode, lambda x: x['contentMeta']['displayMeta']['seasonID'])
                season_number = int_or_none(try_get(episode, lambda x: x['contentMeta']['displayMeta']['seasonNum']))
                episode_number = int_or_none(try_get(episode, lambda x: x['contentMeta']['displayMeta']['episodeNum']))

                ext = determine_ext(video_url)
                if ext == "m3u8":
                    formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_url, video_id, 'mp4', fatal=False)
                    self._sort_formats(formats)

                    entries.append({
                        'id': video_id,
                        'title': title,
                        'description': description,
                        'formats': formats,
                        'subtitles': subtitles,
                        'thumbnail': thumbnail,
                        'series': series_title,
                        'series_id': series_id,
                        'season_id': season_id,
                        'season_number': season_number,
                        'episode_number': episode_number,
                    })
                else:
                    print("No manifest was found for video_id {}".format(video_id))

        return self.playlist_result(entries, display_id, series_title, series_description)


class FreeTvMoviesIE(FreeTvBaseIE):
    _VALID_URL = r'https?://(?:www\.)?freetv\.com/(?:peliculas)/(?:[^/]+/)*(?P<id>[^/]+)'
    _TESTS = [{
        'url': 'https://www.freetv.com/peliculas/atrapame-si-puedes/',
        'md5': 'dc62d5abf0514726640077cd1591aa92',
        'info_dict': {
            'id': '428021',
            'title': 'Atrápame Si Puedes',
            'description': 'md5:ca63bc00898aeb2f64ec87c6d3a5b982',
            'ext': 'mp4',
        }
    }, {
        'url': 'https://www.freetv.com/peliculas/monstruoso/',
        'md5': '509c15c68de41cb708d1f92d071f20aa',
        'info_dict': {
            'id': '377652',
            'title': 'Monstruoso',
            'description': 'md5:333fc19ee327b457b980e54a911ea4a3',
            'ext': 'mp4',
        }
    }]

Review comment (refactor):
use `raise ExtractorError` or `self.report_warning` as appropriate

Code after:
            'title': 'El Detective L',
            'description': 'md5:f9f1143bc33e9856ecbfcbfb97a759be'
        },
        'playlist_count': 24,
    }, {
        'url': 'https://www.freetv.com/series/esmeraldas/',
        'info_dict': {
            'id': 'esmeraldas',
            'title': 'Esmeraldas',
            'description': 'md5:43d7ec45bd931d8268a4f5afaf4c77bf'
        },
        'playlist_count': 62,
    }, {
        'url': 'https://www.freetv.com/series/las-aventuras-de-leonardo/',
        'info_dict': {
            'id': 'las-aventuras-de-leonardo',
            'title': 'Las Aventuras de Leonardo',
            'description': 'md5:0c47130846c141120a382aca059288f6'
        },
        'playlist_count': 13,
    },
    ]

    def _extract_series_season(self, season_id, series_title):
        episodes = self._get_api_response(season_id, 'series', {
            'contentID': season_id,
            'action': 'olyott_get_dynamic_series_content',
            'type': 'list',
            'perPage': '1000',
        })['1']

        for episode in episodes:
            video_id = str(episode['contentID'])
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(episode['streamURL'], video_id, 'mp4')
            self._sort_formats(formats)

            yield {
                'id': video_id,
                'title': episode.get('fullTitle'),
                'description': episode.get('description'),
                'formats': formats,
                'subtitles': subtitles,
                'thumbnail': episode.get('thumbnail'),
                'series': series_title,
                'series_id': traverse_obj(episode, ('contentMeta', 'displayMeta', 'seriesID')),
                'season_id': traverse_obj(episode, ('contentMeta', 'displayMeta', 'seasonID')),
                'season_number': traverse_obj(
                    episode, ('contentMeta', 'displayMeta', 'seasonNum'), expected_type=int_or_none),
                'episode_number': traverse_obj(
                    episode, ('contentMeta', 'displayMeta', 'episodeNum'), expected_type=int_or_none),
            }