Skip to content
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

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

hoffie
Copy link
Contributor

@hoffie hoffie commented Apr 7, 2024

Fix PlayerMPD.prev/next() when stopped

  • 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 #2294
Fixes #2327

@hoffie hoffie force-pushed the fix-prev-next-while-stopped branch from a0e56d0 to 8cc0323 Compare April 7, 2024 20:25
@s-martin s-martin added bug future3 Relates to future3 development labels Apr 7, 2024
@s-martin s-martin linked an issue Apr 7, 2024 that may be closed by this pull request
@pabera pabera added this to the v3.6 milestone Apr 8, 2024
@pabera pabera self-requested a review April 8, 2024 09:12
@pabera pabera linked an issue Apr 8, 2024 that may be closed by this pull request
@hoffie hoffie force-pushed the fix-prev-next-while-stopped branch from 8cc0323 to 76b5c6d Compare April 11, 2024 20:41
@coveralls
Copy link

coveralls commented Apr 11, 2024

Pull Request Test Coverage Report for Build 8661575867

Details

  • 1 of 6 (16.67%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 38.235%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/jukebox/jukebox/utils.py 1 6 16.67%
Totals Coverage Status
Change from base Build 8605260930: -0.1%
Covered Lines: 494
Relevant Lines: 1292

💛 - Coveralls

Copy link
Collaborator

@pabera pabera left a 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.

@pabera pabera mentioned this pull request Apr 11, 2024
@s-martin
Copy link
Collaborator

No action could be a third option, but that could also be added in a later PR.

#2327 (comment)

@hoffie hoffie force-pushed the fix-prev-next-while-stopped branch 2 times, most recently from 3554511 to f34bc74 Compare April 11, 2024 22:30
@hoffie
Copy link
Contributor Author

hoffie commented Apr 11, 2024

No action could be a third option, but that could also be added in a later PR.

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?).

Comment on lines 248 to 272
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]

Copy link
Collaborator

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)

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@hoffie hoffie force-pushed the fix-prev-next-while-stopped branch from f34bc74 to 1e770ea Compare April 12, 2024 11:31
pabera and others added 2 commits April 12, 2024 13:50
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]>
@hoffie hoffie force-pushed the fix-prev-next-while-stopped branch from 1e770ea to ac24a06 Compare April 12, 2024 11:50
@pabera pabera merged commit a9ab571 into MiczFlor:future3/develop Apr 12, 2024
22 checks passed
@s-martin s-martin modified the milestones: v3.6, v2.7.0 May 5, 2024
@pabera pabera removed this from the v2.7.0 milestone Nov 25, 2024
@pabera pabera added this to the v3.6 milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug future3 Relates to future3 development
Projects
None yet
4 participants