]>
Commit | Line | Data |
---|---|---|
bd2d82a5 PH |
1 | from __future__ import unicode_literals |
2 | ||
eb03f4da R |
3 | import json |
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
eb03f4da | 7 | |
d0ae9e3a | 8 | |
eb03f4da | 9 | class NewgroundsIE(InfoExtractor): |
d55433bb | 10 | _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/audio/listen/(?P<id>[0-9]+)' |
eb03f4da | 11 | _TEST = { |
bd2d82a5 | 12 | 'url': 'http://www.newgrounds.com/audio/listen/549479', |
bd2d82a5 PH |
13 | 'md5': 'fe6033d297591288fa1c1f780386f07a', |
14 | 'info_dict': { | |
d55433bb PH |
15 | 'id': '549479', |
16 | 'ext': 'mp3', | |
17 | 'title': 'B7 - BusMode', | |
18 | 'uploader': 'Burn7', | |
eb03f4da R |
19 | } |
20 | } | |
21 | ||
22 | def _real_extract(self, url): | |
23 | mobj = re.match(self._VALID_URL, url) | |
24 | music_id = mobj.group('id') | |
25 | webpage = self._download_webpage(url, music_id) | |
5f6a1245 | 26 | |
bd2d82a5 PH |
27 | title = self._html_search_regex( |
28 | r',"name":"([^"]+)",', webpage, 'music title') | |
29 | uploader = self._html_search_regex( | |
30 | r',"artist":"([^"]+)",', webpage, 'music uploader') | |
5f6a1245 | 31 | |
bd2d82a5 PH |
32 | music_url_json_string = self._html_search_regex( |
33 | r'({"url":"[^"]+"),', webpage, 'music url') + '}' | |
eb03f4da R |
34 | music_url_json = json.loads(music_url_json_string) |
35 | music_url = music_url_json['url'] | |
36 | ||
d0ae9e3a | 37 | return { |
bd2d82a5 PH |
38 | 'id': music_id, |
39 | 'title': title, | |
40 | 'url': music_url, | |
eb03f4da | 41 | 'uploader': uploader, |
d0ae9e3a | 42 | } |