logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

freesound.py (2496B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. get_element_by_class,
  7. get_element_by_id,
  8. unified_strdate,
  9. )
  10. class FreesoundIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?freesound\.org/people/[^/]+/sounds/(?P<id>[^/]+)'
  12. _TEST = {
  13. 'url': 'http://www.freesound.org/people/miklovan/sounds/194503/',
  14. 'md5': '12280ceb42c81f19a515c745eae07650',
  15. 'info_dict': {
  16. 'id': '194503',
  17. 'ext': 'mp3',
  18. 'title': 'gulls in the city.wav',
  19. 'description': 'the sounds of seagulls in the city',
  20. 'duration': 130.233,
  21. 'uploader': 'miklovan',
  22. 'upload_date': '20130715',
  23. 'tags': list,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. audio_id = self._match_id(url)
  28. webpage = self._download_webpage(url, audio_id)
  29. audio_url = self._og_search_property('audio', webpage, 'song url')
  30. title = self._og_search_property('audio:title', webpage, 'song title')
  31. description = self._html_search_regex(
  32. r'(?s)id=["\']sound_description["\'][^>]*>(.+?)</div>',
  33. webpage, 'description', fatal=False)
  34. duration = float_or_none(
  35. get_element_by_class('duration', webpage), scale=1000)
  36. upload_date = unified_strdate(get_element_by_id('sound_date', webpage))
  37. uploader = self._og_search_property(
  38. 'audio:artist', webpage, 'uploader', fatal=False)
  39. channels = self._html_search_regex(
  40. r'Channels</dt><dd>(.+?)</dd>', webpage,
  41. 'channels info', fatal=False)
  42. tags_str = get_element_by_class('tags', webpage)
  43. tags = re.findall(r'<a[^>]+>([^<]+)', tags_str) if tags_str else None
  44. audio_urls = [audio_url]
  45. LQ_FORMAT = '-lq.mp3'
  46. if LQ_FORMAT in audio_url:
  47. audio_urls.append(audio_url.replace(LQ_FORMAT, '-hq.mp3'))
  48. formats = [{
  49. 'url': format_url,
  50. 'format_note': channels,
  51. 'quality': quality,
  52. } for quality, format_url in enumerate(audio_urls)]
  53. self._sort_formats(formats)
  54. return {
  55. 'id': audio_id,
  56. 'title': title,
  57. 'description': description,
  58. 'duration': duration,
  59. 'uploader': uploader,
  60. 'upload_date': upload_date,
  61. 'tags': tags,
  62. 'formats': formats,
  63. }