pikaraoke
pikaraoke copied to clipboard
Feature request: limit queue entries for users
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.
I'd like to give this suggestion a load of up-votes!
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.
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).
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.
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]
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.
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 atapp.py:191
) to get the success state boolean viarc(0)
and the error message fromrc(1)
Edit: correction boolean from:
rc[0]
message fromrc[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".