Exemple #1
0
 def play(self, track_id):
     track = self.spotify.getTrack(track_id)
     if track['thumb'] == '':
         track['thumb'] = _DEFAULT_ICON
     if track['title'] == '':
         track['title'] = _DEFAULT_TITLE
     if self.kodi:
         self.listitem.setArt({'thumb': track['thumb']})
         self.listitem.setInfo(
             'music',
             {
                 'album': track['album'],
                 'artist': track['artist'],
                 'title': track['title']
             }
         )
         if self.isPlaying() and self.getPlayingFile() == _STREAM:
             log('updating librespot playback')
             self.updateInfoTag(self.listitem)
         else:
             self.librespot.unsuspend()
             log('starting librespot playback')
             super(Player, self).play(_STREAM, self.listitem)
     else:
         self.dialog.notification(
             track['title'],
             track['artist'],
             icon=track['thumb'],
             sound=False)
Exemple #2
0
 def play(self, track_id):
     track = self.spotify.getTrack(track_id)
     if track['thumb'] == '':
         track['thumb'] = _DEFAULT_ICON
     if track['title'] == '':
         track['title'] = _DEFAULT_TITLE
     if self.kodi:
         self.listitem.setArt({'thumb': track['thumb']})
         self.listitem.setInfo(
             'music', {
                 'album': track['album'],
                 'artist': track['artist'],
                 'title': track['title']
             })
         if self.isPlaying() and self.getPlayingFile() == _STREAM:
             log('updating librespot playback')
             self.updateInfoTag(self.listitem)
         else:
             self.librespot.unsuspend()
             log('starting librespot playback')
             super(Player, self).play(_STREAM, self.listitem)
     else:
         self.dialog.notification(track['title'],
                                  track['artist'],
                                  icon=track['thumb'],
                                  sound=False)
Exemple #3
0
 def stop(self):
     if self.isPlaying():
         if self.getPlayingFile() == _STREAM:
             log('stopping librespot playback')
             super(Player, self).stop()
         else:
             self.librespot.stop()
     else:
         self.librespot.restart()
Exemple #4
0
 def stop(self):
     if self.isPlaying():
         if self.getPlayingFile() == _STREAM:
             log('stopping librespot playback')
             super(Player, self).stop()
         else:
             self.librespot.stop()
     else:
         self.librespot.restart()
 def getTrack(self, track_id):
     try:
         if time.time() > self.expiration:
             log('token expired')
             token = json.loads(
                 urllib2.urlopen(urllib2.Request(*self.request)).read())
             log('token {} expires in {} seconds'.format(
                 token['access_token'], token['expires_in']))
             self.expiration = time.time() + float(token['expires_in']) - 60
             self.headers = {
                 'Accept': 'application/json',
                 'Content-Type': 'application/json',
                 'Authorization': 'Bearer {}'.format(token['access_token'])
             }
         track = json.loads(
             urllib2.urlopen(
                 urllib2.Request(
                     'https://api.spotify.com/v1/tracks/{}'.format(
                         track_id), None, self.headers)).read())
     except Exception as e:
         log('failed to get track {} from Spotify: {}'.format(e))
         track = dict()
     return {
         'album': _get('', track, 'album', 'name'),
         'artist': _get('', track, 'artists', 0, 'name'),
         'duration': _get(0, track, 'duration_ms') / 1000,
         'thumb': _get('', track, 'album', 'images', 0, 'url'),
         'title': _get('', track, 'name')
     }
Exemple #6
0
 def getTrack(self, track_id):
     try:
         if time.time() > self.expiration:
             log('token expired')
             token = json.loads(urllib2.urlopen(
                 urllib2.Request(*self.request)).read())
             log('token {} expires in {} seconds'.format(
                 token['access_token'], token['expires_in']))
             self.expiration = time.time() + float(token['expires_in']) - 60
             self.headers = {
                 'Accept': 'application/json',
                 'Content-Type': 'application/json',
                 'Authorization': 'Bearer {}'.format(token['access_token'])
             }
         track = json.loads(urllib2.urlopen(urllib2.Request(
             'https://api.spotify.com/v1/tracks/{}'.format(track_id), None,
             self.headers)).read())
     except Exception as e:
         log('failed to get track {} from Spotify: {}'.format(e))
         track = dict()
     return {
         'album': _get('', track, 'album', 'name'),
         'artist': _get('', track, 'artists', 0, 'name'),
         'duration': _get(0, track, 'duration_ms') / 1000,
         'thumb': _get('', track, 'album', 'images', 0, 'url'),
         'title': _get('', track, 'name')
     }
Exemple #7
0
 def run(self):
     log('named pipe started')
     try:
         os.unlink(_FIFO)
     except OSError:
         pass
     os.mkfifo(_FIFO)
     while (os.path.exists(_FIFO) and
            stat.S_ISFIFO(os.stat(_FIFO).st_mode)):
         with open(_FIFO, 'r') as fifo:
             command = fifo.read().splitlines()
             log('named pipe received {}'.format(str(command)))
             if len(command) == 0:
                 break
             elif command[0] == 'play':
                 self.play(command[1])
             elif command[0] == 'stop':
                 self.stop()
             elif command[0] == 'pause':
                 self.pause()
     try:
         os.unlink(_FIFO)
     except OSError:
         pass
     log('named pipe stopped')
Exemple #8
0
 def run(self):
     log('named pipe started')
     try:
         os.unlink(_FIFO)
     except OSError:
         pass
     os.mkfifo(_FIFO)
     while (os.path.exists(_FIFO)
            and stat.S_ISFIFO(os.stat(_FIFO).st_mode)):
         with open(_FIFO, 'r') as fifo:
             command = fifo.read().splitlines()
             log('named pipe received {}'.format(str(command)))
             if len(command) == 0:
                 break
             elif command[0] == 'play':
                 self.play(command[1])
             elif command[0] == 'stop':
                 self.stop()
             elif command[0] == 'pause':
                 self.pause()
     try:
         os.unlink(_FIFO)
     except OSError:
         pass
     log('named pipe stopped')
 def stop(self):
     if self.state:
         log('stopping librespot')
         _systemctl('stop')
         self.state = False
Exemple #10
0
 def pause(self):
     if self.isPlaying() and self.getPlayingFile() == _STREAM:
         log('pausing librespot playback')
         super(Player, self).pause()
Exemple #11
0
def _pactl(bit):
    log('pactl {}'.format(bit))
    subprocess.call(['pactl', 'suspend-sink', _SINK, bit])
Exemple #12
0
 def pause(self):
     if self.isPlaying() and self.getPlayingFile() == _STREAM:
         log('pausing librespot playback')
         super(Player, self).pause()
Exemple #13
0
 def onPlayBackStopped(self):
     log('a playback stopped')
     self.librespot.restart()
Exemple #14
0
 def onPlayBackEnded(self):
     log('a playback ended')
     self.librespot.restart()
Exemple #15
0
 def onAbortRequested(self):
     log('abort requested')
     with open(_FIFO, 'w') as fifo:
         fifo.close()
     self.join()
 def __init__(self):
     log('monitor started')
     self.player = Player()
Exemple #17
0
 def stop(self):
     if self.state:
         log('stopping librespot')
         _systemctl('stop')
         self.state = False
Exemple #18
0
 def restart(self):
     log('restarting librespot')
     _systemctl('restart')
     self.state = True
Exemple #19
0
def _systemctl(command):
    log('systemctl {}'.format(command))
    subprocess.call(['systemctl', command, _SERVICE])
    _pactl('1')
 def restart(self):
     log('restarting librespot')
     _systemctl('restart')
     self.state = True
Exemple #21
0
 def onAbortRequested(self):
     log('abort requested')
     with open(_FIFO, 'w') as fifo:
         fifo.close()
     self.join()
Exemple #22
0
 def onPlayBackEnded(self):
     log('a playback ended')
     self.librespot.restart()
Exemple #23
0
 def onPlayBackStarted(self):
     log('a playback started')
     if self.getPlayingFile() != _STREAM:
         self.librespot.stop()
def _systemctl(command):
    log('systemctl {}'.format(command))
    subprocess.call(['systemctl', command, _SERVICE])
    _pactl('1')
Exemple #25
0
 def onSettingsChanged(self):
     log('settings changed')
     self.stop()
     self.updateSettings()
Exemple #26
0
 def onSettingsChanged(self):
     log('settings changed')
     self.stop()
     self.updateSettings()
Exemple #27
0
 def onPlayBackStarted(self):
     log('a playback started')
     if self.getPlayingFile() != _STREAM:
         self.librespot.stop()
 def waitForAbort(self):
     super(Monitor, self).waitForAbort()
     self.player.onAbortRequested()
     log('monitor stopped')
Exemple #29
0
 def onPlayBackStopped(self):
     log('a playback stopped')
     self.librespot.restart()
def _pactl(bit):
    log('pactl {}'.format(bit))
    subprocess.call(['pactl', 'suspend-sink', _SINK, bit])