summaryrefslogtreecommitdiff
path: root/lastfm_similarity.py
diff options
context:
space:
mode:
Diffstat (limited to 'lastfm_similarity.py')
-rw-r--r--lastfm_similarity.py33
1 files changed, 28 insertions, 5 deletions
diff --git a/lastfm_similarity.py b/lastfm_similarity.py
index d2e04ba..ce0d605 100644
--- a/lastfm_similarity.py
+++ b/lastfm_similarity.py
@@ -38,10 +38,11 @@ class LastFMSimilarity(EventPlugin):
"plugins", "lastfm_similarity_blacklist_tracks", 10)
self._blacklist_artist_count = config.getint(
"plugins", "lastfm_similarity_blacklist_artists", 10)
+ self._similarity_strictness = config.getfloat(
+ "plugins", "lastfm_similarity_strictness", 0.5)
self._last_tracks = []
self._last_artists = []
-
def PluginPreferences(self, parent):
"""Plugin Preferences."""
def blacklist_track_changed(entry):
@@ -54,7 +55,12 @@ class LastFMSimilarity(EventPlugin):
config.set("plugins", "lastfm_similarity_blacklist_artist",
self._blacklist_artist_count)
- table = Gtk.Table(rows=2, columns=2)
+ def strictness_changed(entry):
+ self._similarity_strictness = entry.get_value() / 10
+ config.set("plugins", "lastfm_similarity_strictness",
+ self._track_similarity_strictness)
+
+ table = Gtk.Table(rows=3, columns=2)
table.set_row_spacings(6)
table.set_col_spacings(6)
table.attach(
@@ -73,6 +79,19 @@ class LastFMSimilarity(EventPlugin):
self._blacklist_artist_count, 0, 1000, 1, 10, 0))
artist_entry.connect("value-changed", blacklist_artist_changed)
table.attach(artist_entry, 1, 2, 1, 2)
+ strictness_label = Gtk.Label(label=_("Similarity strictness:"))
+ strictness_label.set_alignment(1.0, 0.0)
+ table.attach(strictness_label, 0, 1, 2, 3,
+ xoptions=Gtk.AttachOptions.FILL)
+ strictness_adj = Gtk.Adjustment(lower=0.00, upper=10.00,
+ step_increment=0.1)
+ strictness_hscale = Gtk.HScale(adjustment=strictness_adj)
+ strictness_hscale.set_value(self._similarity_strictness * 10)
+ strictness_hscale.set_draw_value(False)
+ strictness_hscale.set_show_fill_level(False)
+ strictness_hscale.connect("value_changed", strictness_changed)
+ table.attach(strictness_hscale, 1, 2, 2, 3)
+
return table
def _check_artist_played(self, artist):
@@ -128,8 +147,9 @@ class LastFMSimilarity(EventPlugin):
response = json.loads(str(stream.read(), "utf-8"))
for track in response["similartracks"]["track"]:
- similar_tracks.append(
- (track["artist"]["name"], track["name"]))
+ if track["match"] >= self._similarity_strictness:
+ similar_tracks.append(
+ (track["artist"]["name"], track["name"]))
return similar_tracks
@@ -172,7 +192,8 @@ class LastFMSimilarity(EventPlugin):
response = json.loads(str(stream.read(), "utf-8"))
for artist in response["similarartists"]["artist"]:
- similar_artists.append(artist["name"])
+ if artist["match"] >= self._similarity_strictness:
+ similar_artists.append(artist["name"])
return similar_artists
@@ -200,6 +221,8 @@ class LastFMSimilarity(EventPlugin):
candidates = self._find_similar_tracks(track, artist)
if candidates:
+ random.shuffle(candidates)
+
for candidate in candidates:
if not self._check_artist_played(candidate[0]):