Libraryο
The core, basic library implementation which is just a simple set of folders.
Classes:
|
Represents a local library, providing various methods for manipulating tracks and playlists across an entire local library collection. |
- class musify.libraries.local.library.library.LocalLibrary(library_folders=None, playlist_folder=None, playlist_filter=(), path_mapper=PathMapper({}), remote_wrangler=None)ο
Bases:
LocalCollection
[LocalTrack
],Library
[LocalTrack
]Represents a local library, providing various methods for manipulating tracks and playlists across an entire local library collection.
- Parameters:
library_folders (
Union
[str
,Collection
[str
],None
] (default:None
)) β The absolute paths of the library folders containing all tracks. The intialiser will check for the existence of these paths and only store them if they exist.playlist_folder (
str
|None
(default:None
)) β The absolute path of the playlist folder containing all playlists or the relative path within one of the availablelibrary_folders
. If a relative path is given and many library folders are given, only the first path that gives an existing result is processed. The setter will check for the existence of this path and only store the absolute path if it exists.playlist_filter (
Union
[Collection
[str
],Filter
[str
]] (default:()
)) β An optionalFilter
to apply or collection of playlist names to include when loading playlists. Playlist names will be passed to this filter to limit which playlists are loaded.path_mapper (
PathMapper
(default:PathMapper({})
)) β Optionally, provide aPathMapper
for paths stored in the playlist files. Useful if the playlist files contain relative paths and/or paths for other systems that need to be mapped to absolute, system-specific paths to be loaded and back again when saved.remote_wrangler (
RemoteDataWrangler
|None
(default:None
)) β Optionally, provide aRemoteDataWrangler
object for processing URIs on tracks. If given, the wrangler can be used when calling __get_item__ to get an item from the collection from its URI. The wrangler is also used when loading tracks to allow them to process URI tags. For more info on this, seeLocalTrack
.
Attributes:
The tracks in this collection
The playlists in this library mapped as
{<name>: <playlist>}
Dynamically generate a set of folder collections from the tracks in this library.
Dynamically generate a set of album collections from the tracks in this library
Dynamically generate a set of artist collections from the tracks in this library
Dynamically generate a set of genre collections from the tracks in this library
Passed to playlist objects when loading playlists to map paths stored in the playlist file.
Path to the library folder
Filter
to filter out the playlists loaded by name.Path to the playlist folder
Stores the paths that caused errors when loading/enriching
Methods:
load
()Loads all tracks and playlists in this library from scratch and log results.
load_track
(path)Wrapper for
load_track()
which automatically loads the track at the givenpath
and assigns optional arguments using this library's attributes.Load all tracks from all the valid paths in this library, replacing currently loaded tracks.
Log stats on currently loaded tracks
load_playlist
(path)Wrapper for
load_playlist()
which automatically loads the playlist at the givenpath
and assigns optional arguments using this library's attributes.Load all playlists found in this library's
playlist_folder
, filtered down using theplaylist_filter
if given, replacing currently loaded playlists.Log stats on currently loaded playlists
save_playlists
([dry_run])For each Playlist in this Library, saves its associate tracks and its settings (if applicable) to file.
restore_tracks
(backup[,Β tags])Restore track tags from a backup to loaded track objects.
json
()Return a dictionary representation of the key attributes of this object that is safe to output to JSON
- class property name: strο
The type of library loaded
- class property source: strο
The type of local library loaded
- property tracks: list[LocalTrack]ο
The tracks in this collection
- property playlists: dict[str, LocalPlaylist]ο
The playlists in this library mapped as
{<name>: <playlist>}
- property folders: list[LocalFolder]ο
Dynamically generate a set of folder collections from the tracks in this library. Folder collections are generated relevant to the library folder it is found in.
- property albums: list[LocalAlbum]ο
Dynamically generate a set of album collections from the tracks in this library
- property artists: list[LocalArtist]ο
Dynamically generate a set of artist collections from the tracks in this library
- property genres: list[LocalGenres]ο
Dynamically generate a set of genre collections from the tracks in this library
- path_mapperο
Passed to playlist objects when loading playlists to map paths stored in the playlist file.
- property library_folders: list[str]ο
Path to the library folder
- playlist_filter: Filter[str]ο
Filter
to filter out the playlists loaded by name.
- property playlist_folder: strο
Path to the playlist folder
- errors: list[str]ο
Stores the paths that caused errors when loading/enriching
- load()ο
Loads all tracks and playlists in this library from scratch and log results.
- Return type:
None
- load_track(path)ο
Wrapper for
load_track()
which automatically loads the track at the givenpath
and assigns optional arguments using this libraryβs attributes.Handles exceptions by logging paths which produce errors to internal list of
errors
.- Return type:
LocalTrack
|None
- load_tracks()ο
Load all tracks from all the valid paths in this library, replacing currently loaded tracks.
- Return type:
None
- log_tracks()ο
Log stats on currently loaded tracks
- Return type:
None
- load_playlist(path)ο
Wrapper for
load_playlist()
which automatically loads the playlist at the givenpath
and assigns optional arguments using this libraryβs attributes.Handles exceptions by logging paths which produce errors to internal list of
errors
.- Return type:
- load_playlists()ο
Load all playlists found in this libraryβs
playlist_folder
, filtered down using theplaylist_filter
if given, replacing currently loaded playlists.- Returns:
None
β The loaded playlists.- Raises:
LocalCollectionError β If a given playlist name cannot be found.
- log_playlists()ο
Log stats on currently loaded playlists
- Return type:
None
- save_playlists(dry_run=True)ο
For each Playlist in this Library, saves its associate tracks and its settings (if applicable) to file.
- Parameters:
dry_run (
bool
(default:True
)) β Run function, but do not modify the file on the disk.- Returns:
dict
[str
,Result
] β A map of the playlist name to the results of its sync as aResult
object.
- restore_tracks(backup, tags=LocalTrackField.ALL)ο
Restore track tags from a backup to loaded track objects. This does not save the updated tags.
- Parameters:
backup (
Mapping
[str
,Mapping
[str
,Any
]]) β Backup data in the form{<path>: {<Map of JSON formatted track data>}}
tags (
Union
[LocalTrackField
,Iterable
[LocalTrackField
]] (default:<LocalTrackField.ALL: 0>
)) β Set of tags to restore.
- Returns:
int
β The number of tracks restored
- json()ο
Return a dictionary representation of the key attributes of this object that is safe to output to JSON