soundgasm.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class SoundgasmIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?soundgasm\.net/u/(?P<user>[0-9a-zA-Z_\-]+)/(?P<title>[0-9a-zA-Z_\-]+)'
  7. _TEST = {
  8. 'url': 'http://soundgasm.net/u/ytdl/Piano-sample',
  9. 'md5': '010082a2c802c5275bb00030743e75ad',
  10. 'info_dict': {
  11. 'id': '88abd86ea000cafe98f96321b23cc1206cbcbcc9',
  12. 'ext': 'm4a',
  13. 'title': 'ytdl_Piano-sample',
  14. 'description': 'Royalty Free Sample Music'
  15. }
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. audio_title = mobj.group('user') + '_' + mobj.group('title')
  20. webpage = self._download_webpage(url, '')
  21. audio_url = self._html_search_regex(r'(?s)m4a\:\s"([^"]+)"', webpage, 'audio URL')
  22. audio_id = re.split('\/|\.', audio_url)[-2]
  23. description = self._html_search_regex(r'(?s)<li>Description:\s(.*?)<\/li>', webpage, 'description', fatal=False, flags=re.DOTALL)
  24. return {
  25. 'id': audio_id,
  26. 'url': audio_url,
  27. 'title': audio_title,
  28. 'description': description
  29. }