mxplayer.py 9.7 KB

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