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