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.

64 lines
2.0 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class SoundgasmIE(InfoExtractor):
  6. IE_NAME = 'soundgasm'
  7. _VALID_URL = r'https?://(?:www\.)?soundgasm\.net/u/(?P<user>[0-9a-zA-Z_\-]+)/(?P<title>[0-9a-zA-Z_\-]+)'
  8. _TEST = {
  9. 'url': 'http://soundgasm.net/u/ytdl/Piano-sample',
  10. 'md5': '010082a2c802c5275bb00030743e75ad',
  11. 'info_dict': {
  12. 'id': '88abd86ea000cafe98f96321b23cc1206cbcbcc9',
  13. 'ext': 'm4a',
  14. 'title': 'ytdl_Piano-sample',
  15. 'description': 'Royalty Free Sample Music'
  16. }
  17. }
  18. def _real_extract(self, url):
  19. mobj = re.match(self._VALID_URL, url)
  20. display_id = mobj.group('title')
  21. audio_title = mobj.group('user') + '_' + mobj.group('title')
  22. webpage = self._download_webpage(url, display_id)
  23. audio_url = self._html_search_regex(
  24. r'(?s)m4a\:\s"([^"]+)"', webpage, 'audio URL')
  25. audio_id = re.split('\/|\.', audio_url)[-2]
  26. description = self._html_search_regex(
  27. r'(?s)<li>Description:\s(.*?)<\/li>', webpage, 'description',
  28. fatal=False)
  29. return {
  30. 'id': audio_id,
  31. 'display_id': display_id,
  32. 'url': audio_url,
  33. 'title': audio_title,
  34. 'description': description
  35. }
  36. class SoundgasmProfileIE(InfoExtractor):
  37. IE_NAME = 'soundgasm:profile'
  38. _VALID_URL = r'https?://(?:www\.)?soundgasm\.net/u/(?P<id>[^/]+)/?(?:\#.*)?$'
  39. _TEST = {
  40. 'url': 'http://soundgasm.net/u/ytdl',
  41. 'info_dict': {
  42. 'id': 'ytdl',
  43. },
  44. 'playlist_count': 1,
  45. }
  46. def _real_extract(self, url):
  47. profile_id = self._match_id(url)
  48. webpage = self._download_webpage(url, profile_id)
  49. entries = [
  50. self.url_result(audio_url, 'Soundgasm')
  51. for audio_url in re.findall(r'href="([^"]+/u/%s/[^"]+)' % profile_id, webpage)]
  52. return self.playlist_result(entries, profile_id)