From 7a1343ac91c4ba15fb7004ff0ad0af05bfbc56fe Mon Sep 17 00:00:00 2001 From: Tim Rae Date: Sun, 9 Jun 2024 08:46:54 +0200 Subject: [PATCH] Add config param for sync_favorites_default and cleanup command line arg --- example_config.yml | 5 +++++ readme.md | 6 ++++++ src/spotify_to_tidal/__main__.py | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/example_config.yml b/example_config.yml index 9ea6f56..d345b15 100644 --- a/example_config.yml +++ b/example_config.yml @@ -14,6 +14,11 @@ spotify: #excluded_playlists: # - spotify:playlist:1ABCDEqsABCD6EaABCDa0a +# default setting for syncing favorites when no command line arguments are provided +# - when true: favorites will be synced by default (overriden when any command line arg provided) +# - when false: favorites can only be synced manually via --sync-favorites argument +sync_favorites_default: true + # increasing these parameters should increase the search speed, while decreasing reduces likelihood of 429 errors max_concurrency: 10 # max concurrent connections at any given time rate_limit: 10 # max sustained connections per second diff --git a/readme.md b/readme.md index f864e0e..76fd765 100644 --- a/readme.md +++ b/readme.md @@ -30,6 +30,12 @@ You can also just synchronize a specific playlist by doing the following: spotify_to_tidal --uri 1ABCDEqsABCD6EaABCDa0a # accepts playlist id or full playlist uri ``` +or sync just your 'Liked Songs' with: + +```bash +spotify_to_tidal --sync-favorites +``` + See example_config.yml for more configuration options, and `spotify_to_tidal --help` for more options. --- diff --git a/src/spotify_to_tidal/__main__.py b/src/spotify_to_tidal/__main__.py index 2aa7121..a97b944 100644 --- a/src/spotify_to_tidal/__main__.py +++ b/src/spotify_to_tidal/__main__.py @@ -9,8 +9,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument('--config', default='config.yml', help='location of the config file') parser.add_argument('--uri', help='synchronize a specific URI instead of the one in the config') - parser.add_argument('--sync-favorites', action='store_true', help='synchronize the favorites') - parser.add_argument('--disable-favorites-sync', action='store_true', help='disable synchronization of favorites (only valid when no other args passed)') # todo: use subparser + parser.add_argument('--sync-favorites', action=argparse.BooleanOptionalAction, help='synchronize the favorites') args = parser.parse_args() with open(args.config, 'r') as f: @@ -27,17 +26,20 @@ def main(): tidal_playlists = _sync.get_tidal_playlists_dict(tidal_session) tidal_playlist = _sync.pick_tidal_playlist_for_spotify_playlist(spotify_playlist, tidal_playlists) _sync.sync_playlists_wrapper(spotify_session, tidal_session, [tidal_playlist], config) + sync_favorites = args.sync_favorites # only sync favorites if command line argument explicitly passed + elif args.sync_favorites: + sync_favorites = True # sync only the favorites elif config.get('sync_playlists', None): # if the config contains a sync_playlists list of mappings then use that _sync.sync_playlists_wrapper(spotify_session, tidal_session, _sync.get_playlists_from_config(spotify_session, tidal_session, config), config) - elif args.sync_favorites: - # sync just the favorites - _sync.sync_favorites_wrapper(spotify_session, tidal_session, config) + sync_favorites = args.sync_favorites is None and config.get('sync_favorites_default', True) else: - # otherwise sync all the user playlists in the Spotify account and favorites if not disabled + # otherwise sync all the user playlists in the Spotify account and favorites unless explicitly disabled _sync.sync_playlists_wrapper(spotify_session, tidal_session, _sync.get_user_playlist_mappings(spotify_session, tidal_session, config), config) - if not args.disable_favorites_sync: - _sync.sync_favorites_wrapper(spotify_session, tidal_session, config) + sync_favorites = args.sync_favorites is None and config.get('sync_favorites_default', True) + + if sync_favorites: + _sync.sync_favorites_wrapper(spotify_session, tidal_session, config) if __name__ == '__main__': main()