mxplayer.py 9.8 KB

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