freesound.py 1.1 KB

123456789101112131415161718192021222324252627
  1. # -*- coding: utf-8 -*-
  2. import re
  3. from .common import InfoExtractor
  4. class FreeSoundIE(InfoExtractor):
  5. _VALID_URL = r'(?:http://)?(?:www\.)?freesound\.org/people/([^/]+)/sounds/([^/]+)'
  6. def _real_extract(self, url):
  7. mobj = re.match(self._VALID_URL, url)
  8. music_id = mobj.group(2)
  9. webpage = self._download_webpage(url, music_id)
  10. title = self._html_search_regex(r'<meta property="og:title" content="([^"]*)"',
  11. webpage, 'music title')
  12. music_url = self._html_search_regex(r'<meta property="og:audio" content="([^"]*)"',
  13. webpage, 'music url')
  14. uploader = self._html_search_regex(r'<meta property="og:audio:artist" content="([^"]*)"',
  15. webpage, 'music uploader')
  16. ext = music_url.split('.')[-1]
  17. return [{
  18. 'id': music_id,
  19. 'title': title,
  20. 'url': music_url,
  21. 'uploader': uploader,
  22. 'ext': ext,
  23. }]