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.

53 lines
1.6 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|portal/view)/(?P<id>[0-9]+)'
  7. _TESTS = [{
  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. 'url': 'http://www.newgrounds.com/portal/view/673111',
  18. 'md5': '3394735822aab2478c31b1004fe5e5bc',
  19. 'info_dict': {
  20. 'id': '673111',
  21. 'ext': 'mp4',
  22. 'title': 'Dancin',
  23. 'uploader': 'Squirrelman82',
  24. },
  25. }]
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. music_id = mobj.group('id')
  29. webpage = self._download_webpage(url, music_id)
  30. title = self._html_search_regex(
  31. r'<title>([^>]+)</title>', webpage, 'title')
  32. uploader = self._html_search_regex(
  33. [r',"artist":"([^"]+)",', r'[\'"]owner[\'"]\s*:\s*[\'"]([^\'"]+)[\'"],'],
  34. webpage, 'uploader')
  35. music_url_json_string = self._html_search_regex(
  36. r'({"url":"[^"]+"),', webpage, 'music url') + '}'
  37. music_url_json = json.loads(music_url_json_string)
  38. music_url = music_url_json['url']
  39. return {
  40. 'id': music_id,
  41. 'title': title,
  42. 'url': music_url,
  43. 'uploader': uploader,
  44. }