[Mxplayer] Use mobile API (#966)

Authored by: Ashish0804
This commit is contained in:
Ashish Gupta 2021-09-15 02:23:36 +05:30 committed by GitHub
parent 40b18348e7
commit 1722099ded
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,43 +3,68 @@ from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str from ..compat import compat_str
from ..utils import ( from ..utils import try_get
ExtractorError,
js_to_json,
qualities,
try_get,
url_or_none,
urljoin,
)
class MxplayerIE(InfoExtractor): class MxplayerIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?mxplayer\.in/(?:movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)' _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/(?P<type>movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)'
_TESTS = [{ _TESTS = [{
'url': 'https://www.mxplayer.in/show/watch-my-girlfriend-is-an-alien-hindi-dubbed/season-1/episode-1-online-9d2013d31d5835bb8400e3b3c5e7bb72',
'info_dict': {
'id': '9d2013d31d5835bb8400e3b3c5e7bb72',
'ext': 'mp4',
'title': 'Episode 1',
'description': 'md5:62ed43eb9fec5efde5cf3bd1040b7670',
'season_number': 1,
'episode_number': 1,
'duration': 2451,
'season': 'Season 1',
'series': 'My Girlfriend Is An Alien (Hindi Dubbed)',
'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/9d2013d31d5835bb8400e3b3c5e7bb72/en/16x9/320x180/9562f5f8df42cad09c9a9c4e69eb1567_1920x1080.webp',
'episode': 'Episode 1'
},
'params': {
'format': 'bv',
'skip_download': True,
},
}, {
'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true', 'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true',
'info_dict': { 'info_dict': {
'id': 'b9fa28df3bfb8758874735bbd7d2655a', 'id': 'b9fa28df3bfb8758874735bbd7d2655a',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Knock Knock (Hindi Dubbed)', 'title': 'Knock Knock (Hindi Dubbed)',
'description': 'md5:b195ba93ff1987309cfa58e2839d2a5b' 'description': 'md5:b195ba93ff1987309cfa58e2839d2a5b',
'season_number': 0,
'episode_number': 0,
'duration': 5970,
'season': 'Season 0',
'series': None,
'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/b9fa28df3bfb8758874735bbd7d2655a/en/16x9/320x180/test_pic1588676032011.webp',
'episode': 'Episode 0'
}, },
'params': { 'params': {
'format': 'bv',
'skip_download': True, 'skip_download': True,
'format': 'bestvideo' },
}
}, { }, {
'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c', 'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c',
'info_dict': { 'info_dict': {
'id': '45055d5bcff169ad48f2ad7552a83d6c', 'id': '45055d5bcff169ad48f2ad7552a83d6c',
'ext': 'm3u8', 'ext': 'mp4',
'title': 'The infamous taxi gang of Meerut', 'title': 'The infamous taxi gang of Meerut',
'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28', 'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28',
'season_number': 1,
'episode_number': 1,
'duration': 2332,
'season': 'Season 1', 'season': 'Season 1',
'series': 'Shaitaan' 'series': 'Shaitaan',
'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/45055d5bcff169ad48f2ad7552a83d6c/en/16x9/320x180/voot_8e7d5f8d8183340869279c732c1e3a43.webp',
'episode': 'Episode 1'
}, },
'params': { 'params': {
'format': 'best',
'skip_download': True, 'skip_download': True,
} },
}, { }, {
'url': 'https://www.mxplayer.in/show/watch-aashram/chapter-1/duh-swapna-online-d445579792b0135598ba1bc9088a84cb', 'url': 'https://www.mxplayer.in/show/watch-aashram/chapter-1/duh-swapna-online-d445579792b0135598ba1bc9088a84cb',
'info_dict': { 'info_dict': {
@ -47,88 +72,110 @@ class MxplayerIE(InfoExtractor):
'ext': 'mp4', 'ext': 'mp4',
'title': 'Duh Swapna', 'title': 'Duh Swapna',
'description': 'md5:35ff39c4bdac403c53be1e16a04192d8', 'description': 'md5:35ff39c4bdac403c53be1e16a04192d8',
'season_number': 1,
'episode_number': 3,
'duration': 2568,
'season': 'Chapter 1', 'season': 'Chapter 1',
'series': 'Aashram' 'series': 'Aashram',
'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/d445579792b0135598ba1bc9088a84cb/en/4x3/1600x1200/test_pic1624819307993.webp',
'episode': 'Episode 3'
}, },
'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
'params': { 'params': {
'format': 'bv',
'skip_download': True, 'skip_download': True,
'format': 'bestvideo' },
} }, {
'url': 'https://www.mxplayer.in/show/watch-dangerous/season-1/chapter-1-online-5a351b4f9fb69436f6bd6ae3a1a75292',
'info_dict': {
'id': '5a351b4f9fb69436f6bd6ae3a1a75292',
'ext': 'mp4',
'title': 'Chapter 1',
'description': 'md5:233886b8598bc91648ac098abe1d288f',
'season_number': 1,
'episode_number': 1,
'duration': 1305,
'season': 'Season 1',
'series': 'Dangerous',
'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/5a351b4f9fb69436f6bd6ae3a1a75292/en/4x3/1600x1200/test_pic1624706302350.webp',
'episode': 'Episode 1'
},
'params': {
'format': 'bv',
'skip_download': True,
},
}, {
'url': 'https://www.mxplayer.in/movie/watch-the-attacks-of-2611-movie-online-0452f0d80226c398d63ce7e3ea40fa2d',
'info_dict': {
'id': '0452f0d80226c398d63ce7e3ea40fa2d',
'ext': 'mp4',
'title': 'The Attacks of 26/11',
'description': 'md5:689bacd29e97b3f31eaf519eb14127e5',
'season_number': 0,
'episode_number': 0,
'duration': 6085,
'season': 'Season 0',
'series': None,
'thumbnail': 'https://qqcdnpictest.mxplay.com/pic/0452f0d80226c398d63ce7e3ea40fa2d/en/16x9/320x180/00c8955dab5e5d340dbde643f9b1f6fd_1920x1080.webp',
'episode': 'Episode 0'
},
'params': {
'format': 'best',
'skip_download': True,
},
}] }]
def _get_stream_urls(self, video_dict):
stream_provider_dict = try_get(
video_dict,
lambda x: x['stream'][x['stream']['provider']])
if not stream_provider_dict:
raise ExtractorError('No stream provider found', expected=True)
for stream_name, stream in stream_provider_dict.items():
if stream_name in ('hls', 'dash', 'hlsUrl', 'dashUrl'):
stream_type = stream_name.replace('Url', '')
if isinstance(stream, dict):
for quality, stream_url in stream.items():
if stream_url:
yield stream_type, quality, stream_url
else:
yield stream_type, 'base', stream
def _real_extract(self, url): def _real_extract(self, url):
display_id, video_id = self._match_valid_url(url).groups() type, display_id, video_id = self._match_valid_url(url).groups()
webpage = self._download_webpage(url, video_id) type = 'movie_film' if type == 'movie' else 'tvshow_episode'
API_URL = 'https://androidapi.mxplay.com/v1/detail/'
source = self._parse_json( headers = {
js_to_json(self._html_search_regex( 'X-Av-Code': '23',
r'(?s)<script>window\.state\s*[:=]\s(\{.+\})\n(\w+).*(</script>).*', 'X-Country': 'IN',
webpage, 'WindowState')), 'X-Platform': 'android',
video_id) 'X-App-Version': '1370001318',
if not source: 'X-Resolution': '3840x2160',
raise ExtractorError('Cannot find source', expected=True) }
data_json = self._download_json(f'{API_URL}{type}/{video_id}', display_id, headers=headers)['profile']
config_dict = source['config']
video_dict = source['entities'][video_id]
season, series = None, None
for dct in data_json.get('levelInfos', []):
if dct.get('type') == 'tvshow_season':
season = dct.get('name')
elif dct.get('type') == 'tvshow_show':
series = dct.get('name')
thumbnails = [] thumbnails = []
for i in video_dict.get('imageInfo') or []: for thumb in data_json.get('poster', []):
thumbnails.append({ thumbnails.append({
'url': urljoin(config_dict['imageBaseUrl'], i['url']), 'url': thumb.get('url'),
'width': i['width'], 'width': thumb.get('width'),
'height': i['height'], 'height': thumb.get('height'),
}) })
formats = [] formats = []
get_quality = qualities(['main', 'base', 'high']) subtitles = {}
for stream_type, quality, stream_url in self._get_stream_urls(video_dict): for dct in data_json.get('playInfo', []):
format_url = url_or_none(urljoin(config_dict['videoCdnBaseUrl'], stream_url)) if dct.get('extension') == 'mpd':
if not format_url: frmt, subs = self._extract_mpd_formats_and_subtitles(dct.get('playUrl'), display_id, fatal=False)
continue formats.extend(frmt)
if stream_type == 'dash': subtitles = self._merge_subtitles(subtitles, subs)
dash_formats = self._extract_mpd_formats( elif dct.get('extension') == 'm3u8':
format_url, video_id, mpd_id='dash-%s' % quality, headers={'Referer': url}) frmt, subs = self._extract_m3u8_formats_and_subtitles(dct.get('playUrl'), display_id, fatal=False)
for frmt in dash_formats: formats.extend(frmt)
frmt['quality'] = get_quality(quality) subtitles = self._merge_subtitles(subtitles, subs)
formats.extend(dash_formats)
dash_formats_h265 = self._extract_mpd_formats(
format_url.replace('h264_high', 'h265_main'), video_id, mpd_id='dash-%s' % quality, headers={'Referer': url}, fatal=False)
for frmt in dash_formats_h265:
frmt['quality'] = get_quality(quality)
formats.extend(dash_formats_h265)
elif stream_type == 'hls':
formats.extend(self._extract_m3u8_formats(
format_url, video_id, fatal=False,
m3u8_id='hls-%s' % quality, quality=get_quality(quality), ext='mp4'))
self._sort_formats(formats) self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'display_id': display_id, 'display_id': display_id,
'title': video_dict['title'] or self._og_search_title(webpage), 'title': data_json.get('name') or display_id,
'formats': formats, 'description': data_json.get('description'),
'description': video_dict.get('description'), 'season_number': data_json.get('seasonNum'),
'season': try_get(video_dict, lambda x: x['container']['title']), 'episode_number': data_json.get('episodeNum'),
'series': try_get(video_dict, lambda x: x['container']['container']['title']), 'duration': data_json.get('duration'),
'season': season,
'series': series,
'thumbnails': thumbnails, 'thumbnails': thumbnails,
'formats': formats,
'subtitles': subtitles,
} }