summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2018-06-15 19:57:39 +0100
committerMichaël Ball <michael.ball@gmail.com>2018-06-15 19:57:39 +0100
commit57827d9ed06fefb15cc96a01098c38b7becb8f8c (patch)
tree3c2f52e65e78b8801b96d0a4639a64db92d1ebd2
parentcd64bb1989ebbdb06500d8ba58a123eea2198d6c (diff)
Improve similarity checking
-rw-r--r--lastfm_similarity.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/lastfm_similarity.py b/lastfm_similarity.py
index ce0d605..f381d23 100644
--- a/lastfm_similarity.py
+++ b/lastfm_similarity.py
@@ -58,7 +58,7 @@ class LastFMSimilarity(EventPlugin):
def strictness_changed(entry):
self._similarity_strictness = entry.get_value() / 10
config.set("plugins", "lastfm_similarity_strictness",
- self._track_similarity_strictness)
+ self._similarity_strictness)
table = Gtk.Table(rows=3, columns=2)
table.set_row_spacings(6)
@@ -126,8 +126,8 @@ class LastFMSimilarity(EventPlugin):
else:
print_d("Trying with {} - {}".format(artistname.splitlines()[0],
trackname))
- request = "".join((request, "&track=", quote(trackname), "&artist=",
- quote(artistname.splitlines()[0])))
+ request = "".join((request, "&track=", quote(trackname),
+ "&artist=", quote(artistname.splitlines()[0])))
request = "".join((request, "&limit={}".format(limit)))
@@ -147,7 +147,9 @@ class LastFMSimilarity(EventPlugin):
response = json.loads(str(stream.read(), "utf-8"))
for track in response["similartracks"]["track"]:
- if track["match"] >= self._similarity_strictness:
+ similarity_score = float(track["match"])
+
+ if similarity_score >= self._similarity_strictness:
similar_tracks.append(
(track["artist"]["name"], track["name"]))
@@ -158,6 +160,8 @@ class LastFMSimilarity(EventPlugin):
return self._find_similar_tracks(trackname, artistname)
return []
+ except (ValueError, OverflowError):
+ return []
else:
return []
@@ -192,7 +196,9 @@ class LastFMSimilarity(EventPlugin):
response = json.loads(str(stream.read(), "utf-8"))
for artist in response["similarartists"]["artist"]:
- if artist["match"] >= self._similarity_strictness:
+ similarity_score = float(artist["match"])
+
+ if similarity_score >= self._similarity_strictness:
similar_artists.append(artist["name"])
return similar_artists
@@ -202,6 +208,8 @@ class LastFMSimilarity(EventPlugin):
return self._find_similar_artists(artistname)
return []
+ except (ValueError, OverflowError):
+ return []
else:
return []