From bc8745480e1b0a561030dd8b7c392ef83e573c5d Mon Sep 17 00:00:00 2001 From: Ashish <39122144+Ashish0804@users.noreply.github.com> Date: Tue, 10 Aug 2021 18:42:11 +0530 Subject: [PATCH] [BandCamp] Add BandcampMusicIE (#668) Authored by Ashish0804 --- yt_dlp/extractor/bandcamp.py | 42 +++++++++++++++++++++++++++++++++- yt_dlp/extractor/extractors.py | 7 +++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/yt_dlp/extractor/bandcamp.py b/yt_dlp/extractor/bandcamp.py index 006aab3b4..07ceaa0fe 100644 --- a/yt_dlp/extractor/bandcamp.py +++ b/yt_dlp/extractor/bandcamp.py @@ -212,7 +212,7 @@ class BandcampIE(InfoExtractor): class BandcampAlbumIE(BandcampIE): IE_NAME = 'Bandcamp:album' - _VALID_URL = r'https?://(?:(?P[^.]+)\.)?bandcamp\.com(?:/album/(?P[^/?#&]+))?' + _VALID_URL = r'https?://(?:(?P[^.]+)\.)?bandcamp\.com(?!/music)(?:/album/(?P[^/?#&]+))?' _TESTS = [{ 'url': 'http://blazo.bandcamp.com/album/jazz-format-mixtape-vol-1', @@ -389,3 +389,43 @@ class BandcampWeeklyIE(BandcampIE): 'episode_id': show_id, 'formats': formats } + + +class BandcampMusicIE(InfoExtractor): + _VALID_URL = r'https?://(?P[^/]+)\.bandcamp\.com/music' + _TESTS = [{ + 'url': 'https://steviasphere.bandcamp.com/music', + 'playlist_mincount': 47, + 'info_dict': { + 'id': 'steviasphere', + }, + }, { + 'url': 'https://coldworldofficial.bandcamp.com/music', + 'playlist_mincount': 10, + 'info_dict': { + 'id': 'coldworldofficial', + }, + }, { + 'url': 'https://nuclearwarnowproductions.bandcamp.com/music', + 'playlist_mincount': 399, + 'info_dict': { + 'id': 'nuclearwarnowproductions', + }, + } + ] + + _TYPE_IE_DICT = { + 'album': BandcampAlbumIE.ie_key(), + 'track': BandcampIE.ie_key() + } + + def _real_extract(self, url): + id = self._match_id(url) + webpage = self._download_webpage(url, id) + items = re.findall(r'href\=\"\/(?P(?Palbum|track)+/[^\"]+)', webpage) + entries = [ + self.url_result( + f'https://{id}.bandcamp.com/{item[0]}', + ie=self._TYPE_IE_DICT[item[1]]) + for item in items] + return self.playlist_result(entries, id) diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py index efb3235b1..975fb0328 100644 --- a/yt_dlp/extractor/extractors.py +++ b/yt_dlp/extractor/extractors.py @@ -109,7 +109,12 @@ from .awaan import ( from .azmedien import AZMedienIE from .baidu import BaiduVideoIE from .bandaichannel import BandaiChannelIE -from .bandcamp import BandcampIE, BandcampAlbumIE, BandcampWeeklyIE +from .bandcamp import ( + BandcampIE, + BandcampAlbumIE, + BandcampWeeklyIE, + BandcampMusicIE, +) from .bbc import ( BBCCoUkIE, BBCCoUkArticleIE,