コード例 #1
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
    def change_songs(self):
        ''' puts current song in previous queue, sets next song to current '''
        song_id = self.get_current_song()  # get currently playing song ID
        song = self.lookup(song_id)  # get the currently playing song object
        if song is not None:
            song['last_played'] = int(time.time() * 1000)  # last played = now
            song['play_count'] = song.get('play_count', 0) + 1  # count += 1
            result = firebase.put(config.SONGS, song_id, song)

        next_queue = firebase.get(config.QUEUE, config.NEXT)
        if next_queue is None:
            next_id = self._get_auto_song()
            print 'auto-choose: next song id is', next_id
        else:
            list_queue = [next_queue[key] for key in next_queue]
            comp = lambda song: song.get('time_added', -1)
            sorted_queue = sorted(list_queue, key=comp)

            print 'the sorted queue is'
            pprint(sorted_queue)

            next_id = sorted_queue.pop(0).get(
                'key')  # get current song off the front
            print 'next song id is', next_id

            # find key to remove from the queue. this is to update firebase
            # we have the key of the song, and we have to iterate through the
            # queue to see which {key, time_added} object to remove
            queue_key = None
            for k, v in next_queue.items():
                if v.get('key') == next_id:
                    queue_key = k
                    break

            if queue_key is not None:
                next_queue.pop(queue_key)
                print "removed key", next_id, "at", queue_key
                result = firebase.put(config.QUEUE, config.NEXT, next_queue)
            else:
                print "could not remove key", next_id, "at", queue_key
                result = False

        result = firebase.put(config.QUEUE, config.CURRENT, next_id)
        song = self.lookup(next_id)
        if song is not None:
            song_link = song.get('url')
            result = firebase.put('nowplaying', 'cur', song_link)
        return result
コード例 #2
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
    def change_songs(self):
        """ puts current song in previous queue, sets next song to current """
        song_id = self.get_current_song()  # get currently playing song ID
        song = self.lookup(song_id)  # get the currently playing song object
        if song is not None:
            song["last_played"] = int(time.time() * 1000)  # last played = now
            song["play_count"] = song.get("play_count", 0) + 1  # count += 1
            result = firebase.put(config.SONGS, song_id, song)

        next_queue = firebase.get(config.QUEUE, config.NEXT)
        if next_queue is None:
            next_id = self._get_auto_song()
            print "auto-choose: next song id is", next_id
        else:
            list_queue = [next_queue[key] for key in next_queue]
            comp = lambda song: song.get("time_added", -1)
            sorted_queue = sorted(list_queue, key=comp)

            print "the sorted queue is"
            pprint(sorted_queue)

            next_id = sorted_queue.pop(0).get("key")  # get current song off the front
            print "next song id is", next_id

            # find key to remove from the queue. this is to update firebase
            # we have the key of the song, and we have to iterate through the
            # queue to see which {key, time_added} object to remove
            queue_key = None
            for k, v in next_queue.items():
                if v.get("key") == next_id:
                    queue_key = k
                    break

            if queue_key is not None:
                next_queue.pop(queue_key)
                print "removed key", next_id, "at", queue_key
                result = firebase.put(config.QUEUE, config.NEXT, next_queue)
            else:
                print "could not remove key", next_id, "at", queue_key
                result = False

        result = firebase.put(config.QUEUE, config.CURRENT, next_id)
        song = self.lookup(next_id)
        if song is not None:
            song_link = song.get("url")
            result = firebase.put("nowplaying", "cur", song_link)
        return result
コード例 #3
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
 def get_previous_queue(self):
     """ returns the previously played queue """
     queue = firebase.get(config.QUEUE, config.PREV) or []
     return queue
コード例 #4
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
 def get_current_song(self):
     """ returns the song that's playing right now """
     result = firebase.get(config.QUEUE, config.CURRENT)
     return result
コード例 #5
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
 def get_songs(self):
     result = firebase.get(config.SONGS, None)
     return result
コード例 #6
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
 def get_previous_queue(self):
     ''' returns the previously played queue '''
     queue = firebase.get(config.QUEUE, config.PREV) or []
     return queue
コード例 #7
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
 def get_current_song(self):
     ''' returns the song that's playing right now '''
     result = firebase.get(config.QUEUE, config.CURRENT)
     return result
コード例 #8
0
ファイル: queue.py プロジェクト: httpsters/ryze-espresso
 def get_songs(self):
     result = firebase.get(config.SONGS, None)
     return result