hungama.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class HungamaIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?hungama\.com/song/[^/]+/(?P<id>[0-9]+)'
  7. _TEST = {
  8. 'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
  9. 'md5': 'a845a6d1ebd08d80c1035126d49bd6a0',
  10. 'info_dict': {
  11. 'id': '2931166',
  12. 'ext': 'mp4',
  13. 'title': 'Lucky Ali - Kitni Haseen Zindagi',
  14. 'track': 'Kitni Haseen Zindagi',
  15. 'artist': 'Lucky Ali',
  16. 'album': 'Aks',
  17. 'release_year': 2000,
  18. }
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. data = self._download_json(
  23. 'https://www.hungama.com/audio-player-data/track/%s' % video_id,
  24. video_id, query={'_country': 'IN'})[0]
  25. track = data['song_name']
  26. artist = data.get('singer_name')
  27. m3u8_url = self._download_json(
  28. data.get('file') or data['preview_link'],
  29. video_id)['response']['media_url']
  30. formats = self._extract_m3u8_formats(
  31. m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
  32. m3u8_id='hls')
  33. self._sort_formats(formats)
  34. title = '%s - %s' % (artist, track) if artist else track
  35. thumbnail = data.get('img_src') or data.get('album_image')
  36. return {
  37. 'id': video_id,
  38. 'title': title,
  39. 'thumbnail': thumbnail,
  40. 'track': track,
  41. 'artist': artist,
  42. 'album': data.get('album_name'),
  43. 'release_year': int_or_none(data.get('date')),
  44. 'formats': formats,
  45. }