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

Code before:
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor

import requests

token_url = "https://useraction.zee5.com/tokennd"
search_api_endpoint = "https://gwapi.zee5.com/content/details/"
platform_token = "https://useraction.zee5.com/token/platform_tokens.php?platform_name=web_app"
stream_baseurl = "https://zee5vodnd.akamaized.net"

headers = {
    "User-Agent": "Mozilla/5.0 (Linux; Android 10; SM-J400F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36",
    "Referer": "https://www.zee5.com",
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "en-US,en;q=0.9",
    "Origin": "https://www.zee5.com",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
}


class Zee5IE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?zee5\.com/.*/(?P<id>.*)'
    _TEST = {
        'url': 'https://www.zee5.com/movies/details/krishna-the-birth/0-0-63098',
        # 'md5': 'cd5abd10fab020dbb633cb8e94df0e12',
        'info_dict': {
            'id': '0-0-63098',
            'ext': 'm3u8',
            'title': 'Krishna - The Birth',
            'thumbnail': 'https://akamaividz.zee5.com/resources/0-0-63098/list/270x152/0063098_list_80888170.jpg',
            'description': str,
            'show': str,
            'season_title': str,
            'season_index': str,
            'ep_index': str,
        },
        'params': {
            'format': 'bv',
        },
    }

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

Review comment (refactor):
use only the headers that actually need to be set (probably only referer and origin are needed - maybe not even that)

Also, move this inside the class

Code after:
# coding: utf-8
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..utils import (
    int_or_none,
    parse_age_limit,
    str_or_none,
    try_get,
    unified_strdate,
    unified_timestamp,
    url_or_none,
)


class Zee5IE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?zee5\.com/[^#?]*/(?P<display_id>[-\w]+)/(?P<id>[-\d]+)'
    _TESTS = [{
        'url': 'https://www.zee5.com/movies/details/krishna-the-birth/0-0-63098',
        'info_dict': {
            "id": "0-0-63098",
            "ext": "m3u8",
            "display_id": "krishna-the-birth",
            "title": "Krishna - The Birth",
            "duration": 4368,
            "average_rating": 4,
            "description": str,
            "alt_title": "Krishna - The Birth",
            "uploader": "Zee Entertainment Enterprises Ltd",
            "release_date": "20060101",
            "upload_date": "20060101",
            "timestamp": 1136073600,
            "thumbnail": "https://akamaividz.zee5.com/resources/0-0-63098/list/270x152/0063098_list_80888170.jpg",
            "tags": list
        },
        'params': {
            'format': 'bv',
        },
    }, {
        '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,