From f6df14a7982eb0af913fbe4bdf28ed0c7d8ee233 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 14 Mar 2015 15:13:07 -0700 Subject: [PATCH] Isolate bugs in pylast Should fix crashes like this: http://hastebin.com/nizusukuli.log --- beetsplug/lastgenre/__init__.py | 20 +++++++++++++------- docs/changelog.rst | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/beetsplug/lastgenre/__init__.py b/beetsplug/lastgenre/__init__.py index e65593730..ab0e22be9 100644 --- a/beetsplug/lastgenre/__init__.py +++ b/beetsplug/lastgenre/__init__.py @@ -26,6 +26,7 @@ https://gist.github.com/1241307 import pylast import os import yaml +import traceback from beets import plugins from beets import ui @@ -391,17 +392,22 @@ class LastGenrePlugin(plugins.BeetsPlugin): If `min_weight` is specified, tags are filtered by weight. """ + # Work around an inconsistency in pylast where + # Album.get_top_tags() does not return TopItem instances. + # https://code.google.com/p/pylast/issues/detail?id=85 + if isinstance(obj, pylast.Album): + obj = super(pylast.Album, obj) + try: - # Work around an inconsistency in pylast where - # Album.get_top_tags() does not return TopItem instances. - # https://code.google.com/p/pylast/issues/detail?id=85 - if isinstance(obj, pylast.Album): - res = super(pylast.Album, obj).get_top_tags() - else: - res = obj.get_top_tags() + res = obj.get_top_tags() except PYLAST_EXCEPTIONS as exc: self._log.debug(u'last.fm error: {0}', exc) return [] + except Exception as exc: + # Isolate bugs in pylast. + self._log.debug(traceback.format_exc()) + self._log.error('error in pylast library: {0}', exc) + return [] # Filter by weight (optionally). if min_weight: diff --git a/docs/changelog.rst b/docs/changelog.rst index 693c4b1d8..b222e3ad8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -123,6 +123,8 @@ Fixes: Unicode filenames. :bug:`1297` * :doc:`/plugins/discogs`: Handle and log more kinds of communication errors. :bug:`1299` :bug:`1305` +* :doc:`/plugins/lastgenre`: Bugs in the `pylast` library can no longer crash + beets. For developers: