Exemple #1
0
    def add(uri, user, notification=True):
        """ Add a track into a redis queue

        Parameters
        ----------
        uri: str
            The spotify URI of the Track to add to the Queue
        user: str
            The user id of the user whome added the track to the Queue
        """

        qid = str(uuid.uuid4())

        # Push the Track into the Queue
        redis.rpush(config.PLAYLIST_REDIS_KEY,
                    json.dumps({
                        'uri': uri,
                        'user': user,
                        'uuid': qid,
                    }))

        # Publish Add Event
        if notification:
            redis.publish(
                config.PLAYER_CHANNEL,
                json.dumps({
                    'id': qid,
                    'event': 'add',
                    'uri': uri,
                    'user': user
                }))
Exemple #2
0
    def delete(self):
        """ Unapuses the player.
        """
        event = {'event': 'resume'}
        redis.publish(config.PLAYER_CHANNEL, json.dumps(event))

        return http.OK(event)
Exemple #3
0
    def post(self):
        """ Pauses the player.
        """
        event = {'event': 'pause'}
        redis.publish(config.PLAYER_CHANNEL, json.dumps(event))

        return http.Created(event)
Exemple #4
0
    def delete(self):
        """ Set the player mute state to False.
        """

        redis.publish(config.PLAYER_CHANNEL,
                      json.dumps({
                          'event': 'set_mute',
                          'mute': False
                      }))

        return http.OK({'mute': self.is_mute()})
Exemple #5
0
    def post(self):
        """ Set the player mute state to True.
        """

        redis.publish(config.PLAYER_CHANNEL,
                      json.dumps({
                          'event': 'set_mute',
                          'mute': True
                      }))

        return http.Created({'mute': self.is_mute()})
Exemple #6
0
    def post(self):
        """ Change the volume level for the player.
        """

        serializer = VolumeSerializer()

        try:
            data = serializer.marshal(request.json)
        except MappingErrors as e:
            return http.UnprocessableEntity(errors=e.message)

        redis.publish(
            config.PLAYER_CHANNEL,
            json.dumps({
                'event': 'set_volume',
                'volume': data['volume']
            }))
        return http.OK(data)
Exemple #7
0
    def delete(uuid):
        """ Remove a track from a redis queue

        Parameters
        ----------
        uuid: Uuid
            Unique identifator of track in the queue
        """

        for item in Queue.iterate():
            json_item = json.loads(item)
            if json_item.get('uuid') == uuid:
                redis.lrem(config.PLAYLIST_REDIS_KEY, item, 1)
                redis.publish(
                    config.PLAYER_CHANNEL,
                    json.dumps({
                        'event': 'deleted',
                        'uri': json_item['uri'],
                        'user': json_item['user'],
                        'uuid': json_item['uuid'],
                    }))
                break
        else:
            raise ValueError('Cannot find value')
Exemple #8
0
    def delete(self):
        """ Skips the currently playing track.

        Returns
        -------
        http.Response
            A http response intance, in this case it should always be a 204
        """

        track, user = self.get_current_track()
        if track is None or user is None:
            return http.NoContent()

        redis.publish(
            config.PLAYER_CHANNEL,
            json.dumps({
                'event': 'stop',
                'user': str(user.id),
                'track': str(track.id),
                'uri': str(track.spotify_uri),
                'by': str(current_user.id),
            }))

        return http.OK()