Collection
The collection
package contains modules:
base_collection
: abstraction for Collectionbase_playlist
: abstraction for Playlistbase_track
: abstraction for Trackconfig
: the configuration object for thecollection
packagecopy_playlists
: copies audio files for tracks within a set of playlists to a new location and writes a new collection with these updated pathshelpers
: contains helper classes and functions for the other modules of this packageplaylist_builder
: constructs playlists using tags in a Collection and a defined playlist structure incollection_playlists.yaml
playlist_filters
: abstractions and implementations for playlist filtersplaylists
: abstractions and implementations for playlistsrekordbox_collection
: implementation of Collection for Rekordboxrekordbox_playlist
: implementation of Playlist for Rekordboxrekordbox_track
: implementation of Track for Rekordboxshuffle_playlists
: writes sequential numbers to tags of shuffled tracks in playlists to emulate playlist shufflingtracks
: abstractions and implementations for tracks
RekordboxCollection
Bases: Collection
Collection implementation for usage with Rekordbox.
Source code in djtools/collection/rekordbox_collection.py
24 25 26 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 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 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 188 189 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 |
|
__init__(path)
Deserializes a Collection from an XML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to a serialized collection. |
required |
Source code in djtools/collection/rekordbox_collection.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 |
|
__repr__()
Produce a string representation of this Collection.
Returns:
Type | Description |
---|---|
str
|
Collection represented as a string. |
Source code in djtools/collection/rekordbox_collection.py
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 96 97 98 99 100 101 102 103 104 105 |
|
serialize(*args, path=None, **kwargs)
Serializes this Collection as an XML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Path]
|
Path to output serialized collection to. |
None
|
Returns:
Type | Description |
---|---|
Path
|
Path to the serialized collection XML file. |
Source code in djtools/collection/rekordbox_collection.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 188 189 190 191 192 193 194 195 |
|
validate(input_xml, output_xml)
classmethod
Validate the serialized Collection matches the original.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_xml
|
Path
|
Path to an XML containing the original collection. |
required |
output_xml
|
Path
|
Path to an XML containing the serialized collection. |
required |
Raises:
Type | Description |
---|---|
AssertionError
|
A serialized Collection must exactly match the original XML used to deserialize from. |
Source code in djtools/collection/rekordbox_collection.py
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 |
|
RekordboxPlaylist
Bases: Playlist
Playlist implementation for usage with Rekordbox.
Source code in djtools/collection/rekordbox_playlist.py
20 21 22 23 24 25 26 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 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 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 188 189 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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
__init__(playlist, *args, tracks=None, playlist_tracks=None, parent=None, **kwargs)
Deserialize a Playlist from a BeautifulSoup NODE Tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Tag
|
BeautifulSoup Tag representing a playlist. |
required |
tracks
|
Dict[str, RekordboxTrack]
|
All the tracks in this collection. |
None
|
playlist_tracks
|
Optional[Dict[str, RekordboxTrack]]
|
Tracks to set when initializing with new_playlist. |
None
|
parent
|
Optional[RekordboxPlaylist]
|
The folder this playlist is in. |
None
|
Source code in djtools/collection/rekordbox_playlist.py
23 24 25 26 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 |
|
__repr__()
Produces a string representation of this playlist.
Returns:
Type | Description |
---|---|
str
|
Playlist represented as a string. |
Source code in djtools/collection/rekordbox_playlist.py
74 75 76 77 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 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 |
|
__str__()
Produce a string representation of this playlist.
Returns:
Type | Description |
---|---|
str
|
Playlist represented as a string. |
Source code in djtools/collection/rekordbox_playlist.py
156 157 158 159 160 161 162 |
|
get_name()
Returns the name of this playlist.
Returns:
Type | Description |
---|---|
str
|
The name of this playlist. |
Source code in djtools/collection/rekordbox_playlist.py
164 165 166 167 168 169 170 |
|
is_folder()
Returns whether this playlist is a folder or a playlist of tracks.
Returns:
Type | Description |
---|---|
bool
|
Boolean representing whether this is a folder or not. |
Source code in djtools/collection/rekordbox_playlist.py
172 173 174 175 176 177 178 |
|
new_playlist(name, playlists=None, tracks=None, enable_aggregation=None)
classmethod
Creates a new playlist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the Playlist to be created. |
required |
playlists
|
Optional[List[RekordboxPlaylist]]
|
A list of Playlists to add to this Playlist. |
None
|
tracks
|
Optional[Dict[str, RekordboxTrack]]
|
A dict of Tracks to add to this Playlist. |
None
|
enable_aggregation
|
Optional[bool]
|
Whether or not this playlist has an aggregation playlist. |
None
|
Raises:
Type | Description |
---|---|
RuntimeError
|
You must provide either a list of Playlists or a list of Tracks. |
RuntimeError
|
You must not provide both a list of Playlists and a list of Tracks. |
Returns:
Type | Description |
---|---|
RekordboxPlaylist
|
A new playlist. |
Source code in djtools/collection/rekordbox_playlist.py
180 181 182 183 184 185 186 187 188 189 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 |
|
serialize(*args, **kwargs)
Serializes this playlist as a BeautifulSoup NODE Tag.
Returns:
Type | Description |
---|---|
Tag
|
BeautifulSoup Tag representing this playlist. |
Source code in djtools/collection/rekordbox_playlist.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
RekordboxTrack
Bases: Track
Track implementation for usage with Rekordbox.
Source code in djtools/collection/rekordbox_track.py
23 24 25 26 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 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 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 188 189 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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
__init__(track)
Deserialize a track from a BeautifulSoup TRACK Tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track
|
Tag
|
BeautifulSoup Tag representing a track. |
required |
Source code in djtools/collection/rekordbox_track.py
26 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 |
|
__repr__()
Produces a string representation of this track.
Returns:
Type | Description |
---|---|
str
|
Track represented as a string. |
Source code in djtools/collection/rekordbox_track.py
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 |
|
__str__()
Produces a string representation of this track.
Returns:
Type | Description |
---|---|
str
|
Track represented as a string. |
Source code in djtools/collection/rekordbox_track.py
144 145 146 147 148 149 150 |
|
get_artists()
Gets the track artists.
Returns:
Type | Description |
---|---|
str
|
A string representing the track's artists. |
Source code in djtools/collection/rekordbox_track.py
152 153 154 155 156 157 158 |
|
get_bpm()
Gets the track BPM.
Returns:
Type | Description |
---|---|
float
|
A float representing BPM. |
Source code in djtools/collection/rekordbox_track.py
160 161 162 163 164 165 166 |
|
get_comments()
Gets the track comments.
Returns:
Type | Description |
---|---|
str
|
A string representing the track's comments. |
Source code in djtools/collection/rekordbox_track.py
168 169 170 171 172 173 174 |
|
get_date_added()
Gets the track's date added.
Returns:
Type | Description |
---|---|
str
|
A datetime representing the track's date added. |
Source code in djtools/collection/rekordbox_track.py
176 177 178 179 180 181 182 |
|
get_genre_tags()
Gets the genre tags of the track.
Returns:
Type | Description |
---|---|
List[str]
|
A list of the track's genre tags. |
Source code in djtools/collection/rekordbox_track.py
184 185 186 187 188 189 190 |
|
get_id()
Get the track ID.
Returns:
Type | Description |
---|---|
str
|
The ID of this track. |
Source code in djtools/collection/rekordbox_track.py
192 193 194 195 196 197 198 |
|
get_key()
Gets the track key.
Returns:
Type | Description |
---|---|
Any
|
The key of this track. |
Source code in djtools/collection/rekordbox_track.py
200 201 202 203 204 205 206 |
|
get_label()
Gets the track label.
Returns:
Type | Description |
---|---|
Any
|
The label of this track. |
Source code in djtools/collection/rekordbox_track.py
208 209 210 211 212 213 214 |
|
get_location()
Gets the location of the track.
Returns:
Type | Description |
---|---|
Path
|
The Path for the location of the track. |
Source code in djtools/collection/rekordbox_track.py
216 217 218 219 220 221 222 |
|
get_rating()
Gets the rating of the track.
Returns:
Type | Description |
---|---|
int
|
The rating of the track. |
Source code in djtools/collection/rekordbox_track.py
224 225 226 227 228 229 230 |
|
get_tags()
Gets the tags of the track.
Returns:
Type | Description |
---|---|
List[str]
|
A set of the track's tags. |
Source code in djtools/collection/rekordbox_track.py
232 233 234 235 236 237 238 |
|
get_year()
Gets the year of the track.
Returns:
Type | Description |
---|---|
str
|
The year of the track. |
Source code in djtools/collection/rekordbox_track.py
240 241 242 243 244 245 246 |
|
serialize(*args, playlist=False, **kwargs)
Serializes this track as a BeautifulSoup TRACK Tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
bool
|
Whether or not to serialize this track as a member of a playlist. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
The DateAdded attribute must serialize into its original format. |
Returns:
Type | Description |
---|---|
Tag
|
BeautifulSoup Tag representing this track. |
Source code in djtools/collection/rekordbox_track.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
set_location(location)
Sets the path of the track to location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location
|
Path
|
New location of the track. |
required |
Source code in djtools/collection/rekordbox_track.py
371 372 373 374 375 376 377 378 |
|
set_track_number(number)
Sets the track number of a track.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
number
|
int
|
Number to set for TrackNumber. |
required |
Source code in djtools/collection/rekordbox_track.py
380 381 382 383 384 385 386 |
|
collection_playlists(config, path=None)
Builds playlists automatically.
By maintaining a collection with tracks having tag data (e.g. genre tags, Rekordbox's "My Tags", etc.) and providing a playlist config which specifies a desired playlist structure based around these tags, users can automatically generate that playlist structure.
The playlist config is a YAML file which specifies a nested structure of folders. Each folder is declared with a "name" and a list of "playlists" which may be either more folder declarations or else strings matching a tag in your collection.
Any folder that has more than one playlist within it will automatically
have an "All
Any tag in your collection that is not specified in the playlist config will automatically be added to either an "Other" folder of playlists or an "Other" playlist (depending on your configured choice for collection_playlists_remainder).
A special folder with the name "_ignore" may be included anywhere within the "tags" specification with playlists matching the set of tags to ignore when creating the "Other" folder / playlist.
In addition to creating playlists from tags, this function also supports creating "combiner" playlists by evaluating boolean algebra expressions. This is an incredibly powerful feature which allows users to apply set operations {union, intersection, and difference} to a diverse range of operands {tag, playlists, BPMs, ratings, etc.}.
Combiner playlists are declared in the "combiner" specification of the playlist config with playlists whose names are the boolean algebra expressions used to construct them.
Here's an example combiner playlist to illustrate this:
((Dubstep ~ [1-3]) | {playlist: My Favorites} | (*Techno & [135-145])) & Dark
The resulting combiner playlist will be comprised of tracks that are:
- tagged as "Dubstep" but NOT having a rating less than 4
- OR in the playlist called "My Favorites"
- OR tagged as something ending with "Techno" AND in the BPM range of 135 to 145
- AND tagged as "Dark"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
path
|
Optional[Path]
|
Path to write the new collection to. |
None
|
Source code in djtools/collection/playlist_builder.py
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 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 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 188 189 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 |
|
This module contains the configuration objects for the collection package. The attributes of this configuration object correspond with the "collection" key of config.yaml
CollectionConfig
Bases: BaseConfigFormatter
Configuration object for the collection package.
Source code in djtools/collection/config.py
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
__init__(*args, **kwargs)
Constructor.
Raises:
Type | Description |
---|---|
RuntimeError
|
Using the collection package requires a valid collection_path. |
RuntimeError
|
Failed to render collection_playlist.yaml from template. |
RuntimeError
|
collection_path must be a valid collection path. |
RuntimeError
|
collection_playlists.yaml must be a valid YAML file. |
Source code in djtools/collection/config.py
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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
PlaylistConfig
Bases: BaseModel
A class for type checking the playlist config YAML.
Source code in djtools/collection/config.py
197 198 199 200 |
|
PlaylistConfigContent
Bases: BaseModel
A class for type checking the content of the playlist config YAML.
Source code in djtools/collection/config.py
190 191 192 193 194 |
|
PlaylistFilters
Bases: Enum
PlaylistFilters enum.
Source code in djtools/collection/config.py
21 22 23 24 25 26 27 |
|
PlaylistName
Bases: BaseModel
A class for configuring the names of playlists.
Source code in djtools/collection/config.py
184 185 186 187 |
|
PlaylistRemainder
Bases: Enum
PlaylistRemainder enum.
Source code in djtools/collection/config.py
46 47 48 49 50 |
|
RegisteredPlatforms
Bases: Enum
RegisteredPlatforms enum.
Source code in djtools/collection/config.py
67 68 69 70 |
|
This module is used to automatically generate a playlist structure.
collection_playlists(config, path=None)
Builds playlists automatically.
By maintaining a collection with tracks having tag data (e.g. genre tags, Rekordbox's "My Tags", etc.) and providing a playlist config which specifies a desired playlist structure based around these tags, users can automatically generate that playlist structure.
The playlist config is a YAML file which specifies a nested structure of folders. Each folder is declared with a "name" and a list of "playlists" which may be either more folder declarations or else strings matching a tag in your collection.
Any folder that has more than one playlist within it will automatically
have an "All
Any tag in your collection that is not specified in the playlist config will automatically be added to either an "Other" folder of playlists or an "Other" playlist (depending on your configured choice for collection_playlists_remainder).
A special folder with the name "_ignore" may be included anywhere within the "tags" specification with playlists matching the set of tags to ignore when creating the "Other" folder / playlist.
In addition to creating playlists from tags, this function also supports creating "combiner" playlists by evaluating boolean algebra expressions. This is an incredibly powerful feature which allows users to apply set operations {union, intersection, and difference} to a diverse range of operands {tag, playlists, BPMs, ratings, etc.}.
Combiner playlists are declared in the "combiner" specification of the playlist config with playlists whose names are the boolean algebra expressions used to construct them.
Here's an example combiner playlist to illustrate this:
((Dubstep ~ [1-3]) | {playlist: My Favorites} | (*Techno & [135-145])) & Dark
The resulting combiner playlist will be comprised of tracks that are:
- tagged as "Dubstep" but NOT having a rating less than 4
- OR in the playlist called "My Favorites"
- OR tagged as something ending with "Techno" AND in the BPM range of 135 to 145
- AND tagged as "Dark"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
path
|
Optional[Path]
|
Path to write the new collection to. |
None
|
Source code in djtools/collection/playlist_builder.py
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 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 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 188 189 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 |
|
This module contains the PlaylistFilter abstract base class and its implementations.
PlaylistFilter subclasses implement an 'is_filter_playlist' method and a 'filter_track' method.
The 'is_filter_playlist' method, when given a 'Playlist', returns true if that 'Playlist' should have its tracks filtered.
The 'filter_track' method, when given a 'Track', returns true if that 'Track' should remain in the playlist.
ComplexTrackFilter
Bases: PlaylistFilter
This class filters "complex" playlists.
This PlaylistFilter looks for playlists with "complex" in their name or in the name of a parent playlist. When found, tracks contained in the playlist must have no less than 'min_tags_for_complex_track' in order to remain in the playlist.
Source code in djtools/collection/playlist_filters.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 |
|
__init__(min_tags_for_complex_track=3, exclude_tags=None)
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_tags_for_complex_track
|
Optional[int]
|
Maximum number of non-genre tags before a track is no longer considered "complex". |
3
|
exclude_tags
|
Optional[List[str]]
|
Tags to ignore when determining the number of non-genre tags. |
None
|
Source code in djtools/collection/playlist_filters.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
filter_track(track)
Returns True if this track should remain in the playlist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track
|
Track
|
Track object to apply filter to. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not this track should be included in the playlist. |
Source code in djtools/collection/playlist_filters.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
is_filter_playlist(playlist)
Returns True if this playlist should be filtered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Playlist
|
Playlist object to potentially filter. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not to filter this playlist. |
Source code in djtools/collection/playlist_filters.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
HipHopFilter
Bases: PlaylistFilter
This class filters playlists called "Hip Hop".
Source code in djtools/collection/playlist_filters.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 95 96 97 98 99 100 101 102 103 104 |
|
filter_track(track)
Returns True if this track should remain in the playlist.
If the playlist is not underneath a folder called "Bass", then this track is filtered out unless it has exclusively "Hip Hop" and "R&B" genre tags. If the playlist is underneath a folder called "Bass", then this track is filtered out if it does have exclusively "Hip Hop" and "R&B" genre tags.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track
|
Track
|
Track object to apply filter to. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not this track should be included in the playlist. |
Source code in djtools/collection/playlist_filters.py
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 |
|
is_filter_playlist(playlist)
Returns True if this playlist's name is "Hip Hop".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Playlist
|
Playlist object to potentially filter. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not to filter this playlist. |
Source code in djtools/collection/playlist_filters.py
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 |
|
MinimalDeepTechFilter
Bases: PlaylistFilter
This class filters playlists called "Minimal Deep Tech".
Source code in djtools/collection/playlist_filters.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 |
|
filter_track(track)
Returns True if this track should remain in the playlist.
If the playlist is not underneath a folder called "Techno", then this track is filtered out if there's another genre tag containing "Techno". If the playlist is underneath a folder called "Techno", then this track is filtered out if there's no other genre tag containing "Techno".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track
|
Track
|
Track object to apply filter to. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not this track should be included in the playlist. |
Source code in djtools/collection/playlist_filters.py
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 |
|
is_filter_playlist(playlist)
Returns True if this playlist's name is "Minimal Deep Tech".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Playlist
|
Playlist object to potentially filter. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not to filter this playlist. |
Source code in djtools/collection/playlist_filters.py
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 |
|
PlaylistFilter
Bases: ABC
This class defines an interface for filtering tracks from playlists.
Source code in djtools/collection/playlist_filters.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
filter_track(track)
abstractmethod
Returns True if this track should remain in the playlist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track
|
Track
|
Track object to apply filter to. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not this track should be included in the playlist. |
Source code in djtools/collection/playlist_filters.py
25 26 27 28 29 30 31 32 33 34 |
|
is_filter_playlist(playlist)
abstractmethod
Returns True if this playlist should be filtered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Playlist
|
Playlist object to potentially filter. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not to filter this playlist. |
Source code in djtools/collection/playlist_filters.py
36 37 38 39 40 41 42 43 44 45 |
|
TransitionTrackFilter
Bases: PlaylistFilter
This class filters "transition" playlists.
This PlaylistFilter looks for playlists with "transition" in their name or in the name of a parent playlist. When found, tracks contained in the playlist must have a square bracket enclosed set of transition tokens (forward-slash delimited list of floats, for BPMs, or otherwise, for genres).
Source code in djtools/collection/playlist_filters.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
__init__(separator='/')
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
separator
|
Optional[str]
|
Character used to separate transition tokens. |
'/'
|
Source code in djtools/collection/playlist_filters.py
257 258 259 260 261 262 263 264 265 |
|
filter_track(track)
Returns True if this track should remain in the playlist.
Matches square bracket enclosed tokens representing transitions for supported playlist types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track
|
Track
|
Track object to apply filter to. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not this track should be included in the playlist. |
Source code in djtools/collection/playlist_filters.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
is_filter_playlist(playlist)
Returns True if this playlist should be filtered.
Identifies playlists with a supported transition playlist type in its name while also having a parent playlist with "transition" in its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Playlist
|
Playlist object to potentially filter. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not to filter this playlist. |
Source code in djtools/collection/playlist_filters.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
This module is used to emulate shuffling the track order of one or more playlists. This is done by setting the track number attribute of each track in sequential order after collecting the set of Tracks from the provided playlist(s).
shuffle_playlists(config, path=None)
For each playlist in "shuffle_playlists", randomize the tracks and sequentially set the track number to emulate shuffling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
path
|
Optional[Path]
|
Path to write the new collection to. |
None
|
Source code in djtools/collection/shuffle_playlists.py
24 25 26 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 |
|
This module is used to copy the audio files from the provided playlists to a new location and serialize a new collection with those tracks pointing to these new locations.
The purpose of this utility is to:
- backup subsets of your library
- ensure you have easy access to a preparation independent of the setup
copy_playlists(config, path=None)
Copies tracks from provided playlists to a destination.
Serializes the collection with these playlists and updated locations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
BaseConfig
|
Configuration object. |
required |
path
|
Optional[Path]
|
Path to write the new collection to. |
None
|
Raises:
Type | Description |
---|---|
LookupError
|
Playlist names in copy_playlists must exist in "collection_path". |
Source code in djtools/collection/copy_playlists.py
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
This module contains helpers for the collection package.
BooleanNode
Node that contains boolean logic for a sub-expression.
Source code in djtools/collection/helpers.py
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
|
__init__(tags_tracks, parent=None)
Constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags_tracks
|
Dict[str, Dict[str, Track]]
|
Dict of tags to tracks. |
required |
parent
|
Optional[BooleanNode]
|
BooleanNode of which this node is a sub-expression. |
None
|
Source code in djtools/collection/helpers.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
|
add_operand(operand)
Add operand to BooleanNode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operand
|
str
|
Tag or track set to be evaluated. |
required |
Returns:
Type | Description |
---|---|
str
|
Empty string to reset tag in the parse_expression function. |
Source code in djtools/collection/helpers.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
|
add_operator(operator)
Adds a set operation to the BooleanNode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
str
|
Character representing a set operation. |
required |
Source code in djtools/collection/helpers.py
775 776 777 778 779 780 781 |
|
evaluate()
Applies operators to the operands to produce a dict of tracks.
Raises:
Type | Description |
---|---|
RuntimeError
|
The boolean expression is malformed. It must contain one less operator than there are operands. |
Returns:
Type | Description |
---|---|
Dict[str, Track]
|
A dict of tracks reduced from the boolean expression. |
Source code in djtools/collection/helpers.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 |
|
get_parent()
Gets the parent of the BooleanNode.
Returns:
Type | Description |
---|---|
BooleanNode
|
Parent BooleanNode. |
Source code in djtools/collection/helpers.py
825 826 827 828 829 830 831 |
|
is_operator(char)
Checks if a character is one that represents a set operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
char
|
str
|
Character that may represent a set operation. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether or not the character is an operator. |
Source code in djtools/collection/helpers.py
833 834 835 836 837 838 839 840 841 842 |
|
add_selectors_to_tags(content, tags_tracks, collection, auto_playlists)
Recursively update the track lookup with selectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
Union[PlaylistConfigContent, PlaylistName, str]
|
A component of a playlist config to create a playlist for. |
required |
tags_tracks
|
Dict[str, Dict[str, Track]]
|
Dict of tags to tracks. |
required |
collection
|
Collection
|
Collection object. |
required |
auto_playlists
|
List[Playlist]
|
Tag playlists built in this same run. |
required |
Source code in djtools/collection/helpers.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
aggregate_playlists(playlist, playlist_class, minimum_tracks=None)
Recursively aggregate tracks from folders into "All" playlists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Playlist
|
Playlist which may be a folder or not. |
required |
playlist_class
|
Playlist
|
Playlist implementation class. |
required |
minimum_tracks
|
Optional[int]
|
Required number of tracks to make a playlist. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Track]
|
Dict of tracks. |
Source code in djtools/collection/helpers.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
build_combiner_playlists(content, tags_tracks, playlist_class, minimum_tracks=None)
Recursively traverses a playlist config to generate playlists from tags.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
Union[PlaylistConfig, PlaylistName, str]
|
A component of a playlist config to create a playlist for. |
required |
tags_tracks
|
Dict[str, Dict[str, Track]]
|
Dict of tags to tracks. |
required |
playlist_class
|
Playlist
|
Playlist implementation class. |
required |
minimum_tracks
|
Optional[int]
|
Required number of tracks to make a playlist. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
The user's playlist config must not be malformed. |
Returns:
Type | Description |
---|---|
Optional[Playlist]
|
A Playlist or None. |
Source code in djtools/collection/helpers.py
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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 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 |
|
build_tag_playlists(content, tags_tracks, playlist_class, tag_set=None, minimum_tracks=None)
Recursively traverses a playlist config to generate playlists from tags.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
Union[PlaylistConfigContent, PlaylistName, str]
|
A component of a playlist config to create a playlist for. |
required |
tags_tracks
|
Dict[str, Dict[str, Track]]
|
Dict of tags to tracks. |
required |
playlist_class
|
Playlist
|
Playlist implementation class. |
required |
tag_set
|
Optional[Set]
|
A set of tags seen while creating playlists. This is used to indicate which tags should be ignored when creating the "Unused Tags" playlists. |
None
|
minimum_tracks
|
Optional[int]
|
Required number of tracks to make a playlist. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
The user's playlist config must not be malformed. |
Returns:
Type | Description |
---|---|
Optional[Playlist]
|
A Playlist or None. |
Source code in djtools/collection/helpers.py
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 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 188 189 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 |
|
copy_file(track, destination)
Copies a track to a destination and updates its location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track
|
Track
|
Track object. |
required |
destination
|
Path
|
Directory to copy tracks to. |
required |
Source code in djtools/collection/helpers.py
51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
filter_tag_playlists(playlist, playlist_filters)
Applies a list of PlaylistFilter implementations to the playlist.
If the PlaylistFilter implementations' is_filter_playlist method evaluates to True, then the filter_track method is applied to each track in the playlist. The playlist's tracks are set to remove the tracks that have been filtered out.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playlist
|
Playlist
|
Playlist to potentially have its tracks filtered. |
required |
playlist_filters
|
List[PlaylistFilter]
|
A list of PlaylistFilter implementations used to filter playlist tracks. |
required |
Source code in djtools/collection/helpers.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
parse_expression(expression, tags_tracks)
Parses a boolean algebra expression by constructing a tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression
|
str
|
String representing boolean algebra expression. |
required |
tags_tracks
|
Dict[str, Dict[str, Track]]
|
Dict of tags to tracks. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Track]
|
Dict of track IDs and tracks. |
Source code in djtools/collection/helpers.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
|
parse_numerical_selectors(numerical_matches, numerical_value_lookup)
Parses a string match of one or more numerical selectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numerical_matches
|
List[str]
|
List of numerical strings. |
required |
numerical_value_lookup
|
Dict[Union[str, Tuple], str]
|
Empty dict to populate with tuples or strings mapping numerical ranges or values to their "tag" representation. |
required |
Returns:
Type | Description |
---|---|
Set[str]
|
Set of numerical selector values. |
Source code in djtools/collection/helpers.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
parse_string_selectors(string_matches, string_value_lookup, string_selector_type_map, playlists)
Parses a string match of one or more string selectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_matches
|
List[str]
|
List of strings for string selectors. |
required |
string_value_lookup
|
Dict[Union[str, Tuple], str]
|
Empty dict to populate with strings mapping string selectors to their "tag" representation. |
required |
string_selector_type_map
|
Dict[str, str]
|
Maps a selector type to a Track method name. |
required |
playlists
|
Set[str]
|
Set for storing playlist names. |
required |
Source code in djtools/collection/helpers.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
|
parse_timedelta(time_str)
Parse a timedelta from a string and return the relative offset from now.
Supported units of time
- years
- months
- weeks
- days
Some example strings
- 1y
- 6m
- 3m2w
- 7d
Modified from peter's answer at https://stackoverflow.com/a/51916936
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_str
|
A string identifying a duration. |
required |
Returns:
Type | Description |
---|---|
Optional[datetime]
|
A datetime.datetime object. |
Source code in djtools/collection/helpers.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
|
print_data(data)
Prints an ASCII histogram of tag data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Dict[str, int]
|
Tag names to tag counts. |
required |
Source code in djtools/collection/helpers.py
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 |
|
print_playlists_tag_statistics(combiner_playlists)
Prints tag statistics for Combiner playlists.
Statistics are split out by Combiner playlist and then by TagParser type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
combiner_playlists
|
Playlist
|
Playlist object for Combiner playlists. |
required |
Source code in djtools/collection/helpers.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
|
scale_data(data, maximum=25)
Scales range of data values with an upper bound.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Dict[str, int]
|
Tag names to tag counts. |
required |
maximum
|
Optional[int]
|
Upper bound for re-scaled data. |
25
|
Returns:
Type | Description |
---|---|
Dict[str, int]
|
Re-scaled dictionary of tag names and tag counts. |
Source code in djtools/collection/helpers.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
|