diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index ea0537988..9a6c99585 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -41,6 +41,10 @@ PYLAST_EXCEPTIONS = ( pylast.NetworkError, ) +REPLACE = { + u'\u2010': '-', +} + def deduplicate(seq): """Remove duplicates from sequence wile preserving order. @@ -238,7 +242,10 @@ class LastGenrePlugin(plugins.BeetsPlugin): def _cached_lookup(self, entity, method, *args): """Get a genre based on the named entity using the callable `method` whose arguments are given in the sequence `args`. The genre lookup - is cached based on the entity name and the arguments. + is cached based on the entity name and the arguments. Before the + lookup, each argument is has some Unicode characters replaced with + rough ASCII equivalents in order to return better results from the + Last.fm database. """ # Shortcut if we're missing metadata. if any(not s for s in args): @@ -248,7 +255,13 @@ class LastGenrePlugin(plugins.BeetsPlugin): if key in self._genre_cache: return self._genre_cache[key] else: - genre = self.fetch_genre(method(*args)) + args_replaced = [] + for arg in args: + for k, v in REPLACE.items(): + arg = arg.replace(k, v) + args_replaced.append(arg) + + genre = self.fetch_genre(method(*args_replaced)) self._genre_cache[key] = genre return genre