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.

46 lines
1.4 KiB

10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. class NewgroundsIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/(?:audio/listen|portal/view)/(?P<id>[0-9]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.newgrounds.com/audio/listen/549479',
  7. 'md5': 'fe6033d297591288fa1c1f780386f07a',
  8. 'info_dict': {
  9. 'id': '549479',
  10. 'ext': 'mp3',
  11. 'title': 'B7 - BusMode',
  12. 'uploader': 'Burn7',
  13. }
  14. }, {
  15. 'url': 'https://www.newgrounds.com/portal/view/673111',
  16. 'md5': '3394735822aab2478c31b1004fe5e5bc',
  17. 'info_dict': {
  18. 'id': '673111',
  19. 'ext': 'mp4',
  20. 'title': 'Dancin',
  21. 'uploader': 'Squirrelman82',
  22. },
  23. }]
  24. def _real_extract(self, url):
  25. media_id = self._match_id(url)
  26. webpage = self._download_webpage(url, media_id)
  27. title = self._html_search_regex(
  28. r'<title>([^>]+)</title>', webpage, 'title')
  29. uploader = self._html_search_regex(
  30. r'Author\s*<a[^>]+>([^<]+)', webpage, 'uploader', fatal=False)
  31. music_url = self._parse_json(self._search_regex(
  32. r'"url":("[^"]+"),', webpage, ''), media_id)
  33. return {
  34. 'id': media_id,
  35. 'title': title,
  36. 'url': music_url,
  37. 'uploader': uploader,
  38. }