Playlist synchronizing - WilliamNT/tunesynctool GitHub Wiki
Tunesynctool supports automatically adding missing tracks to a playlist. All you need is the IDs of the source playlist and the target playlist.
This page explains how synchronizing works internally and how you can use it in your projects.
[!NOTE]
- If you're looking for the CLI usage guide, check CLI usage.
- Currently, tunesynctool lacks a continuous-automatically syncing tool. However, a Dockerized solution for this purpose is in the works and will be released soon.
Internally, the sync utility employs the track matching algorithm of tunesynctool to synchronize tracks from your source playlist with tracks on the target service. Upon successful synchronization, the target playlist is updated with the identified songs.
If a song couldn't be identified, it is ignored.
[!TIP] Learn more about how track matching works.
Using the PlaylistSynchronizer class
You can use the playlist synchronizer utility by importing it from the tunesynctool package.
from tunesynctool import PlaylistSynchronizer, Configuration, YouTubeDriver, SpotifyDriver, Track
Let's continue by defining the mandatory variables.
my_config = Configuration(...) # Create your config object
source_driver = YouTubeDriver(config=my_config)
target_driver = SpotifyDriver(config=my_config)
sync = PlaylistSynchronizer( # Initialize a new PlaylistSynchronizer
source_driver=source_driver, # Will be used to look up songs from your source playlist
target_driver=target_driver # Will be used to find songs on the other streaming service to then add them to the playlist
)
We’re halfway there! Read about the methods available on the PlaylistSynchronizer class in the next sections.
find_missing_tracks(self, source_playlist_tracks: List[Track], target_playlist_tracks: List[Track]) -> List[Track]
This method compares the track lists and returns a list of Track objects, containing only the tracks that are part of source_playlist_tracks but aren't found in the target_playlist_tracks.
The track lists do not need to originate from the same streaming service because tunesynctool employs its track comparison algorithm to match tracks, rather than relying on their unique service identifiers or object hashes.
sync(self, source_playlist_id: str, target_playlist_id: str) -> None
The sync method necessitates the provision of source_playlist_id and target_playlist_id. Their names are self-explanatory, but in the event of confusion, the source_playlist_id corresponds to the ID of the playlist that serves as the source of truth. Conversely, the target_playlist_id identifies the playlist that is purportedly incomplete (not in sync with the source) and the object of the update.
This method retrieves tracks through the source and target service drivers. It identifies songs present in the source but absent from the target, matches them against the target streaming service’s catalog of songs, and subsequently updates the target playlist with the successfully identified songs.
Should you have any feedback or issues, please create an issue, and I will do my best to assist you and resolve any confusion.