]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/mxplayer.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / mxplayer.py
CommitLineData
097b056c 1from .common import InfoExtractor
87c3d062 2from ..compat import compat_str
576faf00
I
3from ..utils import (
4 int_or_none,
5 traverse_obj,
6 try_get,
9b383177 7 urljoin,
576faf00 8)
097b056c
AC
9
10
097b056c 11class MxplayerIE(InfoExtractor):
1722099d 12 _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/(?P<type>movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)'
1caaf92d 13 _TESTS = [{
1722099d
AG
14 'url': 'https://www.mxplayer.in/show/watch-my-girlfriend-is-an-alien-hindi-dubbed/season-1/episode-1-online-9d2013d31d5835bb8400e3b3c5e7bb72',
15 'info_dict': {
16 'id': '9d2013d31d5835bb8400e3b3c5e7bb72',
576faf00 17 'display_id': 'episode-1-online',
1722099d
AG
18 'ext': 'mp4',
19 'title': 'Episode 1',
20 'description': 'md5:62ed43eb9fec5efde5cf3bd1040b7670',
21 'season_number': 1,
22 'episode_number': 1,
23 'duration': 2451,
24 'season': 'Season 1',
25 'series': 'My Girlfriend Is An Alien (Hindi Dubbed)',
1722099d
AG
26 'episode': 'Episode 1'
27 },
28 'params': {
29 'format': 'bv',
30 'skip_download': True,
31 },
32 }, {
097b056c
AC
33 'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true',
34 'info_dict': {
35 'id': 'b9fa28df3bfb8758874735bbd7d2655a',
576faf00 36 'display_id': 'episode-1-online',
097b056c 37 'ext': 'mp4',
1caaf92d 38 'title': 'Knock Knock (Hindi Dubbed)',
576faf00 39 'description': 'md5:4160f2dfc3b87c524261366f6b736329',
1722099d 40 'duration': 5970,
097b056c
AC
41 },
42 'params': {
1722099d 43 'format': 'bv',
097b056c 44 'skip_download': True,
1722099d 45 },
576faf00 46 'skip': 'No longer available',
1caaf92d
A
47 }, {
48 'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c',
49 'info_dict': {
50 'id': '45055d5bcff169ad48f2ad7552a83d6c',
1722099d 51 'ext': 'mp4',
1caaf92d
A
52 'title': 'The infamous taxi gang of Meerut',
53 'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28',
1722099d
AG
54 'season_number': 1,
55 'episode_number': 1,
56 'duration': 2332,
1caaf92d 57 'season': 'Season 1',
1722099d 58 'series': 'Shaitaan',
1722099d 59 'episode': 'Episode 1'
1caaf92d
A
60 },
61 'params': {
1722099d 62 'format': 'best',
1caaf92d 63 'skip_download': True,
1722099d 64 },
576faf00 65 'skip': 'No longer available.'
1caaf92d
A
66 }, {
67 'url': 'https://www.mxplayer.in/show/watch-aashram/chapter-1/duh-swapna-online-d445579792b0135598ba1bc9088a84cb',
68 'info_dict': {
69 'id': 'd445579792b0135598ba1bc9088a84cb',
576faf00 70 'display_id': 'duh-swapna-online',
1caaf92d
A
71 'ext': 'mp4',
72 'title': 'Duh Swapna',
73 'description': 'md5:35ff39c4bdac403c53be1e16a04192d8',
1722099d
AG
74 'season_number': 1,
75 'episode_number': 3,
76 'duration': 2568,
576faf00 77 'season': 'Season 1',
1722099d 78 'series': 'Aashram',
1722099d 79 'episode': 'Episode 3'
1caaf92d 80 },
1caaf92d 81 'params': {
1722099d 82 'format': 'bv',
1caaf92d 83 'skip_download': True,
1722099d
AG
84 },
85 }, {
86 'url': 'https://www.mxplayer.in/show/watch-dangerous/season-1/chapter-1-online-5a351b4f9fb69436f6bd6ae3a1a75292',
87 'info_dict': {
88 'id': '5a351b4f9fb69436f6bd6ae3a1a75292',
576faf00 89 'display_id': 'chapter-1-online',
1722099d
AG
90 'ext': 'mp4',
91 'title': 'Chapter 1',
92 'description': 'md5:233886b8598bc91648ac098abe1d288f',
93 'season_number': 1,
94 'episode_number': 1,
95 'duration': 1305,
96 'season': 'Season 1',
97 'series': 'Dangerous',
1722099d
AG
98 'episode': 'Episode 1'
99 },
100 'params': {
101 'format': 'bv',
102 'skip_download': True,
103 },
104 }, {
105 'url': 'https://www.mxplayer.in/movie/watch-the-attacks-of-2611-movie-online-0452f0d80226c398d63ce7e3ea40fa2d',
106 'info_dict': {
107 'id': '0452f0d80226c398d63ce7e3ea40fa2d',
108 'ext': 'mp4',
109 'title': 'The Attacks of 26/11',
110 'description': 'md5:689bacd29e97b3f31eaf519eb14127e5',
1722099d 111 'duration': 6085,
1722099d
AG
112 },
113 'params': {
114 'format': 'best',
115 'skip_download': True,
116 },
576faf00
I
117 'skip': 'No longer available. Cannot be played on browser'
118 }, {
119 'url': 'https://www.mxplayer.in/movie/watch-kitne-door-kitne-paas-movie-online-a9e9c76c566205955f70d8b2cb88a6a2',
120 'info_dict': {
121 'id': 'a9e9c76c566205955f70d8b2cb88a6a2',
122 'display_id': 'watch-kitne-door-kitne-paas-movie-online',
123 'title': 'Kitne Door Kitne Paas',
124 'duration': 8458,
125 'ext': 'mp4',
126 'description': 'md5:fb825f3c542513088024dcafef0921b4',
127 },
128 'params': {
129 'format': 'bv',
130 'skip_download': True,
131 },
132 }, {
133 'url': 'https://www.mxplayer.in/show/watch-ek-thi-begum-hindi/season-2/game-of-power-online-5e5305c28f1409847cdc4520b6ad77cf',
134 'info_dict': {
135 'id': '5e5305c28f1409847cdc4520b6ad77cf',
136 'display_id': 'game-of-power-online',
137 'title': 'Game Of Power',
138 'duration': 1845,
139 'ext': 'mp4',
140 'description': 'md5:1d0948d2a5312d7013792d53542407f9',
141 'series': 'Ek Thi Begum (Hindi)',
142 'season': 'Season 2',
143 'season_number': 2,
144 'episode': 'Episode 2',
145 'episode_number': 2,
146 },
147 'params': {
148 'format': 'bv',
149 'skip_download': True,
150 },
9b383177 151 }, {
152 'url': 'https://www.mxplayer.in/movie/watch-deewane-huye-paagal-movie-online-4f9175c40a11c3994182a65afdd37ec6?watch=true',
153 'info_dict': {
154 'id': '4f9175c40a11c3994182a65afdd37ec6',
155 'display_id': 'watch-deewane-huye-paagal-movie-online',
156 'title': 'Deewane Huye Paagal',
157 'duration': 9037,
158 'ext': 'mp4',
159 'description': 'md5:d17bd5c651016c4ed2e6f8a4ace15534',
160 },
161 'params': {'skip_download': 'm3u8'},
1caaf92d 162 }]
097b056c 163
097b056c 164 def _real_extract(self, url):
576faf00
I
165 video_type, display_id, video_id = self._match_valid_url(url).group('type', 'display_id', 'id')
166 if 'show' in video_type:
167 video_type = 'episode'
097b056c 168
576faf00
I
169 data_json = self._download_json(
170 f'https://api.mxplay.com/v1/web/detail/video?type={video_type}&id={video_id}', display_id)
097b056c 171
9b383177 172 formats, subtitles = [], {}
173 m3u8_url = urljoin('https://llvod.mxplay.com/', traverse_obj(
174 data_json, ('stream', (('thirdParty', 'hlsUrl'), ('hls', 'high'))), get_all=False))
175 if m3u8_url:
176 formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, display_id, 'mp4', fatal=False)
177 mpd_url = urljoin('https://llvod.mxplay.com/', traverse_obj(
178 data_json, ('stream', (('thirdParty', 'dashUrl'), ('dash', 'high'))), get_all=False))
179 if mpd_url:
180 fmts, subs = self._extract_mpd_formats_and_subtitles(mpd_url, display_id, fatal=False)
181 formats.extend(fmts)
182 self._merge_subtitles(subs, target=subtitles)
576faf00
I
183
184 season = traverse_obj(data_json, ('container', 'title'))
1caaf92d 185 return {
097b056c 186 'id': video_id,
576faf00
I
187 'title': data_json.get('title'),
188 'formats': formats,
9b383177 189 'subtitles': subtitles,
87c3d062 190 'display_id': display_id,
1722099d 191 'duration': data_json.get('duration'),
576faf00
I
192 'series': traverse_obj(data_json, ('container', 'container', 'title')),
193 'description': data_json.get('description'),
1722099d 194 'season': season,
576faf00
I
195 'season_number': int_or_none(
196 self._search_regex(r'Season (\d+)', season, 'Season Number', default=None)),
197 'episode_number': data_json.get('sequence') or None,
097b056c 198 }
87c3d062
A
199
200
201class MxplayerShowIE(InfoExtractor):
73f035e1 202 _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/show/(?P<display_id>[-\w]+)-(?P<id>\w+)/?(?:$|[#?])'
87c3d062
A
203 _TESTS = [{
204 'url': 'https://www.mxplayer.in/show/watch-chakravartin-ashoka-samrat-series-online-a8f44e3cc0814b5601d17772cedf5417',
205 'playlist_mincount': 440,
206 'info_dict': {
207 'id': 'a8f44e3cc0814b5601d17772cedf5417',
208 'title': 'Watch Chakravartin Ashoka Samrat Series Online',
209 }
210 }]
211
212 _API_SHOW_URL = "https://api.mxplay.com/v1/web/detail/tab/tvshowseasons?type=tv_show&id={}&device-density=2&platform=com.mxplay.desktop&content-languages=hi,en"
213 _API_EPISODES_URL = "https://api.mxplay.com/v1/web/detail/tab/tvshowepisodes?type=season&id={}&device-density=1&platform=com.mxplay.desktop&content-languages=hi,en&{}"
214
215 def _entries(self, show_id):
216 show_json = self._download_json(
217 self._API_SHOW_URL.format(show_id),
218 video_id=show_id, headers={'Referer': 'https://mxplayer.in'})
219 page_num = 0
220 for season in show_json.get('items') or []:
221 season_id = try_get(season, lambda x: x['id'], compat_str)
222 next_url = ''
223 while next_url is not None:
224 page_num += 1
225 season_json = self._download_json(
226 self._API_EPISODES_URL.format(season_id, next_url),
227 video_id=season_id,
228 headers={'Referer': 'https://mxplayer.in'},
229 note='Downloading JSON metadata page %d' % page_num)
230 for episode in season_json.get('items') or []:
231 video_url = episode['webUrl']
232 yield self.url_result(
233 'https://mxplayer.in%s' % video_url,
234 ie=MxplayerIE.ie_key(), video_id=video_url.split('-')[-1])
235 next_url = season_json.get('next')
236
237 def _real_extract(self, url):
5ad28e7f 238 display_id, show_id = self._match_valid_url(url).groups()
87c3d062
A
239 return self.playlist_result(
240 self._entries(show_id), playlist_id=show_id,
241 playlist_title=display_id.replace('-', ' ').title())