]>
Commit | Line | Data |
---|---|---|
1 | from __future__ import unicode_literals | |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..compat import compat_str | |
7 | from ..utils import ( | |
8 | ExtractorError, | |
9 | js_to_json, | |
10 | qualities, | |
11 | try_get, | |
12 | url_or_none, | |
13 | urljoin, | |
14 | ) | |
15 | ||
16 | ||
17 | class MxplayerIE(InfoExtractor): | |
18 | _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/(?:movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)' | |
19 | _TESTS = [{ | |
20 | 'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true', | |
21 | 'info_dict': { | |
22 | 'id': 'b9fa28df3bfb8758874735bbd7d2655a', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'Knock Knock (Hindi Dubbed)', | |
25 | 'description': 'md5:b195ba93ff1987309cfa58e2839d2a5b' | |
26 | }, | |
27 | 'params': { | |
28 | 'skip_download': True, | |
29 | 'format': 'bestvideo' | |
30 | } | |
31 | }, { | |
32 | 'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c', | |
33 | 'info_dict': { | |
34 | 'id': '45055d5bcff169ad48f2ad7552a83d6c', | |
35 | 'ext': 'm3u8', | |
36 | 'title': 'The infamous taxi gang of Meerut', | |
37 | 'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28', | |
38 | 'season': 'Season 1', | |
39 | 'series': 'Shaitaan' | |
40 | }, | |
41 | 'params': { | |
42 | 'skip_download': True, | |
43 | } | |
44 | }, { | |
45 | 'url': 'https://www.mxplayer.in/show/watch-aashram/chapter-1/duh-swapna-online-d445579792b0135598ba1bc9088a84cb', | |
46 | 'info_dict': { | |
47 | 'id': 'd445579792b0135598ba1bc9088a84cb', | |
48 | 'ext': 'mp4', | |
49 | 'title': 'Duh Swapna', | |
50 | 'description': 'md5:35ff39c4bdac403c53be1e16a04192d8', | |
51 | 'season': 'Chapter 1', | |
52 | 'series': 'Aashram' | |
53 | }, | |
54 | 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'], | |
55 | 'params': { | |
56 | 'skip_download': True, | |
57 | 'format': 'bestvideo' | |
58 | } | |
59 | }] | |
60 | ||
61 | def _get_stream_urls(self, video_dict): | |
62 | stream_provider_dict = try_get( | |
63 | video_dict, | |
64 | lambda x: x['stream'][x['stream']['provider']]) | |
65 | if not stream_provider_dict: | |
66 | raise ExtractorError('No stream provider found', expected=True) | |
67 | ||
68 | for stream_name, stream in stream_provider_dict.items(): | |
69 | if stream_name in ('hls', 'dash', 'hlsUrl', 'dashUrl'): | |
70 | stream_type = stream_name.replace('Url', '') | |
71 | if isinstance(stream, dict): | |
72 | for quality, stream_url in stream.items(): | |
73 | if stream_url: | |
74 | yield stream_type, quality, stream_url | |
75 | else: | |
76 | yield stream_type, 'base', stream | |
77 | ||
78 | def _real_extract(self, url): | |
79 | display_id, video_id = re.match(self._VALID_URL, url).groups() | |
80 | webpage = self._download_webpage(url, video_id) | |
81 | ||
82 | source = self._parse_json( | |
83 | js_to_json(self._html_search_regex( | |
84 | r'(?s)<script>window\.state\s*[:=]\s(\{.+\})\n(\w+).*(</script>).*', | |
85 | webpage, 'WindowState')), | |
86 | video_id) | |
87 | if not source: | |
88 | raise ExtractorError('Cannot find source', expected=True) | |
89 | ||
90 | config_dict = source['config'] | |
91 | video_dict = source['entities'][video_id] | |
92 | ||
93 | thumbnails = [] | |
94 | for i in video_dict.get('imageInfo') or []: | |
95 | thumbnails.append({ | |
96 | 'url': urljoin(config_dict['imageBaseUrl'], i['url']), | |
97 | 'width': i['width'], | |
98 | 'height': i['height'], | |
99 | }) | |
100 | ||
101 | formats = [] | |
102 | get_quality = qualities(['main', 'base', 'high']) | |
103 | for stream_type, quality, stream_url in self._get_stream_urls(video_dict): | |
104 | format_url = url_or_none(urljoin(config_dict['videoCdnBaseUrl'], stream_url)) | |
105 | if not format_url: | |
106 | continue | |
107 | if stream_type == 'dash': | |
108 | dash_formats = self._extract_mpd_formats( | |
109 | format_url, video_id, mpd_id='dash-%s' % quality, headers={'Referer': url}) | |
110 | for frmt in dash_formats: | |
111 | frmt['quality'] = get_quality(quality) | |
112 | formats.extend(dash_formats) | |
113 | elif stream_type == 'hls': | |
114 | formats.extend(self._extract_m3u8_formats( | |
115 | format_url, video_id, fatal=False, | |
116 | m3u8_id='hls-%s' % quality, quality=get_quality(quality))) | |
117 | ||
118 | self._sort_formats(formats) | |
119 | return { | |
120 | 'id': video_id, | |
121 | 'display_id': display_id, | |
122 | 'title': video_dict['title'] or self._og_search_title(webpage), | |
123 | 'formats': formats, | |
124 | 'description': video_dict.get('description'), | |
125 | 'season': try_get(video_dict, lambda x: x['container']['title']), | |
126 | 'series': try_get(video_dict, lambda x: x['container']['container']['title']), | |
127 | 'thumbnails': thumbnails, | |
128 | } | |
129 | ||
130 | ||
131 | class MxplayerShowIE(InfoExtractor): | |
132 | _VALID_URL = r'(?:https?://)(?:www\.)?mxplayer\.in/show/(?P<display_id>[-\w]+)-(?P<id>\w+)/?(?:$|[#?])' | |
133 | _TESTS = [{ | |
134 | 'url': 'https://www.mxplayer.in/show/watch-chakravartin-ashoka-samrat-series-online-a8f44e3cc0814b5601d17772cedf5417', | |
135 | 'playlist_mincount': 440, | |
136 | 'info_dict': { | |
137 | 'id': 'a8f44e3cc0814b5601d17772cedf5417', | |
138 | 'title': 'Watch Chakravartin Ashoka Samrat Series Online', | |
139 | } | |
140 | }] | |
141 | ||
142 | _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" | |
143 | _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&{}" | |
144 | ||
145 | def _entries(self, show_id): | |
146 | show_json = self._download_json( | |
147 | self._API_SHOW_URL.format(show_id), | |
148 | video_id=show_id, headers={'Referer': 'https://mxplayer.in'}) | |
149 | page_num = 0 | |
150 | for season in show_json.get('items') or []: | |
151 | season_id = try_get(season, lambda x: x['id'], compat_str) | |
152 | next_url = '' | |
153 | while next_url is not None: | |
154 | page_num += 1 | |
155 | season_json = self._download_json( | |
156 | self._API_EPISODES_URL.format(season_id, next_url), | |
157 | video_id=season_id, | |
158 | headers={'Referer': 'https://mxplayer.in'}, | |
159 | note='Downloading JSON metadata page %d' % page_num) | |
160 | for episode in season_json.get('items') or []: | |
161 | video_url = episode['webUrl'] | |
162 | yield self.url_result( | |
163 | 'https://mxplayer.in%s' % video_url, | |
164 | ie=MxplayerIE.ie_key(), video_id=video_url.split('-')[-1]) | |
165 | next_url = season_json.get('next') | |
166 | ||
167 | def _real_extract(self, url): | |
168 | display_id, show_id = re.match(self._VALID_URL, url).groups() | |
169 | return self.playlist_result( | |
170 | self._entries(show_id), playlist_id=show_id, | |
171 | playlist_title=display_id.replace('-', ' ').title()) |