]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/newgrounds.py
Merge tag 'upstream/2014.11.21'
[youtubedl] / youtube_dl / extractor / newgrounds.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7
8
9 class NewgroundsIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/audio/listen/(?P<id>[0-9]+)'
11 _TEST = {
12 'url': 'http://www.newgrounds.com/audio/listen/549479',
13 'md5': 'fe6033d297591288fa1c1f780386f07a',
14 'info_dict': {
15 'id': '549479',
16 'ext': 'mp3',
17 'title': 'B7 - BusMode',
18 'uploader': 'Burn7',
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)
26
27 title = self._html_search_regex(
28 r',"name":"([^"]+)",', webpage, 'music title')
29 uploader = self._html_search_regex(
30 r',"artist":"([^"]+)",', webpage, 'music uploader')
31
32 music_url_json_string = self._html_search_regex(
33 r'({"url":"[^"]+"),', webpage, 'music url') + '}'
34 music_url_json = json.loads(music_url_json_string)
35 music_url = music_url_json['url']
36
37 return {
38 'id': music_id,
39 'title': title,
40 'url': music_url,
41 'uploader': uploader,
42 }