Repository: yt-dlp/yt-dlp

Issue:
Mx Player problem with some URLs
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.10.04** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [ ] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

India

### Provide a description that is worded well enough to be understood

Not working with some movie URLs like:
https://www.mxplayer.in/movie/watch-bhagam-bhag-movie-online-b50750f485274cad5bd81e7ee1a021ef?watch=true

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['-vU', 'https://www.mxplayer.in/movie/watch-bhagam-bhag-movie-online-b50750f485274cad5bd81e7ee1a021ef?watch=true']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.10.04 [4e0511f] (win32_exe)
[debug] Python 3.8.10 (CPython 64bit) - Windows-10-10.0.19044-SP0
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.1.2-essentials_build-www.gyan.dev (setts)
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.09.24, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[debug] Proxy map: {}
[debug] Loaded 1690 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2022.10.04, Current version: 2022.10.04
yt-dlp is up to date (2022.10.04)
[debug] [Mxplayer] Extracting URL: https://www.mxplayer.in/movie/watch-bhagam-bhag-movie-online-b50750f485274cad5bd81e7ee1a021ef?watch=true
[Mxplayer] watch-bhagam-bhag-movie-online: Downloading JSON metadata
ERROR: b50750f485274cad5bd81e7ee1a021ef: An extractor error has occurred. (caused by KeyError('mpd')); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "yt_dlp\extractor\common.py", line 672, in extract
  File "yt_dlp\extractor\mxplayer.py", line 162, in _real_extract
KeyError: 'mpd'
```



Discussion:
any other URLs that behave the same?

(for testing modification)
https://www.mxplayer.in/movie/watch-deewane-huye-paagal-movie-online-4f9175c40a11c3994182a65afdd37ec6?watch=true
This is another such URL.

Make sure that modification does not break currently working URLs.

Resolving patch:
diff --git a/yt_dlp/extractor/mxplayer.py b/yt_dlp/extractor/mxplayer.py
--- a/yt_dlp/extractor/mxplayer.py
+++ b/yt_dlp/extractor/mxplayer.py
@@ -4,6 +4,7 @@
     int_or_none,
     traverse_obj,
     try_get,
+    urljoin,
 )
 
 
@@ -147,6 +148,17 @@ class MxplayerIE(InfoExtractor):
             'format': 'bv',
             'skip_download': True,
         },
+    }, {
+        'url': 'https://www.mxplayer.in/movie/watch-deewane-huye-paagal-movie-online-4f9175c40a11c3994182a65afdd37ec6?watch=true',
+        'info_dict': {
+            'id': '4f9175c40a11c3994182a65afdd37ec6',
+            'display_id': 'watch-deewane-huye-paagal-movie-online',
+            'title': 'Deewane Huye Paagal',
+            'duration': 9037,
+            'ext': 'mp4',
+            'description': 'md5:d17bd5c651016c4ed2e6f8a4ace15534',
+        },
+        'params': {'skip_download': 'm3u8'},
     }]
 
     def _real_extract(self, url):
@@ -157,21 +169,24 @@ def _real_extract(self, url):
         data_json = self._download_json(
             f'https://api.mxplay.com/v1/web/detail/video?type={video_type}&id={video_id}', display_id)
 
-        streams = traverse_obj(data_json, ('stream', {'m3u8': ('hls', 'high'), 'mpd': ('dash', 'high')}))
-        formats, dash_subs = self._extract_mpd_formats_and_subtitles(
-            f'https://llvod.mxplay.com/{streams["mpd"]}', display_id, fatal=False)
-        hls_frmts, hls_subs = self._extract_m3u8_formats_and_subtitles(
-            f'https://llvod.mxplay.com/{streams["m3u8"]}', display_id, fatal=False)
-
-        formats.extend(hls_frmts)
-        self._sort_formats(formats)
+        formats, subtitles = [], {}
+        m3u8_url = urljoin('https://llvod.mxplay.com/', traverse_obj(
+            data_json, ('stream', (('thirdParty', 'hlsUrl'), ('hls', 'high'))), get_all=False))
+        if m3u8_url:
+            formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, display_id, 'mp4', fatal=False)
+        mpd_url = urljoin('https://llvod.mxplay.com/', traverse_obj(
+            data_json, ('stream', (('thirdParty', 'dashUrl'), ('dash', 'high'))), get_all=False))
+        if mpd_url:
+            fmts, subs = self._extract_mpd_formats_and_subtitles(mpd_url, display_id, fatal=False)
+            formats.extend(fmts)
+            self._merge_subtitles(subs, target=subtitles)
 
         season = traverse_obj(data_json, ('container', 'title'))
         return {
             'id': video_id,
             'title': data_json.get('title'),
             'formats': formats,
-            'subtitles': self._merge_subtitles(dash_subs, hls_subs),
+            'subtitles': subtitles,
             'display_id': display_id,
             'duration': data_json.get('duration'),
             'series': traverse_obj(data_json, ('container', 'container', 'title')),


Test patch: