Merge remote-tracking branch 'rzhxeo/RTL_T'
[youtube-dl] / youtube_dl / extractor / newgrounds.py
1 import json
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import determine_ext
6
7
8 class NewgroundsIE(InfoExtractor):
9     _VALID_URL = r'(?:https?://)?(?:www\.)?newgrounds\.com/audio/listen/(?P<id>\d+)'
10     _TEST = {
11         u'url': u'http://www.newgrounds.com/audio/listen/549479',
12         u'file': u'549479.mp3',
13         u'md5': u'fe6033d297591288fa1c1f780386f07a',
14         u'info_dict': {
15             u"title": u"B7 - BusMode",
16             u"uploader": u"Burn7",
17         }
18     }
19
20     def _real_extract(self, url):
21         mobj = re.match(self._VALID_URL, url)
22         music_id = mobj.group('id')
23         webpage = self._download_webpage(url, music_id)
24         
25         title = self._html_search_regex(r',"name":"([^"]+)",', webpage, u'music title')
26         uploader = self._html_search_regex(r',"artist":"([^"]+)",', webpage, u'music uploader')
27         
28         music_url_json_string = self._html_search_regex(r'({"url":"[^"]+"),', webpage, u'music url') + '}'
29         music_url_json = json.loads(music_url_json_string)
30         music_url = music_url_json['url']
31
32         return {
33             'id':       music_id,
34             'title':    title,
35             'url':      music_url,
36             'uploader': uploader,
37             'ext':      determine_ext(music_url),
38         }