]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/mxplayer.py
[youtube] Prefer UTC upload date for videos (#2223)
[yt-dlp.git] / yt_dlp / extractor / mxplayer.py
CommitLineData
097b056c
AC
1from __future__ import unicode_literals
2
097b056c
AC
3
4from .common import InfoExtractor
87c3d062 5from ..compat import compat_str
1722099d 6from ..utils import try_get
097b056c
AC
7
8
097b056c 9class MxplayerIE(InfoExtractor):
1722099d 10 _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/(?P<type>movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)'
1caaf92d 11 _TESTS = [{
1722099d
AG
12 'url': 'https://www.mxplayer.in/show/watch-my-girlfriend-is-an-alien-hindi-dubbed/season-1/episode-1-online-9d2013d31d5835bb8400e3b3c5e7bb72',
13 'info_dict': {
14 'id': '9d2013d31d5835bb8400e3b3c5e7bb72',
15 'ext': 'mp4',
16 'title': 'Episode 1',
17 'description': 'md5:62ed43eb9fec5efde5cf3bd1040b7670',
18 'season_number': 1,
19 'episode_number': 1,
20 'duration': 2451,
21 'season': 'Season 1',
22 'series': 'My Girlfriend Is An Alien (Hindi Dubbed)',
23 'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/9d2013d31d5835bb8400e3b3c5e7bb72/en/16x9/320x180/9562f5f8df42cad09c9a9c4e69eb1567_1920x1080.webp',
24 'episode': 'Episode 1'
25 },
26 'params': {
27 'format': 'bv',
28 'skip_download': True,
29 },
30 }, {
097b056c
AC
31 'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true',
32 'info_dict': {
33 'id': 'b9fa28df3bfb8758874735bbd7d2655a',
34 'ext': 'mp4',
1caaf92d 35 'title': 'Knock Knock (Hindi Dubbed)',
1722099d
AG
36 'description': 'md5:b195ba93ff1987309cfa58e2839d2a5b',
37 'season_number': 0,
38 'episode_number': 0,
39 'duration': 5970,
40 'season': 'Season 0',
41 'series': None,
42 'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/b9fa28df3bfb8758874735bbd7d2655a/en/16x9/320x180/test_pic1588676032011.webp',
43 'episode': 'Episode 0'
097b056c
AC
44 },
45 'params': {
1722099d 46 'format': 'bv',
097b056c 47 'skip_download': True,
1722099d 48 },
1caaf92d
A
49 }, {
50 'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c',
51 'info_dict': {
52 'id': '45055d5bcff169ad48f2ad7552a83d6c',
1722099d 53 'ext': 'mp4',
1caaf92d
A
54 'title': 'The infamous taxi gang of Meerut',
55 'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28',
1722099d
AG
56 'season_number': 1,
57 'episode_number': 1,
58 'duration': 2332,
1caaf92d 59 'season': 'Season 1',
1722099d
AG
60 'series': 'Shaitaan',
61 'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/45055d5bcff169ad48f2ad7552a83d6c/en/16x9/320x180/voot_8e7d5f8d8183340869279c732c1e3a43.webp',
62 'episode': 'Episode 1'
1caaf92d
A
63 },
64 'params': {
1722099d 65 'format': 'best',
1caaf92d 66 'skip_download': True,
1722099d 67 },
1caaf92d
A
68 }, {
69 'url': 'https://www.mxplayer.in/show/watch-aashram/chapter-1/duh-swapna-online-d445579792b0135598ba1bc9088a84cb',
70 'info_dict': {
71 'id': 'd445579792b0135598ba1bc9088a84cb',
72 'ext': 'mp4',
73 'title': 'Duh Swapna',
74 'description': 'md5:35ff39c4bdac403c53be1e16a04192d8',
1722099d
AG
75 'season_number': 1,
76 'episode_number': 3,
77 'duration': 2568,
1caaf92d 78 'season': 'Chapter 1',
1722099d
AG
79 'series': 'Aashram',
80 'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/d445579792b0135598ba1bc9088a84cb/en/4x3/1600x1200/test_pic1624819307993.webp',
81 'episode': 'Episode 3'
1caaf92d 82 },
1caaf92d 83 'params': {
1722099d 84 'format': 'bv',
1caaf92d 85 'skip_download': True,
1722099d
AG
86 },
87 }, {
88 'url': 'https://www.mxplayer.in/show/watch-dangerous/season-1/chapter-1-online-5a351b4f9fb69436f6bd6ae3a1a75292',
89 'info_dict': {
90 'id': '5a351b4f9fb69436f6bd6ae3a1a75292',
91 'ext': 'mp4',
92 'title': 'Chapter 1',
93 'description': 'md5:233886b8598bc91648ac098abe1d288f',
94 'season_number': 1,
95 'episode_number': 1,
96 'duration': 1305,
97 'season': 'Season 1',
98 'series': 'Dangerous',
99 'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/5a351b4f9fb69436f6bd6ae3a1a75292/en/4x3/1600x1200/test_pic1624706302350.webp',
100 'episode': 'Episode 1'
101 },
102 'params': {
103 'format': 'bv',
104 'skip_download': True,
105 },
106 }, {
107 'url': 'https://www.mxplayer.in/movie/watch-the-attacks-of-2611-movie-online-0452f0d80226c398d63ce7e3ea40fa2d',
108 'info_dict': {
109 'id': '0452f0d80226c398d63ce7e3ea40fa2d',
110 'ext': 'mp4',
111 'title': 'The Attacks of 26/11',
112 'description': 'md5:689bacd29e97b3f31eaf519eb14127e5',
113 'season_number': 0,
114 'episode_number': 0,
115 'duration': 6085,
116 'season': 'Season 0',
117 'series': None,
118 'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/0452f0d80226c398d63ce7e3ea40fa2d/en/16x9/320x180/00c8955dab5e5d340dbde643f9b1f6fd_1920x1080.webp',
119 'episode': 'Episode 0'
120 },
121 'params': {
122 'format': 'best',
123 'skip_download': True,
124 },
1caaf92d 125 }]
097b056c 126
097b056c 127 def _real_extract(self, url):
1722099d
AG
128 type, display_id, video_id = self._match_valid_url(url).groups()
129 type = 'movie_film' if type == 'movie' else 'tvshow_episode'
130 API_URL = 'https://androidapi.mxplay.com/v1/detail/'
131 headers = {
132 'X-Av-Code': '23',
133 'X-Country': 'IN',
134 'X-Platform': 'android',
135 'X-App-Version': '1370001318',
136 'X-Resolution': '3840x2160',
137 }
138 data_json = self._download_json(f'{API_URL}{type}/{video_id}', display_id, headers=headers)['profile']
097b056c 139
1722099d
AG
140 season, series = None, None
141 for dct in data_json.get('levelInfos', []):
142 if dct.get('type') == 'tvshow_season':
143 season = dct.get('name')
144 elif dct.get('type') == 'tvshow_show':
145 series = dct.get('name')
1caaf92d 146 thumbnails = []
1722099d 147 for thumb in data_json.get('poster', []):
1caaf92d 148 thumbnails.append({
1722099d
AG
149 'url': thumb.get('url'),
150 'width': thumb.get('width'),
151 'height': thumb.get('height'),
1caaf92d 152 })
097b056c
AC
153
154 formats = []
1722099d
AG
155 subtitles = {}
156 for dct in data_json.get('playInfo', []):
157 if dct.get('extension') == 'mpd':
158 frmt, subs = self._extract_mpd_formats_and_subtitles(dct.get('playUrl'), display_id, fatal=False)
159 formats.extend(frmt)
160 subtitles = self._merge_subtitles(subtitles, subs)
161 elif dct.get('extension') == 'm3u8':
162 frmt, subs = self._extract_m3u8_formats_and_subtitles(dct.get('playUrl'), display_id, fatal=False)
163 formats.extend(frmt)
164 subtitles = self._merge_subtitles(subtitles, subs)
097b056c 165 self._sort_formats(formats)
1caaf92d 166 return {
097b056c 167 'id': video_id,
87c3d062 168 'display_id': display_id,
1722099d
AG
169 'title': data_json.get('name') or display_id,
170 'description': data_json.get('description'),
171 'season_number': data_json.get('seasonNum'),
172 'episode_number': data_json.get('episodeNum'),
173 'duration': data_json.get('duration'),
174 'season': season,
175 'series': series,
1caaf92d 176 'thumbnails': thumbnails,
1722099d
AG
177 'formats': formats,
178 'subtitles': subtitles,
097b056c 179 }
87c3d062
A
180
181
182class MxplayerShowIE(InfoExtractor):
73f035e1 183 _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/show/(?P<display_id>[-\w]+)-(?P<id>\w+)/?(?:$|[#?])'
87c3d062
A
184 _TESTS = [{
185 'url': 'https://www.mxplayer.in/show/watch-chakravartin-ashoka-samrat-series-online-a8f44e3cc0814b5601d17772cedf5417',
186 'playlist_mincount': 440,
187 'info_dict': {
188 'id': 'a8f44e3cc0814b5601d17772cedf5417',
189 'title': 'Watch Chakravartin Ashoka Samrat Series Online',
190 }
191 }]
192
193 _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"
194 _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&{}"
195
196 def _entries(self, show_id):
197 show_json = self._download_json(
198 self._API_SHOW_URL.format(show_id),
199 video_id=show_id, headers={'Referer': 'https://mxplayer.in'})
200 page_num = 0
201 for season in show_json.get('items') or []:
202 season_id = try_get(season, lambda x: x['id'], compat_str)
203 next_url = ''
204 while next_url is not None:
205 page_num += 1
206 season_json = self._download_json(
207 self._API_EPISODES_URL.format(season_id, next_url),
208 video_id=season_id,
209 headers={'Referer': 'https://mxplayer.in'},
210 note='Downloading JSON metadata page %d' % page_num)
211 for episode in season_json.get('items') or []:
212 video_url = episode['webUrl']
213 yield self.url_result(
214 'https://mxplayer.in%s' % video_url,
215 ie=MxplayerIE.ie_key(), video_id=video_url.split('-')[-1])
216 next_url = season_json.get('next')
217
218 def _real_extract(self, url):
5ad28e7f 219 display_id, show_id = self._match_valid_url(url).groups()
87c3d062
A
220 return self.playlist_result(
221 self._entries(show_id), playlist_id=show_id,
222 playlist_title=display_id.replace('-', ' ').title())