-
Notifications
You must be signed in to change notification settings - Fork 0
/
spotiRemote.py
82 lines (72 loc) · 2.19 KB
/
spotiRemote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import sys
import spotipy
import spotipy.util as util
import time
import spotify_token as st
import evdev
#import argparse
import os
def setup():
''' parser = argparse.ArgumentParser()
parser.add_argument('username', help='Spotify username')
parser.add_argument('password', help='password')
return parser.parse_args()'''
user = os.environ['SPOTIFY_USER']
password = os.environ['SPOTIFY_PASS']
return user,password
def access_token(username, password):
#try:
data = st.start_session(username, password)
#except Exception as e:
# print(e)
# print("did not connect to spotify try to log in again")
# return
token = data[0]
expiration_date = data[1]
return token
def currently_played_Song(sp):
if (sp):
current = sp.currently_playing()
print("currently played song is: " + current['item']['name'])
print("The following artist: ")
for artist in current["item"]['artists']:
print(artist['name'])
else:
print("invalid token or no token")
def next_song(sp):
if(sp and sp.currently_playing()):
sp.next_track()
else:
print(" next song no token or spotify")
def prev_song(sp):
if(sp and sp.currently_playing()):
sp.previous_track()
else:
print("prev no token or spotify")
def play_pause(sp):
if(sp and sp.currently_playing()):
if sp.currently_playing()['is_playing']:
sp.pause_playback()
else:
sp.start_playback()
else:
print("play pause no token or spotify")
def key_controller(sp):
device = evdev.InputDevice('/dev/input/event4')
for event in device.read_loop():
if event.type == evdev.ecodes.EV_KEY:
if(event.code == 66 and event.value == 00):
prev_song(sp)
if(event.code == 67 and event.value == 00):
next_song(sp)
if(event.code == 61 and event.value == 00):
play_pause(sp)
def main():
username, password = setup()
print(username)
token = access_token(username, password)
sp = spotipy.Spotify(auth=token)
key_controller(sp)
if __name__ == '__main__':
main()