2021-08-20 18:16:59 +00:00
|
|
|
import re
|
|
|
|
|
2019-01-07 12:11:12 +00:00
|
|
|
from .common import InfoExtractor
|
2019-01-08 03:03:44 +00:00
|
|
|
from ..utils import (
|
|
|
|
int_or_none,
|
2021-08-20 18:16:59 +00:00
|
|
|
try_get,
|
2019-01-08 03:03:44 +00:00
|
|
|
urlencode_postdata,
|
|
|
|
)
|
2019-01-07 12:11:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HungamaIE(InfoExtractor):
|
2019-01-08 03:03:44 +00:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
https?://
|
|
|
|
(?:www\.)?hungama\.com/
|
|
|
|
(?:
|
|
|
|
(?:video|movie)/[^/]+/|
|
|
|
|
tv-show/(?:[^/]+/){2}\d+/episode/[^/]+/
|
|
|
|
)
|
|
|
|
(?P<id>\d+)
|
|
|
|
'''
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'http://www.hungama.com/video/krishna-chants/39349649/',
|
|
|
|
'md5': 'a845a6d1ebd08d80c1035126d49bd6a0',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '2931166',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Lucky Ali - Kitni Haseen Zindagi',
|
|
|
|
'track': 'Kitni Haseen Zindagi',
|
|
|
|
'artist': 'Lucky Ali',
|
|
|
|
'album': 'Aks',
|
|
|
|
'release_year': 2000,
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.hungama.com/movie/kahaani-2/44129919/',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.hungama.com/tv-show/padded-ki-pushup/season-1/44139461/episode/ep-02-training-sasu-pathlaag-karing/44139503/',
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
|
|
|
info = self._search_json_ld(webpage, video_id)
|
|
|
|
|
|
|
|
m3u8_url = self._download_json(
|
|
|
|
'https://www.hungama.com/index.php', video_id,
|
|
|
|
data=urlencode_postdata({'content_id': video_id}), headers={
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
}, query={
|
|
|
|
'c': 'common',
|
|
|
|
'm': 'get_video_mdn_url',
|
|
|
|
})['stream_url']
|
|
|
|
|
|
|
|
formats = self._extract_m3u8_formats(
|
|
|
|
m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
|
|
|
|
m3u8_id='hls')
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
info.update({
|
|
|
|
'id': video_id,
|
|
|
|
'formats': formats,
|
|
|
|
})
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
class HungamaSongIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?hungama\.com/song/[^/]+/(?P<id>\d+)'
|
2019-01-07 12:11:12 +00:00
|
|
|
_TEST = {
|
|
|
|
'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
|
2021-08-20 18:16:59 +00:00
|
|
|
'md5': 'd4a6a05a394ad0453a9bea3ca00e6024',
|
2019-01-07 12:11:12 +00:00
|
|
|
'info_dict': {
|
|
|
|
'id': '2931166',
|
2021-08-20 18:16:59 +00:00
|
|
|
'ext': 'mp3',
|
2019-01-08 02:09:49 +00:00
|
|
|
'title': 'Lucky Ali - Kitni Haseen Zindagi',
|
|
|
|
'track': 'Kitni Haseen Zindagi',
|
|
|
|
'artist': 'Lucky Ali',
|
2021-08-20 18:16:59 +00:00
|
|
|
'album': None,
|
2019-01-08 02:09:49 +00:00
|
|
|
'release_year': 2000,
|
2019-01-07 12:11:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2019-01-08 03:03:44 +00:00
|
|
|
audio_id = self._match_id(url)
|
2019-01-07 12:11:12 +00:00
|
|
|
|
2019-01-08 02:09:49 +00:00
|
|
|
data = self._download_json(
|
2019-01-08 03:03:44 +00:00
|
|
|
'https://www.hungama.com/audio-player-data/track/%s' % audio_id,
|
|
|
|
audio_id, query={'_country': 'IN'})[0]
|
2019-01-08 02:09:49 +00:00
|
|
|
track = data['song_name']
|
|
|
|
artist = data.get('singer_name')
|
2021-08-20 18:16:59 +00:00
|
|
|
formats = []
|
|
|
|
media_json = self._download_json(data.get('file') or data['preview_link'], audio_id)
|
|
|
|
media_url = try_get(media_json, lambda x: x['response']['media_url'], str)
|
|
|
|
media_type = try_get(media_json, lambda x: x['response']['type'], str)
|
|
|
|
|
|
|
|
if media_url:
|
|
|
|
formats.append({
|
|
|
|
'url': media_url,
|
|
|
|
'ext': media_type,
|
|
|
|
'vcodec': 'none',
|
|
|
|
'acodec': media_type,
|
|
|
|
})
|
2019-01-08 02:09:49 +00:00
|
|
|
|
|
|
|
title = '%s - %s' % (artist, track) if artist else track
|
|
|
|
thumbnail = data.get('img_src') or data.get('album_image')
|
2019-01-07 12:11:12 +00:00
|
|
|
|
|
|
|
return {
|
2019-01-08 03:03:44 +00:00
|
|
|
'id': audio_id,
|
2019-01-07 12:11:12 +00:00
|
|
|
'title': title,
|
2019-01-08 02:09:49 +00:00
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'track': track,
|
|
|
|
'artist': artist,
|
2021-08-20 18:16:59 +00:00
|
|
|
'album': data.get('album_name') or None,
|
2019-01-08 02:09:49 +00:00
|
|
|
'release_year': int_or_none(data.get('date')),
|
|
|
|
'formats': formats,
|
2019-01-07 12:11:12 +00:00
|
|
|
}
|
2021-08-20 18:16:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HungamaAlbumPlaylistIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?hungama\.com/(?:playlists|album)/[^/]+/(?P<id>\d+)'
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.hungama.com/album/bhuj-the-pride-of-india/69481490/',
|
|
|
|
'playlist_mincount': 7,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '69481490',
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.hungama.com/playlists/hindi-jan-to-june-2021/123063/',
|
|
|
|
'playlist_mincount': 50,
|
|
|
|
'info_dict': {
|
|
|
|
'id': '123063',
|
|
|
|
},
|
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-19 01:41:24 +00:00
|
|
|
video_id = self._match_id(url)
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
2021-08-20 18:16:59 +00:00
|
|
|
ptrn = r'<meta[^>]+?property=[\"\']?music:song:url[\"\']?[^>]+?content=[\"\']?([^\"\']+)'
|
|
|
|
items = re.findall(ptrn, webpage)
|
|
|
|
entries = [self.url_result(item, ie=HungamaSongIE.ie_key()) for item in items]
|
2021-08-19 01:41:24 +00:00
|
|
|
return self.playlist_result(entries, video_id)
|