From daf74314d743bba802321c1f61d601320a3c632f Mon Sep 17 00:00:00 2001 From: neodarz Date: Wed, 30 Sep 2020 08:56:56 +0200 Subject: Add soundcloud support --- extractors/common.py | 9 +++++++++ extractors/job.py | 3 ++- extractors/soundcloud.py | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 extractors/soundcloud.py diff --git a/extractors/common.py b/extractors/common.py index 0287496..019556c 100644 --- a/extractors/common.py +++ b/extractors/common.py @@ -9,12 +9,21 @@ class Extractor(): def __init__(self, reg, url): self.root = None + self.path = None if not reg: r = re.search(r'(^http(?:s|):(?:\/\/.*?\/|\/\/.*))', url) if r: self.root = r.group(1) + try: + self.path = r.group(2) + except IndexError: + pass if not self.root: self.root = reg.group(1) + try: + self.path = reg.group(2) + except IndexError: + pass self._albums = [] self.root_path = self._root_path() self._update_cache(self.root) diff --git a/extractors/job.py b/extractors/job.py index 795617a..8770500 100644 --- a/extractors/job.py +++ b/extractors/job.py @@ -6,7 +6,8 @@ import sys from utils import NoExtractorException extrs = [ - 'bandcamp' + 'bandcamp', + 'soundcloud', ] diff --git a/extractors/soundcloud.py b/extractors/soundcloud.py new file mode 100644 index 0000000..e7c7e0b --- /dev/null +++ b/extractors/soundcloud.py @@ -0,0 +1,18 @@ +import re +import logging +import requests +from bs4 import BeautifulSoup + +from .common import Extractor + +class soundcloud(Extractor): + pattern = re.compile(r'(http(?:s|):\/\/.*soundcloud.com)(.*)') + filename_template = "%(uploader)s/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s" + + def __init__(self, reg, url): + super().__init__(reg, url) + + def get_albums(self): + # We directly use youtube-dl soudcloud albums management + # (It download all songs by an artist + self._albums.append(self.root + self.path) -- cgit v1.2.1