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

Code before:
            'url': 'https://weyyak.com/en/movie/233255/8-Seconds',
            'md5': 'fe740ae0f63e4d1c8a7fc147a410c564',
            'info_dict': {
                'id': '233255',
                'ext': 'm3u8',
                'title': '8 Seconds',
                'duration': 6490,
            },
        },
    ]

    def _real_extract(self, url):
        _id, _lang, _type = self._match_valid_url(url).group('id', 'lang', 'type')

        path = 'episode/' if _type == 'episode' else 'contents/moviedetails?contentkey='
        video_info = self._download_json(
            f'https://msapifo-prod-me.weyyak.z5.com/v1/{_lang}/{path}{_id}', _id,
            headers={'Content-Type': 'application/json'})
        video_id = video_info['data']['video_id']

        video_details = self._download_json(
            f'https://api-weyyak.akamaized.net/get_info/{video_id}', _id,
            'Extracting video details', headers={'Content-Type': 'application/json'})
        video_url = video_details.get('url_video')
        video_url = re.sub(r'index\.m3u8', 'master-v1a1.m3u8', video_url)
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_url, _id)

        return {
            'id': _id,
            'title': traverse_obj(video_info, ('data', 'title')),
            'url': video_url,
            'duration': video_details.get('duration'),
            'formats': formats,
            'subtitles': subtitles,
        }


Review comment (refactor):
 - if we are not returning the `video_id` var in the info_dict, it's better to not use a var at all
 - if there is only 1 video/format URL, it can be fatal
 - do not do `re.sub`, we want to extract the master m3u8, not a single media playlist
```suggestion
        video_details = self._download_json(
            f'https://api-weyyak.akamaized.net/get_info/{video_info["data"]["video_id"]}',
            _id, 'Extracting video details')
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_details['url_video'], _id)
```

Code after:
                'title': 'Ribat Al Hob',
                'duration': 2771,
                'alt_title': 'رباط الحب',
                'season': 'Season 1',
                'season_number': 1,
                'episode': 'Episode 49',
                'episode_number': 49,
                'timestamp': 1485907200,
                'upload_date': '20170201',
                'thumbnail': r're:^https://content\.weyyak\.com/.+/poster-image',
                'categories': ['Drama', 'Thrillers', 'Romance'],
                'tags': 'count:8',
            },
        },
        {
            'url': 'https://weyyak.com/en/movie/233255/8-Seconds',
            'md5': 'fe740ae0f63e4d1c8a7fc147a410c564',
            'info_dict': {
                'id': '233255',
                'ext': 'mp4',
                'title': '8 Seconds',
                'duration': 6490,
                'alt_title': '8 ثواني',
                'description': 'md5:45b83a155c30b49950624c7e99600b9d',
                'age_limit': 15,
                'release_year': 2015,
                'timestamp': 1683106031,
                'upload_date': '20230503',
                'thumbnail': r're:^https://content\.weyyak\.com/.+/poster-image',
                'categories': ['Drama', 'Social'],
                'cast': ['Ceylin Adiyaman', 'Esra Inal'],
            },
        },
    ]

    def _real_extract(self, url):
        video_id, lang, type_ = self._match_valid_url(url).group('id', 'lang', 'type')

        path = 'episode/' if type_ == 'episode' else 'contents/moviedetails?contentkey='
        data = self._download_json(
            f'https://msapifo-prod-me.weyyak.z5.com/v1/{lang}/{path}{video_id}', video_id)['data']
        m3u8_url = self._download_json(
            f'https://api-weyyak.akamaized.net/get_info/{data["video_id"]}',
            video_id, 'Extracting video details')['url_video']
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(data, {