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.

38 lines
1.3 KiB

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