From e3430a1a80bd64aac652a3053e915380cc8ac7a6 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 19 May 2019 13:31:28 -0400 Subject: [PATCH] Add arguments, update README --- spotify_mpd_sync/msplaylist/spotify.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/spotify_mpd_sync/msplaylist/spotify.py b/spotify_mpd_sync/msplaylist/spotify.py index 4ef782e..d405394 100644 --- a/spotify_mpd_sync/msplaylist/spotify.py +++ b/spotify_mpd_sync/msplaylist/spotify.py @@ -11,11 +11,12 @@ from collections import defaultdict from re import sub from os import environ import spotipy.util as util +import argparse from spotify_mpd_sync.msplaylist.authenticate import prompt_for_user_token class Spotify(): - def __init__(self): + def __init__(self, host="localhost", port=6600): self.username = environ.get("SPOTIFY_USERNAME") scope = "playlist-read-private" @@ -25,7 +26,7 @@ class Spotify(): self.sp = spotipy.Spotify(auth=token) self.mpd_client = MPDClient() - self.mpd_client.connect("127.0.0.1", 6600) + self.mpd_client.connect(host, port) self._playlists = defaultdict(lambda: []) @@ -89,5 +90,21 @@ class Spotify(): def run_sync(): - spotify = Spotify() + parser = argparse.ArgumentParser() + parser.add_argument("-H", + "--host", + default="localhost", + help="The MPD server you would like spotsync to use, defaults localhost") + + parser.add_argument("-P", + "--port", + type=int, + default=6600, + help="The MPD port you would like spotsync to use, defaults to 6600") + + args = parser.parse_args() + + spotify = Spotify(host=args.host, + port=args.port) + spotify.persist_playlists()