]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/hungama.py
[extractor/huya] Fix stream extraction (#4798)
[yt-dlp.git] / yt_dlp / extractor / hungama.py
CommitLineData
14183d1f
A
1import re
2
8cb5c218 3from .common import InfoExtractor
2543938b
S
4from ..utils import (
5 int_or_none,
14183d1f 6 try_get,
2543938b
S
7 urlencode_postdata,
8)
8cb5c218
AG
9
10
11class HungamaIE(InfoExtractor):
2543938b
S
12 _VALID_URL = r'''(?x)
13 https?://
14 (?:www\.)?hungama\.com/
15 (?:
16 (?:video|movie)/[^/]+/|
17 tv-show/(?:[^/]+/){2}\d+/episode/[^/]+/
18 )
19 (?P<id>\d+)
20 '''
21 _TESTS = [{
22 'url': 'http://www.hungama.com/video/krishna-chants/39349649/',
23 'md5': 'a845a6d1ebd08d80c1035126d49bd6a0',
24 'info_dict': {
25 'id': '2931166',
26 'ext': 'mp4',
27 'title': 'Lucky Ali - Kitni Haseen Zindagi',
28 'track': 'Kitni Haseen Zindagi',
29 'artist': 'Lucky Ali',
30 'album': 'Aks',
31 'release_year': 2000,
32 }
33 }, {
34 'url': 'https://www.hungama.com/movie/kahaani-2/44129919/',
35 'only_matching': True,
36 }, {
37 'url': 'https://www.hungama.com/tv-show/padded-ki-pushup/season-1/44139461/episode/ep-02-training-sasu-pathlaag-karing/44139503/',
38 'only_matching': True,
39 }]
40
41 def _real_extract(self, url):
42 video_id = self._match_id(url)
43
44 webpage = self._download_webpage(url, video_id)
45
46 info = self._search_json_ld(webpage, video_id)
47
48 m3u8_url = self._download_json(
49 'https://www.hungama.com/index.php', video_id,
50 data=urlencode_postdata({'content_id': video_id}), headers={
51 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
52 'X-Requested-With': 'XMLHttpRequest',
53 }, query={
54 'c': 'common',
55 'm': 'get_video_mdn_url',
56 })['stream_url']
57
58 formats = self._extract_m3u8_formats(
59 m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
60 m3u8_id='hls')
61 self._sort_formats(formats)
62
63 info.update({
64 'id': video_id,
65 'formats': formats,
66 })
67 return info
68
69
70class HungamaSongIE(InfoExtractor):
71 _VALID_URL = r'https?://(?:www\.)?hungama\.com/song/[^/]+/(?P<id>\d+)'
8cb5c218
AG
72 _TEST = {
73 'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
14183d1f 74 'md5': 'd4a6a05a394ad0453a9bea3ca00e6024',
8cb5c218
AG
75 'info_dict': {
76 'id': '2931166',
14183d1f 77 'ext': 'mp3',
06b4b90c
S
78 'title': 'Lucky Ali - Kitni Haseen Zindagi',
79 'track': 'Kitni Haseen Zindagi',
80 'artist': 'Lucky Ali',
14183d1f 81 'album': None,
06b4b90c 82 'release_year': 2000,
8cb5c218
AG
83 }
84 }
85
86 def _real_extract(self, url):
2543938b 87 audio_id = self._match_id(url)
8cb5c218 88
06b4b90c 89 data = self._download_json(
2543938b
S
90 'https://www.hungama.com/audio-player-data/track/%s' % audio_id,
91 audio_id, query={'_country': 'IN'})[0]
06b4b90c
S
92 track = data['song_name']
93 artist = data.get('singer_name')
14183d1f
A
94 formats = []
95 media_json = self._download_json(data.get('file') or data['preview_link'], audio_id)
96 media_url = try_get(media_json, lambda x: x['response']['media_url'], str)
97 media_type = try_get(media_json, lambda x: x['response']['type'], str)
98
99 if media_url:
100 formats.append({
101 'url': media_url,
102 'ext': media_type,
103 'vcodec': 'none',
104 'acodec': media_type,
105 })
06b4b90c
S
106
107 title = '%s - %s' % (artist, track) if artist else track
108 thumbnail = data.get('img_src') or data.get('album_image')
8cb5c218
AG
109
110 return {
2543938b 111 'id': audio_id,
8cb5c218 112 'title': title,
06b4b90c
S
113 'thumbnail': thumbnail,
114 'track': track,
115 'artist': artist,
14183d1f 116 'album': data.get('album_name') or None,
06b4b90c
S
117 'release_year': int_or_none(data.get('date')),
118 'formats': formats,
8cb5c218 119 }
14183d1f
A
120
121
122class HungamaAlbumPlaylistIE(InfoExtractor):
123 _VALID_URL = r'https?://(?:www\.)?hungama\.com/(?:playlists|album)/[^/]+/(?P<id>\d+)'
124 _TESTS = [{
125 'url': 'https://www.hungama.com/album/bhuj-the-pride-of-india/69481490/',
126 'playlist_mincount': 7,
127 'info_dict': {
128 'id': '69481490',
129 },
130 }, {
131 'url': 'https://www.hungama.com/playlists/hindi-jan-to-june-2021/123063/',
132 'playlist_mincount': 50,
133 'info_dict': {
134 'id': '123063',
135 },
136 }]
137
138 def _real_extract(self, url):
5ad28e7f 139 video_id = self._match_id(url)
140 webpage = self._download_webpage(url, video_id)
14183d1f
A
141 ptrn = r'<meta[^>]+?property=[\"\']?music:song:url[\"\']?[^>]+?content=[\"\']?([^\"\']+)'
142 items = re.findall(ptrn, webpage)
143 entries = [self.url_result(item, ie=HungamaSongIE.ie_key()) for item in items]
5ad28e7f 144 return self.playlist_result(entries, video_id)