From 0ca2ce025817db215e78de297e2bac3380b369ab Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Thu, 31 May 2018 23:00:46 +0100 Subject: Build URI parameters correctly for artists/tracks with non-latin characters --- lastfm_similarity.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lastfm_similarity.py b/lastfm_similarity.py index 1300157..d2e04ba 100644 --- a/lastfm_similarity.py +++ b/lastfm_similarity.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """Last.fm similarity plugin for Quod Libet.""" import json +from urllib.parse import quote from urllib.request import urlopen from urllib.error import URLError import random @@ -106,8 +107,8 @@ class LastFMSimilarity(EventPlugin): else: print_d("Trying with {} - {}".format(artistname.splitlines()[0], trackname)) - request = "".join((request, "&track=", trackname, "&artist=", - artistname.splitlines()[0])) + request = "".join((request, "&track=", quote(trackname), "&artist=", + quote(artistname.splitlines()[0]))) request = "".join((request, "&limit={}".format(limit))) @@ -151,7 +152,7 @@ class LastFMSimilarity(EventPlugin): else: print_d("Trying with {}".format(artistname.splitlines()[0])) request = "".join((request, "&artist=", - artistname.splitlines()[0])) + quote(artistname.splitlines()[0]))) request = "".join((request, "&limit={}".format(limit))) @@ -210,7 +211,6 @@ class LastFMSimilarity(EventPlugin): % (candidate[0], candidate[1])) try: results = list(filter(query.search, app.library)) - print_d("results: %s" % results) if results: song = results[0] @@ -234,7 +234,6 @@ class LastFMSimilarity(EventPlugin): "&(artist = \"%s\", title != \"[silence]\")" % artist) try: results = list(filter(query.search, app.library)) - print_d("results: %s" % results) candidate_song_length = len(results) for dummy in range(candidate_song_length): -- cgit v1.2.3