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.

76 lines
2.3 KiB

  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. _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. _VALID_URL = r'https?://(?:www\.)?soundgasm\.net/u/(?P<id>[0-9a-zA-Z_\-]+)/?$'
  38. _TEST = {
  39. 'url': 'http://soundgasm.net/u/ytdl',
  40. 'playlist_count': 1,
  41. 'info_dict': {
  42. '_type': 'playlist',
  43. 'id': 'ytdl',
  44. 'title': 'ytdl'
  45. }
  46. }
  47. def _real_extract(self, url):
  48. profile_id = self._match_id(url)
  49. webpage = self._download_webpage(url, profile_id)
  50. ids = re.findall(r'''<a\s+href=".+?/u/%s/([^/]+)">''' % re.escape(profile_id), webpage)
  51. ids = [clean_html(id) for id in ids]
  52. entries = []
  53. for id in ids:
  54. entries.append({
  55. '_type': 'url',
  56. 'url': ('http://soundgasm.net/u/%s/%s' % (profile_id, id))
  57. })
  58. info_dict = {
  59. '_type': 'playlist',
  60. 'id': profile_id,
  61. 'title': profile_id,
  62. 'entries': entries
  63. }
  64. return info_dict;