Logo Search packages:      
Sourcecode: panflute version File versions  Download package

def panflute::daemon::mpd::Player::_refresh_status (   self  )  [private]

Query MPD for its current state, and cache it.

Definition at line 266 of file mpd.py.

00266                               :
        """
        Query MPD for its current state, and cache it.
        """

        states = { "play":  panflute.mpris.STATE_PLAYING,
                   "pause": panflute.mpris.STATE_PAUSED,
                   "stop":  panflute.mpris.STATE_STOPPED
                 }

        try:
            status = self.__active.status ()

            if status.has_key ("state"):
                state_name = status["state"]
                if state_name in states:
                    self.cached_status.state = states[state_name]
                    if self.cached_status.state == panflute.mpris.STATE_PLAYING:
                        self.start_polling_for_time ()
                    else:
                        self.stop_polling_for_time ()
                else:
                    self.log.warn ("Unrecognized state \"{0}\"".format (state_name))

            if status.has_key ("repeat"):
                if int (status["repeat"]):
                    self.cached_status.future = panflute.mpris.FUTURE_CONTINUE
                else:
                    self.cached_status.future = panflute.mpris.FUTURE_STOP

            if status.has_key ("songid"):
                self.__songid = status["songid"]
            else:
                self.__songid = None

            song = self.__active.currentsong ()
            metadata = {}

            if song.has_key ("file"):
                # MPD only reports paths relative to the library root, and doesn't
                # offer a command that says where the root actually is, so we're
                # stuck with a relative path.
                metadata["location"] = panflute.daemon.url.make_url (song["file"])

            if song.has_key ("title"):
                metadata["title"] = song["title"]
            elif song.has_key ("name"):
                metadata["title"] = song["name"]

            if song.has_key ("artist"):
                metadata["artist"] = song["artist"]
            elif song.has_key ("performer"):
                metadata["artist"] = song["performer"]
            elif song.has_key ("composer"):
                metadata["artist"] = song["composer"]

            if song.has_key ("album"):
                metadata["album"] = song["album"]

            if song.has_key ("track"):
                metadata["tracknumber"] = song["track"]

            if song.has_key ("time"):
                metadata["time"] = song["time"]
                metadata["mtime"] = int (song["time"]) * 1000

            if song.has_key ("genre"):
                metadata["genre"] = song["genre"]

            if song.has_key ("date"):
                metadata["year"] = song["date"]

            self.cached_metadata = metadata
            self.cached_caps.pause = (metadata.get ("mtime", 0) > 0)
            self.cached_caps.seek = (metadata.get ("mtime", 0) > 0)
            self.cached_caps.provide_metadata = (len (metadata) > 0)

        except mpd.ConnectionError, e:
            self.log.debug ("ConnectionError: {0}".format (e))
            self.__owner._connection_lost (self.__active)


    def __ping_cb (self):


Generated by  Doxygen 1.6.0   Back to index