Browse Source

Update README, requirements, cleanup

pull/3/head
Wesley Kerfoot 5 years ago
parent
commit
324b3ed9a5
  1. 13
      README.md
  2. 2
      requirements.txt
  3. 3
      setup.py
  4. 10
      spotify_mpd_sync/msplaylist/authenticate.py
  5. 6
      spotify_mpd_sync/msplaylist/spotify.py

13
README.md

@ -3,18 +3,19 @@
### Please note that this won't work without Spotify Premium because Spotify limits web API access to non-free accounts.
### This also requires you to have set up [mopidy-spotify](https://github.com/mopidy/mopidy-spotify) in order to play spotify tracks.
* Run `pip install --user .` in this repo.
* Run `pip3 install --user .` in this repo.
* Go to [https://developer.spotify.com/dashboard/applications](https://developer.spotify.com/dashboard/applications) and create an application. Call it whatever you want.
* Go to "Edit Settings" in your newly created app, then add `http://localhost`
as a redirect URI and hit "Save"
* Go to "Edit Settings" in your newly created app, then add
`http://localhost:8080`
as a redirect URI and hit "Save" (You may choose a different one by setting
`SPOTIPY_REDIRECT_URI` in your environment)
* Find your spotify username [here](https://www.spotify.com/us/account/overview/)
* Now you can run `spotsync --username=username --host=my_mpd_host` where
`username` is your username from before, and `my_mpd_host` is the host you
are running MPD on (defaults to `localhost` if you do not pass it)
* Now you can run `spotsync --host=my_mpd_host` where `my_mpd_host` is the host you
are running MPD on (defaults to `localhost:6600` if you do not pass it)
* You will be prompted to grant permission to the app, once that's done, it
will cache the credentials locally and you should be able to just run

2
requirements.txt

@ -2,6 +2,8 @@ bottle==0.12.16
certifi==2019.3.9
cffi==1.12.3
chardet==3.0.4
gevent==1.4.0
greenlet==0.4.15
httplib2==0.12.3
idna==2.8
pycparser==2.19

3
setup.py

@ -16,7 +16,8 @@ setuptools.setup(
install_requires = [
"spotipy>=2.4.4",
"python-mpd2>=1.0.0",
"bottle>=0.12.16"
"bottle>=0.12.16",
"gevent>=1.4.0"
],
classifiers= [
"Programming Language :: Python :: 3",

10
spotify_mpd_sync/msplaylist/authenticate.py

@ -4,6 +4,7 @@ import threading
import spotipy.oauth2 as oauth2
import spotipy
import queue
import os
from bottle import route, run, response, request
auth_token_queue = queue.Queue()
@ -50,13 +51,13 @@ def prompt_for_user_token(username, scope=None, client_id = None,
"""
if not client_id:
client_id = os.getenv('SPOTIPY_CLIENT_ID')
client_id = os.getenv("SPOTIPY_CLIENT_ID")
if not client_secret:
client_secret = os.getenv('SPOTIPY_CLIENT_SECRET')
client_secret = os.getenv("SPOTIPY_CLIENT_SECRET")
if not redirect_uri:
redirect_uri = os.getenv('SPOTIPY_REDIRECT_URI')
redirect_uri = os.getenv("SPOTIPY_REDIRECT_URI", "http://localhost:8080")
if not client_id:
print('''
@ -91,8 +92,7 @@ def prompt_for_user_token(username, scope=None, client_id = None,
except:
print("Please navigate here: %s" % auth_url)
response = "localhost:8080?code=%s" % auth_token_queue.get()
print(response)
response = "%s?code=%s" % (redirect_uri, auth_token_queue.get())
event_queue.put("done")
code = sp_oauth.parse_response_code(response)

6
spotify_mpd_sync/msplaylist/spotify.py

@ -20,11 +20,7 @@ class Spotify():
scope = "playlist-read-private"
token = prompt_for_user_token(self.username,
scope,
client_id=environ.get("SPOTIPY_CLIENT_ID"),
client_secret=environ.get("SPOTIPY_CLIENT_SECRET"),
redirect_uri=environ.get("SPOTIPY_REDIRECT_URI"))
token = prompt_for_user_token(self.username, scope)
if token:
self.sp = spotipy.Spotify(auth=token)

Loading…
Cancel
Save