1 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..compat
import compat_str
16 class MxplayerIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?mxplayer\.in/(?:movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)'
19 'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true',
21 'id': 'b9fa28df3bfb8758874735bbd7d2655a',
23 'title': 'Knock Knock (Hindi Dubbed)',
24 'description': 'md5:b195ba93ff1987309cfa58e2839d2a5b'
27 'skip_download': True,
31 'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c',
33 'id': '45055d5bcff169ad48f2ad7552a83d6c',
35 'title': 'The infamous taxi gang of Meerut',
36 'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28',
41 'skip_download': True,
44 'url': 'https://www.mxplayer.in/show/watch-aashram/chapter-1/duh-swapna-online-d445579792b0135598ba1bc9088a84cb',
46 'id': 'd445579792b0135598ba1bc9088a84cb',
48 'title': 'Duh Swapna',
49 'description': 'md5:35ff39c4bdac403c53be1e16a04192d8',
50 'season': 'Chapter 1',
53 'expected_warnings': ['Unknown MIME type application/mp4 in DASH manifest'],
55 'skip_download': True,
60 def _get_stream_urls(self
, video_dict
):
61 stream_provider_dict
= try_get(
63 lambda x
: x
['stream'][x
['stream']['provider']])
64 if not stream_provider_dict
:
65 raise ExtractorError('No stream provider found', expected
=True)
67 for stream_name
, stream
in stream_provider_dict
.items():
68 if stream_name
in ('hls', 'dash', 'hlsUrl', 'dashUrl'):
69 stream_type
= stream_name
.replace('Url', '')
70 if isinstance(stream
, dict):
71 for quality
, stream_url
in stream
.items():
73 yield stream_type
, quality
, stream_url
75 yield stream_type
, 'base', stream
77 def _real_extract(self
, url
):
78 display_id
, video_id
= self
._match
_valid
_url
(url
).groups()
79 webpage
= self
._download
_webpage
(url
, video_id
)
81 source
= self
._parse
_json
(
82 js_to_json(self
._html
_search
_regex
(
83 r
'(?s)<script>window\.state\s*[:=]\s(\{.+\})\n(\w+).*(</script>).*',
84 webpage
, 'WindowState')),
87 raise ExtractorError('Cannot find source', expected
=True)
89 config_dict
= source
['config']
90 video_dict
= source
['entities'][video_id
]
93 for i
in video_dict
.get('imageInfo') or []:
95 'url': urljoin(config_dict
['imageBaseUrl'], i
['url']),
97 'height': i
['height'],
101 get_quality
= qualities(['main', 'base', 'high'])
102 for stream_type
, quality
, stream_url
in self
._get
_stream
_urls
(video_dict
):
103 format_url
= url_or_none(urljoin(config_dict
['videoCdnBaseUrl'], stream_url
))
106 if stream_type
== 'dash':
107 dash_formats
= self
._extract
_mpd
_formats
(
108 format_url
, video_id
, mpd_id
='dash-%s' % quality
, headers
={'Referer': url}
)
109 for frmt
in dash_formats
:
110 frmt
['quality'] = get_quality(quality
)
111 formats
.extend(dash_formats
)
112 dash_formats_h265
= self
._extract
_mpd
_formats
(
113 format_url
.replace('h264_high', 'h265_main'), video_id
, mpd_id
='dash-%s' % quality
, headers
={'Referer': url}
, fatal
=False)
114 for frmt
in dash_formats_h265
:
115 frmt
['quality'] = get_quality(quality
)
116 formats
.extend(dash_formats_h265
)
117 elif stream_type
== 'hls':
118 formats
.extend(self
._extract
_m
3u8_formats
(
119 format_url
, video_id
, fatal
=False,
120 m3u8_id
='hls-%s' % quality
, quality
=get_quality(quality
), ext
='mp4'))
122 self
._sort
_formats
(formats
)
125 'display_id': display_id
,
126 'title': video_dict
['title'] or self
._og
_search
_title
(webpage
),
128 'description': video_dict
.get('description'),
129 'season': try_get(video_dict
, lambda x
: x
['container']['title']),
130 'series': try_get(video_dict
, lambda x
: x
['container']['container']['title']),
131 'thumbnails': thumbnails
,
135 class MxplayerShowIE(InfoExtractor
):
136 _VALID_URL
= r
'(?:https?://)(?:www\.)?mxplayer\.in/show/(?P<display_id>[-\w]+)-(?P<id>\w+)/?(?:$|[#?])'
138 'url': 'https://www.mxplayer.in/show/watch-chakravartin-ashoka-samrat-series-online-a8f44e3cc0814b5601d17772cedf5417',
139 'playlist_mincount': 440,
141 'id': 'a8f44e3cc0814b5601d17772cedf5417',
142 'title': 'Watch Chakravartin Ashoka Samrat Series Online',
146 _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"
147 _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&{}"
149 def _entries(self
, show_id
):
150 show_json
= self
._download
_json
(
151 self
._API
_SHOW
_URL
.format(show_id
),
152 video_id
=show_id
, headers
={'Referer': 'https://mxplayer.in'}
)
154 for season
in show_json
.get('items') or []:
155 season_id
= try_get(season
, lambda x
: x
['id'], compat_str
)
157 while next_url
is not None:
159 season_json
= self
._download
_json
(
160 self
._API
_EPISODES
_URL
.format(season_id
, next_url
),
162 headers
={'Referer': 'https://mxplayer.in'}
,
163 note
='Downloading JSON metadata page %d' % page_num
)
164 for episode
in season_json
.get('items') or []:
165 video_url
= episode
['webUrl']
166 yield self
.url_result(
167 'https://mxplayer.in%s' % video_url
,
168 ie
=MxplayerIE
.ie_key(), video_id
=video_url
.split('-')[-1])
169 next_url
= season_json
.get('next')
171 def _real_extract(self
, url
):
172 display_id
, show_id
= self
._match
_valid
_url
(url
).groups()
173 return self
.playlist_result(
174 self
._entries
(show_id
), playlist_id
=show_id
,
175 playlist_title
=display_id
.replace('-', ' ').title())