soundgasm.py 2.3 KB

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