soundgasm.py 2.0 KB

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