]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/hungama.py
1 from .common
import InfoExtractor
13 class HungamaBaseIE(InfoExtractor
):
14 def _call_api(self
, path
, content_id
, fatal
=False):
15 return traverse_obj(self
._download
_json
(
16 f
'https://cpage.api.hungama.com/v2/page/content/{content_id}/{path}/detail',
17 content_id
, fatal
=fatal
, query
={
21 }), ('data', {dict}
)) or {}
24 class HungamaIE(HungamaBaseIE
):
27 (?:www\.|un\.)?hungama\.com/
29 (?:video|movie|short-film)/[^/]+/|
30 tv-show/(?:[^/]+/){2}\d+/episode/[^/]+/
35 'url': 'http://www.hungama.com/video/krishna-chants/39349649/',
36 'md5': '687c5f1e9f832f3b59f44ed0eb1f120a',
40 'title': 'Krishna Chants',
42 'upload_date': '20180829',
44 'timestamp': 1535500800,
46 'thumbnail': 'https://images1.hungama.com/tr:n-a_169_m/c/1/0dc/2ca/39349649/39349649_350x197.jpg?v=8',
50 'url': 'https://un.hungama.com/short-film/adira/102524179/',
51 'md5': '2278463f5dc9db9054d0c02602d44666',
56 'description': 'md5:df20cd4d41eabb33634f06de1025a4b4',
57 'upload_date': '20230417',
58 'timestamp': 1681689600,
60 'thumbnail': 'https://images1.hungama.com/tr:n-a_23_m/c/1/197/ac9/102524179/102524179_350x525.jpg?v=1',
64 'url': 'https://www.hungama.com/movie/kahaani-2/44129919/',
65 'only_matching': True,
67 'url': 'https://www.hungama.com/tv-show/padded-ki-pushup/season-1/44139461/episode/ep-02-training-sasu-pathlaag-karing/44139503/',
68 'only_matching': True,
71 def _real_extract(self
, url
):
72 video_id
= self
._match
_id
(url
)
73 video_json
= self
._download
_json
(
74 'https://www.hungama.com/index.php', video_id
,
75 data
=urlencode_postdata({'content_id': video_id}
), headers
={
76 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
77 'X-Requested-With': 'XMLHttpRequest',
80 'm': 'get_video_mdn_url',
82 formats
= self
._extract
_m
3u8_formats
(video_json
['stream_url'], video_id
, ext
='mp4', m3u8_id
='hls')
83 metadata
= self
._call
_api
('movie', video_id
)
86 **traverse_obj(metadata
, ('head', 'data', {
87 'title': ('title', {str}
),
88 'description': ('misc', 'description', {str}
),
89 'duration': ('duration', {int}
), # duration in JSON is incorrect if string
90 'timestamp': ('releasedate', {unified_timestamp}
),
91 'view_count': ('misc', 'playcount', {int_or_none}
),
92 'thumbnail': ('image', {url_or_none}
),
93 'tags': ('misc', 'keywords', ..., {str}
),
99 'url': video_json
['sub_title'],
102 } if video_json
.get('sub_title') else None,
106 class HungamaSongIE(InfoExtractor
):
107 _VALID_URL
= r
'https?://(?:www\.|un\.)?hungama\.com/song/[^/]+/(?P<id>\d+)'
109 'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
110 'md5': '964f46828e8b250aa35e5fdcfdcac367',
114 'title': 'Lucky Ali - Kitni Haseen Zindagi',
115 'track': 'Kitni Haseen Zindagi',
116 'artist': 'Lucky Ali',
118 'release_year': 2000,
119 'thumbnail': 'https://stat2.hungama.ind.in/assets/images/default_images/da-200x200.png',
122 'url': 'https://un.hungama.com/song/tum-kya-mile-from-rocky-aur-rani-kii-prem-kahaani/103553672',
123 'md5': '964f46828e8b250aa35e5fdcfdcac367',
127 'title': 'md5:5ebeb1e10771b634ce5f700ce68ae5f4',
128 'track': 'Tum Kya Mile (From "Rocky Aur Rani Kii Prem Kahaani")',
129 'artist': 'Pritam Chakraborty, Arijit Singh, Shreya Ghoshal, Amitabh Bhattacharya',
130 'album': 'Tum Kya Mile (From "Rocky Aur Rani Kii Prem Kahaani")',
131 'release_year': 2023,
132 'thumbnail': 'https://images.hungama.com/c/1/7c2/c7b/103553671/103553671_200x200.jpg',
136 def _real_extract(self
, url
):
137 audio_id
= self
._match
_id
(url
)
139 data
= self
._download
_json
(
140 'https://www.hungama.com/audio-player-data/track/%s' % audio_id
,
141 audio_id
, query
={'_country': 'IN'}
)[0]
142 track
= data
['song_name']
143 artist
= data
.get('singer_name')
145 media_json
= self
._download
_json
(data
.get('file') or data
['preview_link'], audio_id
)
146 media_url
= try_get(media_json
, lambda x
: x
['response']['media_url'], str)
147 media_type
= try_get(media_json
, lambda x
: x
['response']['type'], str)
154 'acodec': media_type
,
157 title
= '%s - %s' % (artist
, track
) if artist
else track
158 thumbnail
= data
.get('img_src') or data
.get('album_image')
163 'thumbnail': thumbnail
,
166 'album': data
.get('album_name') or None,
167 'release_year': int_or_none(data
.get('date')),
172 class HungamaAlbumPlaylistIE(HungamaBaseIE
):
173 _VALID_URL
= r
'https?://(?:www\.|un\.)?hungama\.com/(?P<path>playlists|album)/[^/]+/(?P<id>\d+)'
175 'url': 'https://www.hungama.com/album/bhuj-the-pride-of-india/69481490/',
176 'playlist_mincount': 7,
181 'url': 'https://www.hungama.com/playlists/hindi-jan-to-june-2021/123063/',
182 'playlist_mincount': 33,
187 'url': 'https://un.hungama.com/album/what-jhumka-%3F-from-rocky-aur-rani-kii-prem-kahaani/103891805/',
188 'playlist_mincount': 1,
194 def _real_extract(self
, url
):
195 playlist_id
, path
= self
._match
_valid
_url
(url
).group('id', 'path')
196 data
= self
._call
_api
(remove_end(path
, 's'), playlist_id
, fatal
=True)
199 for song_url
in traverse_obj(data
, ('body', 'rows', ..., 'data', 'misc', 'share', {url_or_none}
)):
200 yield self
.url_result(song_url
, HungamaSongIE
)
202 return self
.playlist_result(entries(), playlist_id
)