Synchronise your music library to local or remote libraries
Project description
Musify
A Swiss Army knife for music library management
Supporting local and music streaming service (remote) libraries.
- Extract data for all item types from remote libraries, including following/saved items, such as: playlists, tracks, albums, artists, users, podcasts, audiobooks
- Load local audio files, programmatically manipulate, and save tags/metadata/embedded images
- Synchronise local tracks metadata with its matching track's metadata on supported music streaming services
- Synchronise local playlists with playlists on supported music streaming services
- Backup and restore track tags/metadata and playlists for local and remote libraries
- Extract and save images from remote tracks or embedded in local tracks
Contents
NOTE:
This readme provides a brief overview of the program. Read the docs for full reference documentation.
Installation
Install through pip using one of the following commands:
pip install musify
python -m pip install musify
Quick Guides
These quick guides will help you get set up and going with Musify in just a few minutes. For more detailed guides, check out the documentation.
TIP: Set up logging to ensure you can see all info reported by the later operations. Libraries log info about loaded objects to the custom
STAT
level.import logging from musify.log import STAT logging.basicConfig(format="%(message)s", level=STAT)
Spotify
In this example, you will:
- Authorise access to the Spotify Web API
- Load your Spotify library
- Load some other Spotify objects
- Add some tracks to a playlist
-
If you don't already have one, create a Spotify for Developers account.
-
If you don't already have one, create an app. Select "Web API" when asked which APIs you are planning on using. To use this program, you will only need to take note of the client ID and client secret.
-
Create a
SpotifyAPI
object and authorise the program access to Spotify data as follows:The scopes listed in this example will allow access to read your library data and write to your playlists. See Spotify Web API documentation for more information about scopes
from musify.libraries.remote.spotify.api import SpotifyAPI api = SpotifyAPI( client_id="<YOUR CLIENT ID>", client_secret="<YOUR CLIENT SECRET>", scopes=[ "user-library-read", "user-follow-read", "playlist-read-collaborative", "playlist-read-private", "playlist-modify-public", "playlist-modify-private" ], # providing a `token_file_path` will save the generated token to your system # for quicker authorisations in future token_file_path="<PATH TO JSON TOKEN>" ) # authorise the program to access your Spotify data in your web browser api.authorise()
-
Create a
SpotifyLibrary
object and load your library data as follows:from musify.libraries.remote.spotify.library import SpotifyLibrary library = SpotifyLibrary(api=api) # if you have a very large library, this will take some time... library.load() # ...or you may also just load distinct sections of your library library.load_playlists() library.load_tracks() library.load_saved_albums() library.load_saved_artists() # enrich the loaded objects; see each function's docstring for more info on arguments # each of these will take some time depending on the size of your library library.enrich_tracks(features=True, analysis=False, albums=False, artists=False) library.enrich_saved_albums() library.enrich_saved_artists(tracks=True, types=("album", "single")) # optionally log stats about these sections library.log_playlists() library.log_tracks() library.log_albums() library.log_artists() # pretty print an overview of your library print(library)
-
Load some Spotify objects using any of the supported identifiers as follows:
from musify.libraries.remote.spotify.object import SpotifyTrack, SpotifyAlbum, SpotifyPlaylist, SpotifyArtist # load by ID track1 = SpotifyTrack.load("6fWoFduMpBem73DMLCOh1Z", api=api) # load by URI track2 = SpotifyTrack.load("spotify:track:4npv0xZO9fVLBmDS2XP9Bw", api=api) # load by open/external style URL track3 = SpotifyTrack.load("https://open.spotify.com/track/1TjVbzJUAuOvas1bL00TiH", api=api) # load by API style URI track4 = SpotifyTrack.load("https://api.spotify.com/v1/tracks/6pmSweeisgfxxsiLINILdJ", api=api) # load many different kinds of supported Spotify types playlist = SpotifyPlaylist.load("spotify:playlist:37i9dQZF1E4zg1xOOORiP1", api=api, extend_tracks=True) album = SpotifyAlbum.load("https://open.spotify.com/album/0rAWaAAMfzHzCbYESj4mfx", api=api, extend_tracks=True) artist = SpotifyArtist.load("1odSzdzUpm3ZEEb74GdyiS", api=api, extend_tracks=True) # pretty print information about the loaded objects print(track1, track2, track3, playlist, album, artist, sep="\n")
-
Add some tracks to a playlist in your library, synchronise with Spotify, and log the results as follows:
NOTE: This step will only work if you chose to load either your playlists or your entire library in step 4.
my_playlist = library.playlists["<YOUR PLAYLIST'S NAME>"] # case sensitive # add a track to the playlist my_playlist.append(track1) # add an album to the playlist using either of the following my_playlist.extend(album) my_playlist += album # sync the object with Spotify and log the results result = my_playlist.sync(dry_run=False) library.log_sync(result)
Local
In this example, you will:
- Load a local library
- Modify the tags of some local tracks and save them
- Modify a local playlist and save it
-
Create one of the following supported
LocalLibrary
objects:Generic local library
from musify.libraries.local.library import LocalLibrary library = LocalLibrary( library_folders=["<PATH TO YOUR LIBRARY FOLDER>", ...], playlist_folder="<PATH TO YOUR PLAYLIST FOLDER", )
MusicBee
from musify.libraries.local.library import MusicBee library = MusicBee(musicbee_folder="<PATH TO YOUR MUSICBEE FOLDER>")
-
Load your library:
# if you have a very large library, this will take some time... library.load() # ...or you may also just load distinct sections of your library library.load_tracks() library.load_playlists() # optionally log stats about these sections library.log_tracks() library.log_playlists() # pretty print an overview of your library print(library)
-
Get collections from your library:
playlist = library.playlists["<NAME OF YOUR PLAYLIST>"] # case sensitive album = next(album for album in library.albums if album.name == "<ALBUM NAME>") artist = next(artist for artist in library.artists if artist.name == "<ARTIST NAME>") folder = next(folder for folder in library.folders if folder.name == "<FOLDER NAME>") genre = next(genre for genre in library.genres if genre.name == "<GENRE NAME>") # pretty print information about the loaded objects print(playlist, album, artist, folder, genre, sep="\n")
-
Get a track from your library using any of the following identifiers:
# get a track via its title # if multiple tracks have the same title, the first matching one if returned track = library["<TRACK TITLE>"] # get a track via its path track = library["<PATH TO YOUR TRACK>"] # must be an absolute path # get a track according to a specific tag track = next(track for track in library if track.artist == "<ARTIST NAME>") track = next(track for track in library if "<GENRE>" in (track.genres or [])) # pretty print information about this track print(track)
-
Change some tags:
from datetime import date track.title = "new title" track.artist = "new artist" track.album = "new album" track.track_number = 200 track.genres = ["super cool genre", "awesome genre"] track.key = "C#" track.bpm = 120.5 track.date = date(year=2024, month=1, day=1) track.compilation = True track.image_links.update({ "cover front": "https://i.scdn.co/image/ab67616d0000b2737f0918f1560fc4b40b967dd4", "cover back": "<PATH TO AN IMAGE ON YOUR LOCAL DRIVE>" }) # see the updated information print(track)
-
Save the tags to the file:
from musify.libraries.local.track.field import LocalTrackField # you don't have to save all the tags you just modified # select which you wish to save first like so tags = [ LocalTrackField.TITLE, LocalTrackField.GENRES, LocalTrackField.KEY, LocalTrackField.BPM, LocalTrackField.DATE, LocalTrackField.COMPILATION, LocalTrackField.IMAGES ] track.save(tags=tags, replace=True, dry_run=False)
-
Add some tracks to one of your playlists and save it:
my_playlist = library.playlists["<NAME OF YOUR PLAYLIST>"] # case sensitive # add a track to the playlist my_playlist.append(track) # add album's and artist's tracks to the playlist using either of the following my_playlist.extend(album) my_playlist += artist result = my_playlist.save(dry_run=False) print(result)
Currently Supported
- Music Streaming Services:
Spotify
- Audio filetypes:
.flac
.m4a
.mp3
.wma
- Local playlist filetypes:
.m3u
.xautopf
- Local Libraries:
MusicBee
Release History
For change and release history, check out the documentation.
Contributing
For info on how to contribute to Musify, check out the documentation.
Motivations & Aims
The key aim of this package is to provide a seamless framework for interoperability between all types of music
libraries whether local or remote.
This framework should allow for the following key functionality between libraries:
- Synchronise saved user data including:
- playlists data (e.g. name, description, tracks)
- saved tracks/albums/artists etc.
- Synchronise metadata by allowing users to pull metadata from music streaming services and save this to local tracks
- Provide tools to allow users to move from music streaming services to a local library by semi-automating the process of purchasing songs.
With this functionality, user's should then have the freedom to:
- Switch between music streaming services with a few simple commands
- Share local playlists and other local library data with friends over music streaming services without ever having to use them personally
- Easily maintain a high-quality local library with complete metadata
Users should have the freedom to choose how and where they want to listen to their favourite artists.
Given the near non-existence of income these services provide to artists, user's should have the choice to compensate their favourite artists fairly for their work, choosing to switch to other services that do and/or choosing not to use music streaming services altogether because of this. Hopefully, by reintroducing this choice to users, the music industry will be forced to re-evaluate their complete devaluing of creative work in the rush to chase profits, and instead return to a culture of nurturing talent by providing artists with a basic income to survive on the work of their craft. One can dream.
Author notes, contributions, and reporting issues
I initially developed this program for my own use so that I can share my local playlists with friends online. I have always maintained my own local library well and never saw the need to switch to music streaming services after their release. However, as an artist who has released music on all streaming services and after listening to the concerns many of the artists I follow have regarding these services, I started to refocus this project to be one that aims to break down the barriers between listening experiences for users. The ultimate aim being to make managing a local library as easy as any of the major music streaming services, allowing users the same conveniences while compensating artists fairly for their work.
If you have any suggestions, wish to contribute, or have any issues to report, please do let me know via the issues tab or make a new pull request with your new feature for review. Otherwise, I hope you enjoy using Musify!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file musify-0.9.2.tar.gz
.
File metadata
- Download URL: musify-0.9.2.tar.gz
- Upload date:
- Size: 149.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fdc77d224891b011f87ed128cffc97f27df4524fa04af99a5616f357d89dcc3 |
|
MD5 | ce3216d7db7bd7ff5549b6201f933d1b |
|
BLAKE2b-256 | 6e22fc2c7d0004631230ec062131ca7ddeeb12aac478b3051215d482b761f4f8 |
File details
Details for the file musify-0.9.2-py3-none-any.whl
.
File metadata
- Download URL: musify-0.9.2-py3-none-any.whl
- Upload date:
- Size: 196.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dde7ff91bbdc2b2ced198a7d4623e08c37938184f75797ad9224c6dd3b4db182 |
|
MD5 | 6cd17778d92fd672bd64865bc1fa43b5 |
|
BLAKE2b-256 | d537751424928fc59d991aa6c3b6f0db99f25f8e43f44108ad4dfea935b1a5c5 |