You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

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