-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PlayerMPD.prev/next() when stopped #2326
Fix PlayerMPD.prev/next() when stopped #2326
Conversation
a0e56d0
to
8cc0323
Compare
8cc0323
to
76b5c6d
Compare
Pull Request Test Coverage Report for Build 8661575867Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no additional work required on this PR, this can be merged.
No action could be a third option, but that could also be added in a later PR. |
3554511
to
f34bc74
Compare
Added now. As there have been further changes for #2327, this PR needs another review and new testing (I haven't tested the most recent state yet, maybe @IgorWalton can help?). |
def decode_prev_next_actions(self): | ||
end_of_playlist_next_action = cfg.setndefault('playermpd', 'end_of_playlist_next_action', value='').lower() | ||
if end_of_playlist_next_action not in self.end_of_playlist_next_action_dict: | ||
end_of_playlist_next_action = 'stop' | ||
logger.error(f"Config playermpd.end_of_playlist_next_action must be one of " | ||
f"{self.end_of_playlist_next_action.keys()}. " | ||
f"Using default 'stop'") | ||
self.end_of_playlist_next_action = self.end_of_playlist_next_action_dict[end_of_playlist_next_action] | ||
|
||
stopped_prev_action = cfg.setndefault('playermpd', 'stopped_prev_action', value='').lower() | ||
if stopped_prev_action not in self.stopped_prev_action_dict: | ||
stopped_prev_action = 'prev' | ||
logger.error(f"Config playermpd.stopped_prev_action must be one of " | ||
f"{self.stopped_prev_action.keys()}. " | ||
f"Using default 'prev'") | ||
self.stopped_prev_action = self.stopped_prev_action_dict[stopped_prev_action] | ||
|
||
stopped_next_action = cfg.setndefault('playermpd', 'stopped_prev_action', value='').lower() | ||
if stopped_next_action not in self.stopped_prev_action_dict: | ||
stopped_next_action = 'prev' | ||
logger.error(f"Config playermpd.stopped_next_action must be one of " | ||
f"{self.stopped_next_action.keys()}. " | ||
f"Using default 'next'") | ||
self.stopped_next_action = self.stopped_prev_action_dict[stopped_prev_action] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a few aspects that are redundant, or could be abstracted..
Tried to quickly wrap my head around this..
Could this maybe work? (method naming could probably improved :-) )
def get_config_action(cfg, section, option, default, valid_actions_dict, logger):
action = cfg.setndefault(section, option, value='').lower()
if action not in valid_actions_dict:
logger.error(f"Config {section}.{option} must be one of {valid_actions_dict.keys()}. Using default '{default}'")
action = default
return valid_actions_dict[action]
def decode_prev_next_actions(self):
self.end_of_playlist_next_action = get_config_action(
cfg, 'playermpd', 'end_of_playlist_next_action', 'stop',
self.end_of_playlist_next_action_dict, logger)
self.stopped_prev_action = get_config_action(
cfg, 'playermpd', 'stopped_prev_action', 'prev',
self.stopped_prev_action_dict, logger)
self.stopped_next_action = get_config_action(
cfg, 'playermpd', 'stopped_next_action', 'next',
self.stopped_next_action_dict, logger)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way, you might even be able to rethink how to define the actions in the first place (is decode_prev_next_actions
then still required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea! I've taken your standalone function and put it into jukebox.utils, where similar functions live. I've reworked the prev/next logic to make use of that function directly.
f34bc74
to
1e770ea
Compare
This abstracts away the functionality to resolve a given config option to an action in a pre-defined dict. Co-authored-by: Christian Hoffmann <[email protected]>
* Avoid MPD-related crashes during all prev/next() calls. * Explicitly handle prev() in stopped state, configurable via `playermpd.stopped_prev_action`. * Explicitly handle next() in stopped state, configurable via `playermpd.stopped_next_action`. * Explicitly handle next() when reaching the end of the playlist: jukebox-daemon will now ignore the action by default (similar to v2). It can also be configured to rewind the playlist instead by setting the new config option `playermpd.end_of_playlist_next_action: rewind` or to stop playing. Fixes MiczFlor#2294 Fixes MiczFlor#2327 Co-authored-by: pabera <[email protected]>
1e770ea
to
ac24a06
Compare
Fix PlayerMPD.prev/next() when stopped
playermpd.stopped_prev_action
.playermpd.stopped_next_action
.jukebox-daemon will now ignore the action by default (similar to v2).
It can also be configured to rewind the playlist instead by setting
the new config option
playermpd.end_of_playlist_next_action: rewind
or to stop playing.
Fixes #2294
Fixes #2327