Browse Source

Update README, requirements, cleanup

pull/3/head
Wesley Kerfoot 6 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. ### 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. ### 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 [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` * Go to "Edit Settings" in your newly created app, then add
as a redirect URI and hit "Save" `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/) * Find your spotify username [here](https://www.spotify.com/us/account/overview/)
* Now you can run `spotsync --username=username --host=my_mpd_host` where * Now you can run `spotsync --host=my_mpd_host` where `my_mpd_host` is the host you
`username` is your username from before, and `my_mpd_host` is the host you are running MPD on (defaults to `localhost:6600` if you do not pass it)
are running MPD on (defaults to `localhost` if you do not pass it)
* You will be prompted to grant permission to the app, once that's done, 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 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 certifi==2019.3.9
cffi==1.12.3 cffi==1.12.3
chardet==3.0.4 chardet==3.0.4
gevent==1.4.0
greenlet==0.4.15
httplib2==0.12.3 httplib2==0.12.3
idna==2.8 idna==2.8
pycparser==2.19 pycparser==2.19

3
setup.py

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

10
spotify_mpd_sync/msplaylist/authenticate.py

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

6
spotify_mpd_sync/msplaylist/spotify.py

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

Loading…
Cancel
Save