hungama.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. try_get,
  6. urlencode_postdata,
  7. )
  8. class HungamaIE(InfoExtractor):
  9. _VALID_URL = r'''(?x)
  10. https?://
  11. (?:www\.)?hungama\.com/
  12. (?:
  13. (?:video|movie)/[^/]+/|
  14. tv-show/(?:[^/]+/){2}\d+/episode/[^/]+/
  15. )
  16. (?P<id>\d+)
  17. '''
  18. _TESTS = [{
  19. 'url': 'http://www.hungama.com/video/krishna-chants/39349649/',
  20. 'md5': '687c5f1e9f832f3b59f44ed0eb1f120a',
  21. 'info_dict': {
  22. 'id': '39349649',
  23. 'ext': 'mp4',
  24. 'title': 'Krishna Chants',
  25. 'description': 'Watch Krishna Chants video now. You can also watch other latest videos only at Hungama',
  26. 'upload_date': '20180829',
  27. 'duration': 264,
  28. 'timestamp': 1535500800,
  29. 'view_count': int,
  30. 'thumbnail': 'https://images.hungama.com/c/1/0dc/2ca/39349649/39349649_700x394.jpg',
  31. }
  32. }, {
  33. 'url': 'https://www.hungama.com/movie/kahaani-2/44129919/',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'https://www.hungama.com/tv-show/padded-ki-pushup/season-1/44139461/episode/ep-02-training-sasu-pathlaag-karing/44139503/',
  37. 'only_matching': True,
  38. }]
  39. def _real_extract(self, url):
  40. video_id = self._match_id(url)
  41. video_json = self._download_json(
  42. 'https://www.hungama.com/index.php', video_id,
  43. data=urlencode_postdata({'content_id': video_id}), headers={
  44. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  45. 'X-Requested-With': 'XMLHttpRequest',
  46. }, query={
  47. 'c': 'common',
  48. 'm': 'get_video_mdn_url',
  49. })
  50. formats = self._extract_m3u8_formats(video_json['stream_url'], video_id, ext='mp4', m3u8_id='hls')
  51. json_ld = self._search_json_ld(
  52. self._download_webpage(url, video_id, fatal=False) or '', video_id, fatal=False)
  53. return {
  54. **json_ld,
  55. 'id': video_id,
  56. 'formats': formats,
  57. 'subtitles': {
  58. 'en': [{
  59. 'url': video_json['sub_title'],
  60. 'ext': 'vtt',
  61. }]
  62. } if video_json.get('sub_title') else None,
  63. }
  64. class HungamaSongIE(InfoExtractor):
  65. _VALID_URL = r'https?://(?:www\.)?hungama\.com/song/[^/]+/(?P<id>\d+)'
  66. _TEST = {
  67. 'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
  68. 'md5': 'd4a6a05a394ad0453a9bea3ca00e6024',
  69. 'info_dict': {
  70. 'id': '2931166',
  71. 'ext': 'mp3',
  72. 'title': 'Lucky Ali - Kitni Haseen Zindagi',
  73. 'track': 'Kitni Haseen Zindagi',
  74. 'artist': 'Lucky Ali',
  75. 'album': None,
  76. 'release_year': 2000,
  77. }
  78. }
  79. def _real_extract(self, url):
  80. audio_id = self._match_id(url)
  81. data = self._download_json(
  82. 'https://www.hungama.com/audio-player-data/track/%s' % audio_id,
  83. audio_id, query={'_country': 'IN'})[0]
  84. track = data['song_name']
  85. artist = data.get('singer_name')
  86. formats = []
  87. media_json = self._download_json(data.get('file') or data['preview_link'], audio_id)
  88. media_url = try_get(media_json, lambda x: x['response']['media_url'], str)
  89. media_type = try_get(media_json, lambda x: x['response']['type'], str)
  90. if media_url:
  91. formats.append({
  92. 'url': media_url,
  93. 'ext': media_type,
  94. 'vcodec': 'none',
  95. 'acodec': media_type,
  96. })
  97. title = '%s - %s' % (artist, track) if artist else track
  98. thumbnail = data.get('img_src') or data.get('album_image')
  99. return {
  100. 'id': audio_id,
  101. 'title': title,
  102. 'thumbnail': thumbnail,
  103. 'track': track,
  104. 'artist': artist,
  105. 'album': data.get('album_name') or None,
  106. 'release_year': int_or_none(data.get('date')),
  107. 'formats': formats,
  108. }
  109. class HungamaAlbumPlaylistIE(InfoExtractor):
  110. _VALID_URL = r'https?://(?:www\.)?hungama\.com/(?:playlists|album)/[^/]+/(?P<id>\d+)'
  111. _TESTS = [{
  112. 'url': 'https://www.hungama.com/album/bhuj-the-pride-of-india/69481490/',
  113. 'playlist_mincount': 7,
  114. 'info_dict': {
  115. 'id': '69481490',
  116. },
  117. }, {
  118. 'url': 'https://www.hungama.com/playlists/hindi-jan-to-june-2021/123063/',
  119. 'playlist_mincount': 50,
  120. 'info_dict': {
  121. 'id': '123063',
  122. },
  123. }]
  124. def _real_extract(self, url):
  125. video_id = self._match_id(url)
  126. webpage = self._download_webpage(url, video_id)
  127. ptrn = r'<meta[^>]+?property=[\"\']?music:song:url[\"\']?[^>]+?content=[\"\']?([^\"\']+)'
  128. items = re.findall(ptrn, webpage)
  129. entries = [self.url_result(item, ie=HungamaSongIE.ie_key()) for item in items]
  130. return self.playlist_result(entries, video_id)