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

Add skip by rating or tag #2201

Closed
wants to merge 6 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 83 additions & 0 deletions quodlibet/quodlibet/ext/playorder/skip_zeros.py
@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Nick Boultbee
# 2017 Jason Heard
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

from gi.repository import Gtk

from quodlibet import _, print_d, qltk
from quodlibet.order import OrderInOrder
from quodlibet.plugins import PluginConfigMixin
from quodlibet.plugins.playorder import ShufflePlugin
from quodlibet.qltk import Icons
from quodlibet.qltk.ccb import ConfigCheckButton


class SkipZeros(ShufflePlugin, OrderInOrder, PluginConfigMixin):
PLUGIN_ID = "skip_songs"
PLUGIN_NAME = _("Skip Songs")
PLUGIN_ICON = Icons.GO_JUMP
PLUGIN_DESC = _("Playback skips over songs with a rating of zero or with "
"a non-empty 'skip' tag unless they are explicitly "
"played.")

_CFG_SKIP_BY_RATING = 'skip_by_rating'
_CFG_SKIP_BY_TAG = 'skip_by_tag'

@classmethod
def PluginPreferences(self, window):
vb = Gtk.VBox(spacing=10)
vb.set_border_width(0)

# Matching Option
toggles = [
(self._CFG_SKIP_BY_RATING, _("Skip Songs with _Rating of Zero")),
(self._CFG_SKIP_BY_TAG,
_("Skip Songs with a Non-Empty 'skip' _Tag")),
]
vb2 = Gtk.VBox(spacing=6)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need vb2 along with vb here, or is that redundant? I copied this code from the duplicate songs plugin, but don't have the textbox above the checkboxes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could just return the frame and get rid of vb, but how it is now makes it easier to extend in the future.

for key, label in toggles:
ccb = ConfigCheckButton(label, 'plugins', self._config_key(key))
ccb.set_active(self.config_get_bool(key))
vb2.pack_start(ccb, True, True, 0)

frame = qltk.Frame(label=_("Skipping options"), child=vb2)
vb.pack_start(frame, True, True, 0)

vb.show_all()
return vb

def next(self, playlist, current):
next = super(SkipZeros, self).next(playlist, current)

while next is not None and self.shouldSkip(playlist, next):
next = super(SkipZeros, self).next(playlist, next)

return next

def previous(self, playlist, current):
previous = super(SkipZeros, self).previous(playlist, current)

while previous is not None and self.shouldSkip(playlist, previous):
previous = super(SkipZeros, self).previous(playlist, current)

return previous

def shouldSkip(self, playlist, song_iter):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldSkip() -> should_skip()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

song_index = playlist.get_path(song_iter).get_indices()[0]
song = playlist.get()[song_index]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a nicer way to get the song object using the iterator? I looked here but I didn't see a better way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playlist.get_value(song_iter) should work (from qltk.models.ObjectStore)

rating = song("~#rating")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~#rating defaults to the default rating if it isn't set, you might also want to check song.has_rating in case the default is set to 0 by the user.

Copy link
Author

@101100 101100 Jan 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea; added a check for has_rating.


shouldSkip = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should_skip

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if self.config_get_bool(self._CFG_SKIP_BY_RATING) and rating <= 0:
shouldSkip = True
print_d("Rating is %f; skipping..." % (rating))
elif self.config_get_bool(self._CFG_SKIP_BY_TAG) and \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI generally we prefer to use parentheses over multi-line expressions rather than \ at the end.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to parentheses.

song("skip") != '':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and song("skip") is more Pythonic I'd say

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed comparison with '' and moved and to the next line.

shouldSkip = True
print_d("Skip tag present; skipping...")

return shouldSkip