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
Changes from 3 commits
6f6de8d
fdc30c2
90a2489
4a77773
f9dbe7a
dd58cc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldSkip() -> should_skip() There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
rating = song("~#rating") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea; added a check for |
||
|
||
shouldSkip = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should_skip There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched to parentheses. |
||
song("skip") != '': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed comparison with |
||
shouldSkip = True | ||
print_d("Skip tag present; skipping...") | ||
|
||
return shouldSkip |
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.
Do I need
vb2
along withvb
here, or is that redundant? I copied this code from the duplicate songs plugin, but don't have the textbox above the checkboxes.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.
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.