logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

hungama.py (3803B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  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': 'a845a6d1ebd08d80c1035126d49bd6a0',
  21. 'info_dict': {
  22. 'id': '2931166',
  23. 'ext': 'mp4',
  24. 'title': 'Lucky Ali - Kitni Haseen Zindagi',
  25. 'track': 'Kitni Haseen Zindagi',
  26. 'artist': 'Lucky Ali',
  27. 'album': 'Aks',
  28. 'release_year': 2000,
  29. }
  30. }, {
  31. 'url': 'https://www.hungama.com/movie/kahaani-2/44129919/',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'https://www.hungama.com/tv-show/padded-ki-pushup/season-1/44139461/episode/ep-02-training-sasu-pathlaag-karing/44139503/',
  35. 'only_matching': True,
  36. }]
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(url, video_id)
  40. info = self._search_json_ld(webpage, video_id)
  41. m3u8_url = 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. })['stream_url']
  50. formats = self._extract_m3u8_formats(
  51. m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
  52. m3u8_id='hls')
  53. self._sort_formats(formats)
  54. info.update({
  55. 'id': video_id,
  56. 'formats': formats,
  57. })
  58. return info
  59. class HungamaSongIE(InfoExtractor):
  60. _VALID_URL = r'https?://(?:www\.)?hungama\.com/song/[^/]+/(?P<id>\d+)'
  61. _TEST = {
  62. 'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
  63. 'md5': 'a845a6d1ebd08d80c1035126d49bd6a0',
  64. 'info_dict': {
  65. 'id': '2931166',
  66. 'ext': 'mp4',
  67. 'title': 'Lucky Ali - Kitni Haseen Zindagi',
  68. 'track': 'Kitni Haseen Zindagi',
  69. 'artist': 'Lucky Ali',
  70. 'album': 'Aks',
  71. 'release_year': 2000,
  72. }
  73. }
  74. def _real_extract(self, url):
  75. audio_id = self._match_id(url)
  76. data = self._download_json(
  77. 'https://www.hungama.com/audio-player-data/track/%s' % audio_id,
  78. audio_id, query={'_country': 'IN'})[0]
  79. track = data['song_name']
  80. artist = data.get('singer_name')
  81. m3u8_url = self._download_json(
  82. data.get('file') or data['preview_link'],
  83. audio_id)['response']['media_url']
  84. formats = self._extract_m3u8_formats(
  85. m3u8_url, audio_id, ext='mp4', entry_protocol='m3u8_native',
  86. m3u8_id='hls')
  87. self._sort_formats(formats)
  88. title = '%s - %s' % (artist, track) if artist else track
  89. thumbnail = data.get('img_src') or data.get('album_image')
  90. return {
  91. 'id': audio_id,
  92. 'title': title,
  93. 'thumbnail': thumbnail,
  94. 'track': track,
  95. 'artist': artist,
  96. 'album': data.get('album_name'),
  97. 'release_year': int_or_none(data.get('date')),
  98. 'formats': formats,
  99. }