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.3 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import determine_ext
  6. class NewgroundsIE(InfoExtractor):
  7. _VALID_URL = r'(?:https?://)?(?:www\.)?newgrounds\.com/audio/listen/(?P<id>\d+)'
  8. _TEST = {
  9. 'url': 'http://www.newgrounds.com/audio/listen/549479',
  10. 'file': '549479.mp3',
  11. 'md5': 'fe6033d297591288fa1c1f780386f07a',
  12. 'info_dict': {
  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. }