[hungama] Fix code and extract more metadata (closes #18771)

pull/18780/head
Sergey M․ 6 years ago
parent 8cb5c2181a
commit 06b4b90c70
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

@ -2,31 +2,54 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import int_or_none
class HungamaIE(InfoExtractor): class HungamaIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)hungama\.com/song/[\w\d-]+/(?P<id>[0-9]+)' _VALID_URL = r'https?://(?:www\.)?hungama\.com/song/[^/]+/(?P<id>[0-9]+)'
_TEST = { _TEST = {
'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/', 'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
'md5': '396fa7e8e7e67aa25da0edc4cac9b785', 'md5': 'a845a6d1ebd08d80c1035126d49bd6a0',
'info_dict': { 'info_dict': {
'id': '2931166', 'id': '2931166',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Kitni Haseen Zindagi', 'title': 'Lucky Ali - Kitni Haseen Zindagi',
'track': 'Kitni Haseen Zindagi',
'artist': 'Lucky Ali',
'album': 'Aks',
'release_year': 2000,
} }
} }
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
player_data = self._download_json('https://www.hungama.com/audio-player-data/track/%s?_country=IN' % video_id, video_id)[0] data = self._download_json(
title = player_data.get('song_name') or self._og_search_title(webpage) 'https://www.hungama.com/audio-player-data/track/%s' % video_id,
track_data = self._download_json(player_data['file'], video_id) video_id, query={'_country': 'IN'})[0]
media_url = track_data['response']['media_url']
track = data['song_name']
artist = data.get('singer_name')
m3u8_url = self._download_json(
data.get('file') or data['preview_link'],
video_id)['response']['media_url']
formats = self._extract_m3u8_formats(
m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
m3u8_id='hls')
self._sort_formats(formats)
title = '%s - %s' % (artist, track) if artist else track
thumbnail = data.get('img_src') or data.get('album_image')
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'formats': self._extract_m3u8_formats(media_url, video_id, ext='mp4'), 'thumbnail': thumbnail,
'track': track,
'artist': artist,
'album': data.get('album_name'),
'release_year': int_or_none(data.get('date')),
'formats': formats,
} }

Loading…
Cancel
Save