Spotify
Configuration object for the spotify package.
The attributes of this configuration object correspond with the "spotify" key of config.yaml.
SpotifyConfig
Bases: BaseConfigFormatter
Configuration object for the spotify package.
Source code in src/djtools/spotify/config.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 | |
__init__(*args, **kwargs)
Constructor.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Spotify API credentials must exist and be valid. |
RuntimeError
|
Reddit API credentials must exist. |
Source code in src/djtools/spotify/config.py
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 | |
SubredditConfig
Bases: BaseModel
Configuration object for spotify_playlists.
Source code in src/djtools/spotify/config.py
18 19 20 21 22 23 24 | |
This module creates or updates Spotify playlists.
Playlists can be created from:
1. Discord webhook output from djtools.sync.sync_operations.upload_music
2. Subreddit posts (directly linked Spotify tracks or fuzzy-matched titles)
async_spotify_playlists(config)
async
Updates Spotify playlists from subreddit posts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
Source code in src/djtools/spotify/playlist_builder.py
39 40 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 | |
spotify_playlist_from_upload(config)
Generates a Spotify playlist from Discord webhook output.
Uses clipboard contents containing upload_music webhook output to create a Spotify playlist of those tracks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If clipboard is empty. |
Source code in src/djtools/spotify/playlist_builder.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
spotify_playlists(config)
Entry point for async Spotify playlist updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
Source code in src/djtools/spotify/playlist_builder.py
163 164 165 166 167 168 169 | |
This module contains helper functions used by the spotify module.
All Spotify API interactions are delegated to the spotify-tools library. This module provides DJ-Tools specific wrappers and configuration handling.
filter_results(spotify, results, threshold, title, artist)
Filter Spotify search results to find best matching track.
This function uses spotify-tools' search_track_fuzzy for matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spotify
|
Client
|
Spotify client. |
required |
results
|
Dict
|
Spotify search results (unused, kept for API compatibility). |
required |
threshold
|
float
|
Minimum Levenshtein distance. |
required |
title
|
str
|
Potential title of a track. |
required |
artist
|
str
|
Potential artist of a track. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Dict[str, Any], float]
|
Tuple of track object (as dict) and similarity score. |
Source code in src/djtools/spotify/helpers.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
get_playlist_ids()
Load Spotify playlist names -> IDs lookup.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dictionary of Spotify playlist names mapped to playlist IDs. |
Source code in src/djtools/spotify/helpers.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
get_reddit_client(config)
Instantiate a Reddit API client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
Returns:
| Type | Description |
|---|---|
Reddit
|
Reddit API client. |
Source code in src/djtools/spotify/helpers.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
get_spotify_client(config)
Instantiate a Spotify API client using spotify-tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Union[BaseConfig, DJToolsSpotifyConfig]
|
Configuration object. |
required |
Returns:
| Type | Description |
|---|---|
Client
|
Spotify API client. |
Source code in src/djtools/spotify/helpers.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
get_subreddit_posts(spotify, reddit, subreddit, config, praw_cache)
async
Filters subreddit submissions and resolves them to Spotify tracks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spotify
|
Client
|
Spotify client. |
required |
reddit
|
Reddit
|
Reddit client. |
required |
subreddit
|
SubredditConfig
|
SubredditConfig object. |
required |
config
|
BaseConfig
|
Configuration object. |
required |
praw_cache
|
Dict[str, bool]
|
Cached praw submissions. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[Tuple[str, str]], Dict[str, Union[str, int]]]
|
List of Spotify track ("id", "name") tuples and SubredditConfig. |
Source code in src/djtools/spotify/helpers.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
populate_playlist(playlist_name, playlist_ids, spotify_username, spotify, tracks, playlist_limit=None, verbosity=0)
Inserts tracks into either a new playlist or an existing one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
playlist_name
|
str
|
Name of the playlist. |
required |
playlist_ids
|
Dict[str, str]
|
Lookup of playlist IDs. |
required |
spotify_username
|
str
|
Spotify user's username. |
required |
spotify
|
Client
|
Spotify client. |
required |
tracks
|
List[Tuple[str, str]]
|
List of (track_id, track_name) tuples. |
required |
playlist_limit
|
Optional[int]
|
Maximum number of tracks allowed in a playlist. |
None
|
verbosity
|
int
|
Logging verbosity level. |
0
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Updated playlist IDs. |
Source code in src/djtools/spotify/helpers.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
write_playlist_ids(playlist_ids)
Write playlist IDs to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
playlist_ids
|
Dict[str, str]
|
Dictionary of Spotify playlist names mapped to playlist IDs. |
required |
Source code in src/djtools/spotify/helpers.py
259 260 261 262 263 264 265 266 267 268 269 270 | |