Repository: yt-dlp/yt-dlp
File: youtube_dlc/extractor/zee5.py (Python)

Code before:
        'params': {
            'format': 'bv',
        },
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        # webpage = self._download_webpage(url, video_id)

        # TODO more code goes here, for example ...
        token_request = requests.get(token_url, headers=headers).json()
        x_access_token = requests.get(platform_token).json()["token"]
        headers["X-Access-Token"] = x_access_token
        json_data = requests.get(search_api_endpoint + video_id, headers=headers,
                                 params={"translation": "en", "country": "IN"}).json()
        partial_m3u8_url = (json_data["hls"][0].replace("drm", "hls") + token_request["video_token"])
        title = json_data['title']
        m3u8_url = stream_baseurl + partial_m3u8_url
        description = json_data['description']
        thumbnail = json_data['image_url']
        formats = self._extract_m3u8_formats(m3u8_url=m3u8_url, video_id=video_id)
        if json_data['asset_subtype'] == 'episode':
            show_title = json_data['tvshow_details']['title']
            season_title = json_data['season_details']['title']
            season_index = json_data['season_details']['index']
            ep_index = json_data['index']
        elif json_data['asset_subtype'] == 'movie':
            show_title = 'None'
            season_title = 'None'
            season_index = 'None'
            ep_index = 'None'
        return {
            'id': video_id,
            'title': title,
            'formats': formats,
            'description': description,
            'thumbnail': thumbnail,
            'show_title': show_title,
            'season_title': season_title,
            'season_index': season_index,
            'ep_index': ep_index,

            # TODO more properties (see youtube_dl/extractor/common.py)
        }


Review comment (suggestion):
Use `try_get` or `.get` for key access. We don't want error in case the key doesn't exist

Code after:
        'url': 'https://zee5.com/tvshows/details/krishna-balram/0-6-1871/episode-1-the-test-of-bramha/0-1-233402',
        'info_dict': {
            "id": "0-1-233402",
            'ext': 'm3u8',
            "display_id": "episode-1-the-test-of-bramha",
            "title": "Episode 1 - The Test Of Bramha",
            "duration": 1336,
            "average_rating": 4,
            "description": str,
            "alt_title": "Episode 1 - The Test Of Bramha",
            "uploader": "Green Gold",
            "release_date": "20090101",
            "upload_date": "20090101",
            "timestamp": 1230768000,
            "thumbnail": "https://akamaividz.zee5.com/resources/0-1-233402/list/270x152/01233402_list.jpg",
            "series": "Krishna Balram",
            "season_number": 1,
            "episode_number": 1,
            "tags": list,
        },
        'params': {
            'format': 'bv',
        },
    }]

    def _real_extract(self, url):
        video_id, display_id = re.match(self._VALID_URL, url).group('id', 'display_id')
        access_token_request = self._download_json(
            'https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app',
            video_id, note="Downloading access token")
        token_request = self._download_json(
            'https://useraction.zee5.com/tokennd',
            video_id, note="Downloading video token")
        json_data = self._download_json(
            'https://gwapi.zee5.com/content/details/{}?translation=en&country=IN'.format(video_id),
            video_id, headers={'X-Access-Token': access_token_request['token']})
        m3u8_url = try_get(
            json_data,
            (lambda x: x['hls'][0], lambda x: x['video_details']['hls_url']),
            str)
        formats = self._extract_m3u8_formats(
            'https://zee5vodnd.akamaized.net' + m3u8_url.replace('/drm1/', '/hls1/') + token_request['video_token'],
            video_id, fatal=False)
        mpd_url = try_get(
            json_data,
            (lambda x: x['video'][0], lambda x: x['video_details']['url']),
            str)
        formats += self._extract_mpd_formats(
            'https://zee5vodnd.akamaized.net' + mpd_url + token_request['video_token'],
            video_id, fatal=False)