logo

youtube-dl

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

epidemicsound.py (3727B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. float_or_none,
  6. T,
  7. traverse_obj,
  8. txt_or_none,
  9. unified_timestamp,
  10. url_or_none,
  11. )
  12. class EpidemicSoundIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?epidemicsound\.com/track/(?P<id>[0-9a-zA-Z]+)'
  14. _TESTS = [{
  15. 'url': 'https://www.epidemicsound.com/track/yFfQVRpSPz/',
  16. 'md5': 'd98ff2ddb49e8acab9716541cbc9dfac',
  17. 'info_dict': {
  18. 'id': '45014',
  19. 'display_id': 'yFfQVRpSPz',
  20. 'ext': 'mp3',
  21. 'tags': ['foley', 'door', 'knock', 'glass', 'window', 'glass door knock'],
  22. 'title': 'Door Knock Door 1',
  23. 'duration': 1,
  24. 'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/default-sfx/3000x3000.jpg',
  25. 'timestamp': 1415320353,
  26. 'upload_date': '20141107',
  27. 'age_limit': None,
  28. # check that the "best" format was found, since test file MD5 doesn't
  29. # distinguish the formats
  30. 'format': 'full',
  31. },
  32. }, {
  33. 'url': 'https://www.epidemicsound.com/track/mj8GTTwsZd/',
  34. 'md5': 'c82b745890f9baf18dc2f8d568ee3830',
  35. 'info_dict': {
  36. 'id': '148700',
  37. 'display_id': 'mj8GTTwsZd',
  38. 'ext': 'mp3',
  39. 'tags': ['liquid drum n bass', 'energetic'],
  40. 'title': 'Noplace',
  41. 'duration': 237,
  42. 'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/11138/3000x3000.jpg',
  43. 'timestamp': 1694426482,
  44. 'release_timestamp': 1700535606,
  45. 'upload_date': '20230911',
  46. 'age_limit': None,
  47. 'format': 'full',
  48. },
  49. }]
  50. def _real_extract(self, url):
  51. video_id = self._match_id(url)
  52. json_data = self._download_json('https://www.epidemicsound.com/json/track/' + video_id, video_id)
  53. def fmt_or_none(f):
  54. if not f.get('format'):
  55. f['format'] = f.get('format_id')
  56. elif not f.get('format_id'):
  57. f['format_id'] = f['format']
  58. if not (f['url'] and f['format']):
  59. return
  60. if f.get('format_note'):
  61. f['format_note'] = 'track ID ' + f['format_note']
  62. f['preference'] = -1 if f['format'] == 'full' else -2
  63. return f
  64. formats = traverse_obj(json_data, (
  65. 'stems', T(dict.items), Ellipsis, {
  66. 'format': (0, T(txt_or_none)),
  67. 'format_note': (1, 's3TrackId', T(txt_or_none)),
  68. 'format_id': (1, 'stemType', T(txt_or_none)),
  69. 'url': (1, 'lqMp3Url', T(url_or_none)),
  70. }, T(fmt_or_none)))
  71. self._sort_formats(formats)
  72. info = traverse_obj(json_data, {
  73. 'id': ('id', T(txt_or_none)),
  74. 'tags': ('metadataTags', Ellipsis, T(txt_or_none)),
  75. 'title': ('title', T(txt_or_none)),
  76. 'duration': ('length', T(float_or_none)),
  77. 'timestamp': ('added', T(unified_timestamp)),
  78. 'thumbnail': (('imageUrl', 'cover'), T(url_or_none)),
  79. 'age_limit': ('isExplicit', T(lambda b: 18 if b else None)),
  80. 'release_timestamp': ('releaseDate', T(unified_timestamp)),
  81. }, get_all=False)
  82. info.update(traverse_obj(json_data, {
  83. 'categories': ('genres', Ellipsis, 'tag', T(txt_or_none)),
  84. 'tags': ('metadataTags', Ellipsis, T(txt_or_none)),
  85. }))
  86. info.update({
  87. 'display_id': video_id,
  88. 'formats': formats,
  89. })
  90. return info