pikaraoke icon indicating copy to clipboard operation
pikaraoke copied to clipboard

Feature request: limit queue entries for users

Open mhcgolds opened this issue 2 years ago • 7 comments

It would be nice to have an option to limit users to add only one song each in queue. So users would only be able to add another song after his song ended playing. This prevents someone to add a lot of songs in front of other users.

mhcgolds avatar Dec 30 '22 21:12 mhcgolds

I'd like to give this suggestion a load of up-votes!

Hartebee5t avatar Dec 31 '22 18:12 Hartebee5t

It's not clear to me if this repo is accepting PR's. I could try it, it would be fun since idk how to develop in python.

mhcgolds avatar Jan 01 '23 13:01 mhcgolds

Could be something like this(karaoke.py):

  • New method is_user_in_queue:
def is_user_in_queue(self, user):
        for each in self.queue:
            if each["user"] == user:
                return True
        return False
  • Changes to enqueue method:
def enqueue(self, song_path, user="Pikaraoke"):
        if (self.is_song_in_queue(song_path)):
            logging.warn("Song is already in queue, will not add: " + song_path)   
            return False
        elif (self.is_user_in_queue(user)):
            logging.warn("User is already in queue, will not add:" + user)   
            return False
        else:
            logging.info("'%s' is adding song to queue: %s" % (user, song_path))
            self.queue.append({"user": user, "file": song_path, "title": self.filename_from_path(song_path)})
            return True

I'm not sure if its the best approach neither if its correct (not a python developer).

mhcgolds avatar Jan 02 '23 14:01 mhcgolds

With this updated condition, user is also blocked to add new songs even while his song is playing:

elif (self.now_playing_user == user or self.is_user_in_queue(user)):

The code i've posted seems to work, but the message is the same for "Song already in queue", not sure how to adjust the message since the method returns only true or false and the message is based on that.

mhcgolds avatar Jan 03 '23 13:01 mhcgolds

The message is handled in: search.html:198 however as you say it's just a boolean.

In order to distinguish, you'd could modify the enqueue function to return a tuple including the error message, such as return (False, "User already in queue"). Then modify all downstream calls ( particularly the api endpoint at app.py:191 ) to get the success state boolean via rc(0) and the error message from rc(1)

Edit: correction boolean from: rc[0] message from rc[1]

vicwomg avatar Jan 03 '23 17:01 vicwomg

This feature should also be disabled by default and perhaps enabled by a command line option. Most home users would not want to limit this.

vicwomg avatar Jan 03 '23 17:01 vicwomg

The message is handled in: search.html:198 however as you say it's just a boolean.

In order to distinguish, you'd could modify the enqueue function to return a tuple including the error message, such as return (False, "User already in queue"). Then modify all downstream calls ( particularly the api endpoint at app.py:191 ) to get the success state boolean via rc(0) and the error message from rc(1)

Edit: correction boolean from: rc[0] message from rc[1]

Nice. It woudn't be a big update to achieve that feature then.

This feature should also be disabled by default and perhaps enabled by a command line option. Most home users would not want to limit this.

Sure, thats why i said "an option to limit users".

mhcgolds avatar Jan 04 '23 12:01 mhcgolds