Esempio n. 1
0
File: player.py Progetto: piojo/ssp
    def play(self):
        if self.album_mode:
            # Super happy album mode
            self.logger.debug("Selecting track based on album mode algorithm")
            min_play_count = self.library.query(func.min(sspTrack.playcount)).first()[0]
            min_skip_count = self.library.query(func.min(sspTrack.skipcount)).first()[0]
            self.logger.debug("min_play_count: %s" % (min_play_count))
            self.logger.debug("min_skip_count: %s" % (min_skip_count))
            remaining_album_tracks = self.library.query(sspTrack).filter(sspTrack.playcount == min_play_count).filter(sspTrack.skipcount == min_skip_count).filter(sspTrack.albumid == self.album).count()
            self.logger.debug("remaining_album_tracks: %s" % (remaining_album_tracks))
            if remaining_album_tracks == 0:
                self.logger.debug("No tracks left to play, selecting new album")
                self.album = self.library.query(sspTrack.albumid).filter(sspTrack.playcount == min_play_count).filter(sspTrack.skipcount == min_skip_count).order_by(sspTrack.playcount + sspTrack.skipcount, "random()").first()[0]
            self.logger.debug("Album ID: %s" % (self.album))
            self.track = self.library.query(sspTrack).filter(sspTrack.albumid == self.album).filter(sspTrack.playcount == min_play_count).filter(sspTrack.skipcount == min_skip_count).filter(sspTrack.albumid == self.album).order_by(sspTrack.filepath).first()
            if self.track.skipcount > min_skip_count or self.track.playcount > min_play_count or self.track.albumid != self.album:
                self.logger.error("Algorithm failure, selected track doesn't meet selection conditions. This is a bug, report this!")
        else:
            # Regularly ordinary ssp time
            self.logger.debug("Selecting track based on standard algorithm")
            self.track = self.library.query(sspTrack).order_by(sspTrack.playcount + sspTrack.skipcount, "random()").first()
            self.album = self.track.albumid # Set this so we can continue with an album we stumble across

        self.logger.debug("Selected track %s" % (self.track))
        self.stat = self.library.query(sspStat).filter("hour = %s" % datetime.now().hour).first()
        self.trackinfo = TrackInfo()

        if os.path.isfile(self.track.filepath):
            self.player.set_property("uri", u"file://" + fixurl(self.track.filepath.replace("#","%23")))
            self.player.set_state(STATE_PLAYING)
        else:
            self.logger.info("Oops, \"%s\" doesn't seem to exist anymore" % self.track.filepath)
            self.stop()
            self.play()
Esempio n. 2
0
 def scan(self):
     if os.path.isfile(self.track.filepath):
         self.player.set_property("uri", u"file://" + fixurl(self.track.filepath.replace("#","%23")))
         self.player.set_state(gst.STATE_PLAYING)
         self.logger.debug(u"Scanning %s" % self.track.filepath)
     else:
         self.stop()
         self.logger.error(u"Unable to find %s on disk" % (self.track.filepath))
         self.next()
Esempio n. 3
0
 def scan(self):
     if os.path.isfile(self.track.filepath):
         self.player.set_property(
             "uri",
             u"file://" + fixurl(self.track.filepath.replace("#", "%23")))
         self.player.set_state(gst.STATE_PLAYING)
         self.logger.debug(u"Scanning %s" % self.track.filepath)
     else:
         self.stop()
         self.logger.error(u"Unable to find %s on disk" %
                           (self.track.filepath))
         self.next()
Esempio n. 4
0
    def play(self, trackid=None):
        min_play_count = self.library.query(func.min(sspTrack.playcount)).first()[0]
        min_skip_count = self.library.query(func.min(sspTrack.skipcount)).first()[0]

        # Are we restoring a previous state?
        if not trackid:
            self.logger.debug("Did not specify trackid")
            if self.album_mode:
                # Super happy album mode
                self.track = self.select_album(min_play_count, min_skip_count, self.album)
            else:
                # Regular ordinary ssp time
                self.track = self.select_random(min_play_count, min_skip_count)
        else:
            # Try to find track based on trackid
            self.track = self.select_track(trackid)

        self.album = self.track.albumid # Set this so we can continue with an album


        self.logger.debug("Selected track %s" % (self.track))

        self.stat = self.library.query(sspStat).filter("hour = %s" % datetime.now().hour).first()
        if not self.stat:
            self.stat = sspStat(datetime.now().hour)
            self.library.add(self.stat)

        self.weekstat = self.library.query(sspWeekStat).filter("hour = %s" % datetime.now().hour).filter("day = %s" % datetime.now().weekday()).first()
        if not self.weekstat:
            self.weekstat = sspWeekStat(datetime.now().hour, datetime.now().weekday())
            self.library.add(self.weekstat)

        self.trackinfo = TrackInfo()

        if os.path.isfile(self.track.filepath):
            self.player.set_property("uri", u"file://" + fixurl(self.track.filepath.replace("#","%23")))
            self.state_save()
            self.player.set_state(STATE_PLAYING)
        else:
            self.logger.info("Oops, \"%s\" doesn't seem to exist anymore" % self.track.filepath)
            self.stop()
            self.play()
Esempio n. 5
0
 def scan(self):
     if os.path.isfile(self.filepath):
         self.player.set_property("uri", "file://" + fixurl(self.filepath.replace("#","%23")))
         self.player.set_state(gst.STATE_PLAYING)
         print("Scanning %s" % self.filepath)