]>
Commit | Line | Data |
---|---|---|
14183d1f A |
1 | import re |
2 | ||
8cb5c218 | 3 | from .common import InfoExtractor |
2543938b S |
4 | from ..utils import ( |
5 | int_or_none, | |
14183d1f | 6 | try_get, |
2543938b S |
7 | urlencode_postdata, |
8 | ) | |
8cb5c218 AG |
9 | |
10 | ||
11 | class 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/', | |
1c09783f | 23 | 'md5': '687c5f1e9f832f3b59f44ed0eb1f120a', |
2543938b | 24 | 'info_dict': { |
1c09783f | 25 | 'id': '39349649', |
2543938b | 26 | 'ext': 'mp4', |
1c09783f G |
27 | 'title': 'Krishna Chants', |
28 | 'description': 'Watch Krishna Chants video now. You can also watch other latest videos only at Hungama', | |
29 | 'upload_date': '20180829', | |
30 | 'duration': 264, | |
31 | 'timestamp': 1535500800, | |
32 | 'view_count': int, | |
33 | 'thumbnail': 'https://images.hungama.com/c/1/0dc/2ca/39349649/39349649_700x394.jpg', | |
2543938b S |
34 | } |
35 | }, { | |
36 | 'url': 'https://www.hungama.com/movie/kahaani-2/44129919/', | |
37 | 'only_matching': True, | |
38 | }, { | |
39 | 'url': 'https://www.hungama.com/tv-show/padded-ki-pushup/season-1/44139461/episode/ep-02-training-sasu-pathlaag-karing/44139503/', | |
40 | 'only_matching': True, | |
41 | }] | |
42 | ||
43 | def _real_extract(self, url): | |
44 | video_id = self._match_id(url) | |
1c09783f | 45 | video_json = self._download_json( |
2543938b S |
46 | 'https://www.hungama.com/index.php', video_id, |
47 | data=urlencode_postdata({'content_id': video_id}), headers={ | |
48 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
49 | 'X-Requested-With': 'XMLHttpRequest', | |
50 | }, query={ | |
51 | 'c': 'common', | |
52 | 'm': 'get_video_mdn_url', | |
1c09783f | 53 | }) |
2543938b | 54 | |
1c09783f | 55 | formats = self._extract_m3u8_formats(video_json['stream_url'], video_id, ext='mp4', m3u8_id='hls') |
2543938b | 56 | |
1c09783f G |
57 | json_ld = self._search_json_ld( |
58 | self._download_webpage(url, video_id, fatal=False) or '', video_id, fatal=False) | |
59 | ||
60 | return { | |
61 | **json_ld, | |
2543938b S |
62 | 'id': video_id, |
63 | 'formats': formats, | |
1c09783f G |
64 | 'subtitles': { |
65 | 'en': [{ | |
66 | 'url': video_json['sub_title'], | |
67 | 'ext': 'vtt', | |
68 | }] | |
69 | } if video_json.get('sub_title') else None, | |
70 | } | |
2543938b S |
71 | |
72 | ||
73 | class HungamaSongIE(InfoExtractor): | |
74 | _VALID_URL = r'https?://(?:www\.)?hungama\.com/song/[^/]+/(?P<id>\d+)' | |
8cb5c218 AG |
75 | _TEST = { |
76 | 'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/', | |
14183d1f | 77 | 'md5': 'd4a6a05a394ad0453a9bea3ca00e6024', |
8cb5c218 AG |
78 | 'info_dict': { |
79 | 'id': '2931166', | |
14183d1f | 80 | 'ext': 'mp3', |
06b4b90c S |
81 | 'title': 'Lucky Ali - Kitni Haseen Zindagi', |
82 | 'track': 'Kitni Haseen Zindagi', | |
83 | 'artist': 'Lucky Ali', | |
14183d1f | 84 | 'album': None, |
06b4b90c | 85 | 'release_year': 2000, |
8cb5c218 AG |
86 | } |
87 | } | |
88 | ||
89 | def _real_extract(self, url): | |
2543938b | 90 | audio_id = self._match_id(url) |
8cb5c218 | 91 | |
06b4b90c | 92 | data = self._download_json( |
2543938b S |
93 | 'https://www.hungama.com/audio-player-data/track/%s' % audio_id, |
94 | audio_id, query={'_country': 'IN'})[0] | |
06b4b90c S |
95 | track = data['song_name'] |
96 | artist = data.get('singer_name') | |
14183d1f A |
97 | formats = [] |
98 | media_json = self._download_json(data.get('file') or data['preview_link'], audio_id) | |
99 | media_url = try_get(media_json, lambda x: x['response']['media_url'], str) | |
100 | media_type = try_get(media_json, lambda x: x['response']['type'], str) | |
101 | ||
102 | if media_url: | |
103 | formats.append({ | |
104 | 'url': media_url, | |
105 | 'ext': media_type, | |
106 | 'vcodec': 'none', | |
107 | 'acodec': media_type, | |
108 | }) | |
06b4b90c S |
109 | |
110 | title = '%s - %s' % (artist, track) if artist else track | |
111 | thumbnail = data.get('img_src') or data.get('album_image') | |
8cb5c218 AG |
112 | |
113 | return { | |
2543938b | 114 | 'id': audio_id, |
8cb5c218 | 115 | 'title': title, |
06b4b90c S |
116 | 'thumbnail': thumbnail, |
117 | 'track': track, | |
118 | 'artist': artist, | |
14183d1f | 119 | 'album': data.get('album_name') or None, |
06b4b90c S |
120 | 'release_year': int_or_none(data.get('date')), |
121 | 'formats': formats, | |
8cb5c218 | 122 | } |
14183d1f A |
123 | |
124 | ||
125 | class HungamaAlbumPlaylistIE(InfoExtractor): | |
126 | _VALID_URL = r'https?://(?:www\.)?hungama\.com/(?:playlists|album)/[^/]+/(?P<id>\d+)' | |
127 | _TESTS = [{ | |
128 | 'url': 'https://www.hungama.com/album/bhuj-the-pride-of-india/69481490/', | |
129 | 'playlist_mincount': 7, | |
130 | 'info_dict': { | |
131 | 'id': '69481490', | |
132 | }, | |
133 | }, { | |
134 | 'url': 'https://www.hungama.com/playlists/hindi-jan-to-june-2021/123063/', | |
135 | 'playlist_mincount': 50, | |
136 | 'info_dict': { | |
137 | 'id': '123063', | |
138 | }, | |
139 | }] | |
140 | ||
141 | def _real_extract(self, url): | |
5ad28e7f | 142 | video_id = self._match_id(url) |
143 | webpage = self._download_webpage(url, video_id) | |
14183d1f A |
144 | ptrn = r'<meta[^>]+?property=[\"\']?music:song:url[\"\']?[^>]+?content=[\"\']?([^\"\']+)' |
145 | items = re.findall(ptrn, webpage) | |
146 | entries = [self.url_result(item, ie=HungamaSongIE.ie_key()) for item in items] | |
5ad28e7f | 147 | return self.playlist_result(entries, video_id) |