diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 763440238..70477a624 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -210,6 +210,9 @@ class ArtSource(RequestMixin): def fetch_image(self, candidate, plugin): raise NotImplementedError() + def cleanup(self, candidate): + pass + class LocalArtSource(ArtSource): IS_LOCAL = True @@ -291,6 +294,13 @@ class RemoteArtSource(ArtSource): self._log.debug(u'error fetching art: {}', exc) return + def cleanup(self, candidate): + if candidate.path: + try: + util.remove(path=candidate.path) + except util.FilesystemError as exc: + self._log.debug(u'error cleaning up tmp art: {}', exc) + class CoverArtArchive(RemoteArtSource): NAME = u"Cover Art Archive" @@ -1017,6 +1027,8 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): u'using {0.LOC_STR} image {1}'.format( source, util.displayable_path(out.path))) break + # Remove temporary files for invalid candidates. + source.cleanup(candidate) if out: break diff --git a/beetsplug/web/__init__.py b/beetsplug/web/__init__.py index 21ff5d94e..49149772d 100644 --- a/beetsplug/web/__init__.py +++ b/beetsplug/web/__init__.py @@ -177,10 +177,11 @@ class QueryConverter(PathConverter): """ def to_python(self, value): - return value.split('/') + queries = value.split('/') + return [query.replace('\\', os.sep) for query in queries] def to_url(self, value): - return ','.join(value) + return ','.join([v.replace(os.sep, '\\') for v in value]) class EverythingConverter(PathConverter): diff --git a/docs/changelog.rst b/docs/changelog.rst index 5434e8b13..abb6846c6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -118,12 +118,18 @@ New features: * The classes ``AlbumInfo`` and ``TrackInfo`` now have flexible attributes, allowing to solve :bug:`1547`. Thanks to :user:`dosoe`. +* :doc:`/plugins/web`: The query API now interprets backslashes as path + separators to support path queries. + Thanks to :user:`nmeum`. + :bug:`3567` Fixes: -* :doc:`/plugins/fetchart`: Fixed a bug that caused fetchart to not take +* :doc:`/plugins/fetchart`: Fixed a bug that caused fetchart to not take environment variables such as proxy servers into account when making requests :bug:`3450` +* :doc:`/plugins/fetchart`: Temporary files for fetched album art that fail + validation are now removed * :doc:`/plugins/inline`: In function-style field definitions that refer to flexible attributes, values could stick around from one function invocation to the next. This meant that, when displaying a list of objects, later diff --git a/docs/plugins/web.rst b/docs/plugins/web.rst index d416b1b7d..65d4743fb 100644 --- a/docs/plugins/web.rst +++ b/docs/plugins/web.rst @@ -210,7 +210,8 @@ If the server runs UNIX, you'll need to include an extra leading slash: ``GET /item/query/querystring`` +++++++++++++++++++++++++++++++ -Returns a list of tracks matching the query. The *querystring* must be a valid query as described in :doc:`/reference/query`. :: +Returns a list of tracks matching the query. The *querystring* must be a +valid query as described in :doc:`/reference/query`. :: { "results": [ @@ -219,6 +220,11 @@ Returns a list of tracks matching the query. The *querystring* must be a valid q ] } +Path elements are joined as parts of a query. For example, +``/item/query/foo/bar`` will be converted to the query ``foo,bar``. +To specify literal path separators in a query, use a backslash instead of a +slash. + ``GET /item/6/file`` ++++++++++++++++++++