Skip to content

soundcloud

SoundCloud module for downloading and searching songs.

SoundCloud(*args, **kwargs) ¤

Bases: AudioProvider

SoundCloud audio provider class

Arguments¤
  • args: Arguments passed to the AudioProvider class.
  • kwargs: Keyword arguments passed to the AudioProvider class.
Source code in spotdl/providers/audio/soundcloud.py
29
30
31
32
33
34
35
36
37
38
39
def __init__(self, *args: Any, **kwargs: Any) -> None:
    """
    Initialize the SoundCloud API

    ### Arguments
    - args: Arguments passed to the `AudioProvider` class.
    - kwargs: Keyword arguments passed to the `AudioProvider` class.
    """

    super().__init__(*args, **kwargs)
    self.client = SoundCloudClient()

get_results(search_term, *_args, **_kwargs) ¤

Get results from slider.kz

Arguments¤
  • search_term: The search term to search for.
  • args: Unused.
  • kwargs: Unused.
Returns¤
  • A list of slider.kz results if found, None otherwise.
Source code in spotdl/providers/audio/soundcloud.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def get_results(self, search_term: str, *_args, **_kwargs) -> List[Result]:
    """
    Get results from slider.kz

    ### Arguments
    - search_term: The search term to search for.
    - args: Unused.
    - kwargs: Unused.

    ### Returns
    - A list of slider.kz results if found, None otherwise.
    """

    results = list(islice(self.client.search(search_term), 20))
    regex = r"^(.+?)-|(\(\w+[\s\S]*\))"
    # Because anyone can post on soundcloud, we do another search with an edited search
    # The regex removes anything in brackets and the artist(s)'s name(s) if in the name
    edited_search_term = re.sub(regex, "", search_term)
    results.extend(list(islice(self.client.search(edited_search_term), 20)))

    # Simplify results
    simplified_results = []
    for result in results:
        if not isinstance(result, Track):
            continue

        # Ignore results that are not playable
        if "/preview/" in result.media.transcodings[0].url:
            continue

        album = self.client.get_track_albums(result.id)

        try:
            album_name = next(album).title
        except StopIteration:
            album_name = None

        simplified_results.append(
            Result(
                source="soundcloud",
                url=result.permalink_url,
                name=result.title,
                verified=result.user.verified,
                duration=result.full_duration,
                author=result.user.username,
                result_id=str(result.id),
                isrc_search=False,
                search_query=search_term,
                views=result.playback_count,
                explicit=False,
                album=album_name,
            )
        )

    return simplified_results