[hungama] Add extractor
[youtube-dl] / youtube_dl / extractor / hungama.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6
7 class HungamaIE(InfoExtractor):
8     _VALID_URL = r'https?://(?:www\.)hungama\.com/song/[\w\d-]+/(?P<id>[0-9]+)'
9     _TEST = {
10         'url': 'https://www.hungama.com/song/kitni-haseen-zindagi/2931166/',
11         'md5': '396fa7e8e7e67aa25da0edc4cac9b785',
12         'info_dict': {
13             'id': '2931166',
14             'ext': 'mp4',
15             'title': 'Kitni Haseen Zindagi',
16         }
17     }
18
19     def _real_extract(self, url):
20         video_id = self._match_id(url)
21         webpage = self._download_webpage(url, video_id)
22
23         player_data = self._download_json('https://www.hungama.com/audio-player-data/track/%s?_country=IN' % video_id, video_id)[0]
24         title = player_data.get('song_name') or self._og_search_title(webpage)
25         track_data = self._download_json(player_data['file'], video_id)
26         media_url = track_data['response']['media_url']
27
28         return {
29             'id': video_id,
30             'title': title,
31             'formats': self._extract_m3u8_formats(media_url, video_id, ext='mp4'),
32         }