Spotify and python

Posted on
Mon Aug 26, 2013 11:31 am
henkjanvries offline
User avatar
Posts: 108
Joined: May 05, 2012

Spotify and python

Im just a noob,dont get past copying texts into terminal, hoping it will work.

Im wondering if any programmer here is able to make something out of the libspotify and perhaps in combinations with modipy/pyspotify. https://github.com/mopidy/pyspotify
this with python, perhaps indigo is able to send commands and there control spotify on a server.

i hope someone is able to help or send me on my way.

Posted on
Mon Nov 12, 2018 6:00 pm
Korey offline
User avatar
Posts: 688
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Spotify and python

With the development of Spotify plugin now defunct I am using AppleScript to control Spotify.

Just simple commands to play / pause and start playlists.

however I would love to be able to query Spotifys playing state as I use both iTunes and Spotify and need to be able to pause one when the other starts to play. I can do this easily with iTunes but not Spotify.

I noticed that there is:
Code: Select all
player state (stopped/‌playing/‌paused, r/o) : Is Spotify stopped, paused, or playing?
in the Spotify AppleScript dictionary, so I assume this is possible.

I see it done in Python from pyspotify with the commands PlayerState.PAUSED & PlayerState.PLAYING


Code: Select all
from __future__ import unicode_literals

import spotify
from spotify import lib


__all__ = [
    'PlayerState',
]


class PlayerState(object):
    UNLOADED = 'unloaded'
    LOADED = 'loaded'
    PLAYING = 'playing'
    PAUSED = 'paused'


class Player(object):

    """Playback controller.
    You'll never need to create an instance of this class yourself. You'll find
    it ready to use as the :attr:`~Session.player` attribute on the
    :class:`Session` instance.
    """

    state = PlayerState.UNLOADED
    """The player state.
    - The state is initially :attr:`PlayerState.UNLOADED`.
    - When a track is loaded, the state changes to :attr:`PlayerState.LOADED`.
    - When playback is started the state changes to
      :attr:`PlayerState.PLAYING`.
    - When playback is paused the state changes to :attr:`PlayerState.PAUSED`.
    - When the track is unloaded the state changes to
      :attr:`PlayerState.UNLOADED` again.
    """

    def __init__(self, session):
        self._session = session

    def load(self, track):
        """Load :class:`Track` for playback."""
        spotify.Error.maybe_raise(lib.sp_session_player_load(
            self._session._sp_session, track._sp_track))
        self.state = PlayerState.LOADED

    def seek(self, offset):
        """Seek to the offset in ms in the currently loaded track."""
        spotify.Error.maybe_raise(
            lib.sp_session_player_seek(self._session._sp_session, offset))

    def play(self, play=True):
        """Play the currently loaded track.
        This will cause audio data to be passed to the
        :attr:`~SessionCallbacks.music_delivery` callback.
        If ``play`` is set to :class:`False`, playback will be paused.
        """
        spotify.Error.maybe_raise(lib.sp_session_player_play(
            self._session._sp_session, play))
        if play:
            self.state = PlayerState.PLAYING
        else:
            self.state = PlayerState.PAUSED

    def pause(self):
        """Pause the currently loaded track.
        This is the same as calling :meth:`play` with :class:`False`.
        """
        self.play(False)

    def unload(self):
        """Stops the currently playing track."""
        spotify.Error.maybe_raise(
            lib.sp_session_player_unload(self._session._sp_session))
        self.state = PlayerState.UNLOADED

    def prefetch(self, track):
        """Prefetch a :class:`Track` for playback.
        This can be used to make libspotify download and cache a track before
        playing it.
        """
        spotify.Error.maybe_raise(lib.sp_session_player_prefetch(
            self._session._sp_session, track._sp_track))


Any pointers on how I go about getting player state: (Playing / Paused) into a Variable in Indigo?

Thanks! :D

--
Korey

Posted on
Mon Nov 12, 2018 8:43 pm
jay (support) offline
Site Admin
User avatar
Posts: 16815
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Spotify and python

According to the README on the pyspotify github page, it's not longer supported because Spotify stopped supporting the API it was using. It's unclear if it still works or not, but I'm guessing it doesn't.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest