Skip to content

Commit

Permalink
[Epidemic Sound] add support for separate tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
realRobotix committed Nov 29, 2023
1 parent d8c1711 commit bf79f95
Showing 1 changed file with 62 additions and 12 deletions.
74 changes: 62 additions & 12 deletions youtube_dl/extractor/epidemicsound.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
from __future__ import unicode_literals

from .common import InfoExtractor
from ..utils import unified_timestamp
from ..utils import (
ExtractorError,
float_or_none,
txt_or_none,
unified_timestamp,
url_or_none,
traverse_obj,
str_or_none,
T,
)


class EpidemicSoundIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?epidemicsound\.com/track/(?P<id>[0-9a-zA-Z]+)'
_TEST = {
_TESTS = [{
'url': 'https://www.epidemicsound.com/track/yFfQVRpSPz/',
'md5': 'd98ff2ddb49e8acab9716541cbc9dfac',
'info_dict': {
Expand All @@ -20,18 +29,59 @@ class EpidemicSoundIE(InfoExtractor):
'timestamp': 1415320353,
'upload_date': '20141107',
}
}
},
{
'url': 'https://www.epidemicsound.com/track/mj8GTTwsZd/',
'md5': 'c82b745890f9baf18dc2f8d568ee3830',
'info_dict': {
'id': 'mj8GTTwsZd',
'ext': 'mp3',
'tags': ["liquid drum n bass", "energetic"],
'title': 'Noplace',
'duration': 237,
'thumbnail': 'https://cdn.epidemicsound.com/curation-assets/commercial-release-cover-images/11138/3000x3000.jpg',
'timestamp': 1694426482,
'upload_date': '20230911',
}
},
]

def _real_extract(self, url):
video_id = self._match_id(url)
json_data = self._download_json('https://www.epidemicsound.com/json/track/' + video_id, video_id)

return {
'id': video_id,
'url': json_data.get('stems').get('full').get('lqMp3Url'),
'tags': json_data.get('metadataTags'),
'title': json_data.get('title'),
'duration': json_data.get('length'),
'timestamp': unified_timestamp(json_data.get('added')),
'thumbnail': json_data.get('imageUrl'),
}
if not traverse_obj(json_data, ('stems', Ellipsis)):
raise ExtractorError('No downloadable content found')

formats = list(reversed([
{
'format_id': str_or_none(key),
'url': url_or_none(value.get('lqMp3Url'))
} for key, value in json_data.get('stems').items()
]))

for f in formats:
for key, value in f.items():
if value is None or key is None:
del f

if len(formats) == 0:
raise ExtractorError('No downloadable content found')

info = traverse_obj(json_data, {
'tags': ('metadataTags', Ellipsis, T(txt_or_none)),
'title': ('title', T(txt_or_none)),
'duration': ('length', T(float_or_none)),
'timestamp': ('added', T(unified_timestamp)),
'thumbnail': ('imageUrl', T(url_or_none))})

info['id'] = video_id
info['formats'] = formats

if not info.get('tags'):
del info['tags']

if not info.get('title'):
raise ExtractorError('No title found')

return info

0 comments on commit bf79f95

Please sign in to comment.