Skip to content

Commit

Permalink
V1.7 Fixed timeout error
Browse files Browse the repository at this point in the history
This fixes the timeout error by deciding for ourselves which device we want to use and not using pychromecast. The Spotify controller wasn't working so I removed it.
  • Loading branch information
Esamanoaz committed Aug 30, 2021
1 parent 33a9f00 commit b7b32ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 1.7
* Fixed timeout error
+ Ask user which device they would like to use when setting up
- Removed SpotifyController from pychromecast because it was causing the timeout error
- Removed spotify_token

Verson 1.6.2
* Updated .gitignore
* Updated README.md
Expand Down
4 changes: 2 additions & 2 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@
'''
SCOPE = 'user-library-read user-read-currently-playing user-read-playback-state user-modify-playback-state playlist-modify-private'

VERSION = '1.6.2'
UPDATE_DATE = '7/3/2021'
VERSION = '1.7'
UPDATE_DATE = '8/29/2021'
37 changes: 6 additions & 31 deletions nfc_casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from random import shuffle

import pychromecast
from pychromecast.controllers.spotify import SpotifyController
import spotify_token as st
import spotipy
from spotipy.oauth2 import SpotifyOAuth

Expand Down Expand Up @@ -147,45 +145,22 @@ def construct_uris(dictionary, t):
# Create a spotify client
_scope = constants.SCOPE

# Create a spotify token
data = st.start_session(SP_DC, SP_KEY)
access_token = data[0]
expires = data[1] - int(time.time())
#auth=access_token,
client = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, scope=_scope, redirect_uri=SPOTIPY_REDIRECT_URI, username=SPOTIFY_USERNAME))
if args.show_debug:
spotipy.trace = True
spotipy.trace_out = True

#Launch the spotify app on the home
sp = SpotifyController(access_token, expires)
home.register_handler(sp)
sp.launch_app()

n()
print(home.status)
n()

if not sp.is_launched and not sp.credential_error:
print("Failed to launch spotify controller due to timeout")
sys.exit(1)
if not sp.is_launched and sp.credential_error:
print("Failed to launch spotify controller due to credential error")
sys.exit(1)

# Query spotify for active devices
devices_available = client.devices()

# Match active spotify devices with the spotify controller's device id
for device in devices_available["devices"]:
if device["id"] == sp.device:
spotify_device_id = device["id"]
break
# Get a list of available Spotify devices and ask the user which one to use
devices = devices_available['devices']
for i, device in enumerate(devices):
print(f'{i} -> Name: {device["name"]}, \nFull device info: {device}\n')

if not spotify_device_id:
print('No device with id "{}" known by Spotify'.format(sp.device))
print('Known devices: {}'.format(devices_available['devices']))
sys.exit(1)
device_choice = input('Enter the number of the device you want to use: ')
spotify_device_id = devices[device_choice]['id']

#Set up NFC reader
try:
Expand Down

0 comments on commit b7b32ed

Please sign in to comment.