-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarSpotify.py
55 lines (49 loc) · 1.39 KB
/
CarSpotify.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
#Copyright 2015 Jonathan Schober Jr
#!/usr/bin/env python
from __future__ import unicode_literals
import sys
import threading
import spotify
from time import sleep
import CarPi
import ConfigParser
Config = ConfigParser.ConfigParser()
Config.read('Settings.cfg')
def on_connection_state_updated(session):
if session.connection.state is spotify.ConnectionState.LOGGED_IN:
logged_in.set()
def on_end_of_track(self):
global session
end_of_track.set()
def deliverMusic(session, format,data,num_frames):
global setup
if setup is False:
print format
CarPi.setup(num_frames,format.channels,format.sample_rate)
setup = True
CarPi.processData(data)
return num_frames
session = None
setup = False
hasInitted = False
def init():
global hasInitted
if hasInitted is False:
realInit();
hasInitted = True
def realInit():
global session
# Assuming a spotify_appkey.key in the current dir
config = spotify.Config();
config.load_application_key_file(filename=Config.get('Spotify','apikey'))
session = spotify.Session(config)
loop = spotify.EventLoop(session)
loop.start()
session.on(spotify.SessionEvent.MUSIC_DELIVERY, deliverMusic)
session.login(Config.get('Spotify','username'),Config.get('Spotify','password'), remember_me=True)
session.preferred_bitrate(spotify.Bitrate.BITRATE_320k)
def playTrack(track):
global session
# Play a track
session.player.load(track)
session.player.play()