From c27907b043bf4480de18994a6f19ff90ac5ed251 Mon Sep 17 00:00:00 2001 From: wordofglass Date: Sat, 16 Apr 2016 14:10:54 +0200 Subject: [PATCH 1/5] enable fetchart to store the artworks origin in a flexible field; as of now untested --- beetsplug/fetchart.py | 36 +++++++++++++++++++++++------------- docs/plugins/fetchart.rst | 13 +++++++++++++ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index c00124623..5c005656a 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -660,9 +660,9 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): def __init__(self): super(FetchArtPlugin, self).__init__() - # Holds paths to downloaded images between fetching them and - # placing them in the filesystem. - self.art_paths = {} + # Holds candidates corresponding to downloaded images between + # fetching them and placing them in the filesystem. + self.art_candidates = {} self.config.add({ 'auto': True, @@ -675,7 +675,8 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): 'coverart', 'itunes', 'amazon', 'albumart'], 'google_key': None, 'google_engine': u'001442825323518660753:hrh5ch1gjzm', - 'fanarttv_key': None + 'fanarttv_key': None, + 'store_origin': False }) self.config['google_key'].redact = True self.config['fanarttv_key'].redact = True @@ -703,6 +704,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): cover_names = self.config['cover_names'].as_str_seq() self.cover_names = map(util.bytestring_path, cover_names) self.cautious = self.config['cautious'].get(bool) + self.store_origin = self.config['store_origin'].get(bool) self.src_removed = (config['import']['delete'].get(bool) or config['import']['move'].get(bool)) @@ -753,19 +755,28 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): candidate = self.art_for_album(task.album, task.paths, local) if candidate: - self.art_paths[task] = candidate.path + self.art_candidates[task] = candidate + + def _set_art(self, album, candidate, delete=False): + album.set_art(candidate.path, delete) + if self.store_origin: + # store the origin of the chosen artwork in a flexible field + self._log.debug( + u"Storing artorigin for {0.albumartist} - {0.album}", + album) + album.artorigin = candidate.source + album.store() # Synchronous; after music files are put in place. def assign_art(self, session, task): """Place the discovered art in the filesystem.""" - if task in self.art_paths: - path = self.art_paths.pop(task) + if task in self.art_candidates: + candidate = self.art_candidates.pop(task) + + self._set_art(task.album, candidate, not self.src_removed) - album = task.album - album.set_art(path, not self.src_removed) - album.store() if self.src_removed: - task.prune(path) + task.prune(candidate.path) # Manual album art fetching. def commands(self): @@ -842,8 +853,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): candidate = self.art_for_album(album, local_paths) if candidate: - album.set_art(candidate.path, False) - album.store() + self._set_art(album, candidate) message = ui.colorize('text_success', u'found album art') else: message = ui.colorize('text_error', u'no art found') diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index 591dbc4b4..72745e73a 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -62,6 +62,9 @@ file. The available options are: Default: The `beets custom search engine`_, which searches the entire web. **fanarttv_key**: The personal API key for requesting art from fanart.tv. See below. + **store_origin**: If enabled, fetchart store the artwork's source in a + flexible tag. See below for the rationale behind this. + Default: ``no``. Note: ``minwidth`` and ``enforce_ratio`` options require either `ImageMagick`_ or `Pillow`_. @@ -182,6 +185,16 @@ personal key will give you earlier access to new art. .. _on their blog: https://fanart.tv/2015/01/personal-api-keys/ +Storing the artwork's origin +---------------------------- + +Storing the current artwork's source gives the opportunity to selectively +search for new art. For example, if some albums have artwork placed manually in +their directories that should not be replaced by a forced album art fetch, you +could do + +``beet fetchart -f ^artorigin:filesystem`` + Embedding Album Art ------------------- From 740efc0a0e14fab57abf9d86e8b1b9cb0d488c8d Mon Sep 17 00:00:00 2001 From: wordofglass Date: Sat, 16 Apr 2016 21:32:04 +0200 Subject: [PATCH 2/5] small fixes; consistently use 'source' instead of 'origin' --- beetsplug/fetchart.py | 12 ++++++------ docs/plugins/fetchart.rst | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 5c005656a..291181db7 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -676,7 +676,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): 'google_key': None, 'google_engine': u'001442825323518660753:hrh5ch1gjzm', 'fanarttv_key': None, - 'store_origin': False + 'store_source': False, }) self.config['google_key'].redact = True self.config['fanarttv_key'].redact = True @@ -704,7 +704,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): cover_names = self.config['cover_names'].as_str_seq() self.cover_names = map(util.bytestring_path, cover_names) self.cautious = self.config['cautious'].get(bool) - self.store_origin = self.config['store_origin'].get(bool) + self.store_source = self.config['store_source'].get(bool) self.src_removed = (config['import']['delete'].get(bool) or config['import']['move'].get(bool)) @@ -759,12 +759,12 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): def _set_art(self, album, candidate, delete=False): album.set_art(candidate.path, delete) - if self.store_origin: - # store the origin of the chosen artwork in a flexible field + if self.store_source: + # store the source of the chosen artwork in a flexible field self._log.debug( - u"Storing artorigin for {0.albumartist} - {0.album}", + u"Storing art_source for {0.albumartist} - {0.album}", album) - album.artorigin = candidate.source + album.art_source = candidate.source album.store() # Synchronous; after music files are put in place. diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index 72745e73a..04ee5d699 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -62,8 +62,8 @@ file. The available options are: Default: The `beets custom search engine`_, which searches the entire web. **fanarttv_key**: The personal API key for requesting art from fanart.tv. See below. - **store_origin**: If enabled, fetchart store the artwork's source in a - flexible tag. See below for the rationale behind this. +- **store_source**: If enabled, fetchart store the artwork's source in a + flexible tag named ``art_source``. See below for the rationale behind this. Default: ``no``. Note: ``minwidth`` and ``enforce_ratio`` options require either `ImageMagick`_ @@ -185,7 +185,7 @@ personal key will give you earlier access to new art. .. _on their blog: https://fanart.tv/2015/01/personal-api-keys/ -Storing the artwork's origin +Storing the Artwork's Source ---------------------------- Storing the current artwork's source gives the opportunity to selectively @@ -193,7 +193,7 @@ search for new art. For example, if some albums have artwork placed manually in their directories that should not be replaced by a forced album art fetch, you could do -``beet fetchart -f ^artorigin:filesystem`` +``beet fetchart -f ^art_source:filesystem`` Embedding Album Art ------------------- From ec4595677064de4e264d3ff35757e94d1d891d8e Mon Sep 17 00:00:00 2001 From: wordofglass Date: Sat, 16 Apr 2016 21:36:46 +0200 Subject: [PATCH 3/5] update changelog --- docs/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index c9e8ed67b..721c9ab8a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,6 +18,8 @@ New features: * :doc:`/plugins/fetchart`: The ``enforce_ratio`` option was enhanced and now allows specifying a certain deviation that a valid image may have from being exactly square. +* :doc:`/plugins/fetchart`: The plugin can now optionally save the artwork's + source in a flexible field; for a usecase see the documentation. * :doc:`/plugins/export`: A new plugin to export the data from queries to a json format. Thanks to :user:`GuilhermeHideki`. From 7a9c3e592b37fffa24b6f5a9fa952f4b2beae197 Mon Sep 17 00:00:00 2001 From: wordofglass Date: Sun, 17 Apr 2016 14:18:01 +0200 Subject: [PATCH 4/5] document values written to art_source --- docs/plugins/fetchart.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index 04ee5d699..f59761bbb 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -195,6 +195,12 @@ could do ``beet fetchart -f ^art_source:filesystem`` +The values written to ``art_source`` are: + +``'Cover Art Archive'``, ``'Amazon'``, ``'AlbumArt.org scraper'``, ``'Google Images'``, +``'fanart.tv'``, ``'iTunes Store'``, ``'Wikipedia (queried through DBpedia)'``, +``'Filesystem'`` + Embedding Album Art ------------------- From 5fbca32ea44cb0c4490b95ab516c52aa097682d9 Mon Sep 17 00:00:00 2001 From: wordofglass Date: Sun, 17 Apr 2016 20:15:12 +0200 Subject: [PATCH 5/5] reuse the 'sources' names from the configuration for art_source --- beetsplug/fetchart.py | 4 ++-- docs/plugins/fetchart.rst | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 291181db7..db4d0034e 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -197,7 +197,7 @@ class ArtSource(RequestMixin): raise NotImplementedError() def _candidate(self, **kwargs): - return Candidate(source=self.NAME, log=self._log, **kwargs) + return Candidate(source=self, log=self._log, **kwargs) def fetch_image(self, candidate, extra): raise NotImplementedError() @@ -764,7 +764,7 @@ class FetchArtPlugin(plugins.BeetsPlugin, RequestMixin): self._log.debug( u"Storing art_source for {0.albumartist} - {0.album}", album) - album.art_source = candidate.source + album.art_source = SOURCE_NAMES[type(candidate.source)] album.store() # Synchronous; after music files are put in place. diff --git a/docs/plugins/fetchart.rst b/docs/plugins/fetchart.rst index f59761bbb..2812c7745 100644 --- a/docs/plugins/fetchart.rst +++ b/docs/plugins/fetchart.rst @@ -62,7 +62,7 @@ file. The available options are: Default: The `beets custom search engine`_, which searches the entire web. **fanarttv_key**: The personal API key for requesting art from fanart.tv. See below. -- **store_source**: If enabled, fetchart store the artwork's source in a +- **store_source**: If enabled, fetchart stores the artwork's source in a flexible tag named ``art_source``. See below for the rationale behind this. Default: ``no``. @@ -188,18 +188,15 @@ personal key will give you earlier access to new art. Storing the Artwork's Source ---------------------------- -Storing the current artwork's source gives the opportunity to selectively -search for new art. For example, if some albums have artwork placed manually in -their directories that should not be replaced by a forced album art fetch, you -could do +Storing the current artwork's source might be used to narrow down +``fetchart`` commands. For example, if some albums have artwork placed +manually in their directories that should not be replaced by a forced +album art fetch, you could do ``beet fetchart -f ^art_source:filesystem`` -The values written to ``art_source`` are: - -``'Cover Art Archive'``, ``'Amazon'``, ``'AlbumArt.org scraper'``, ``'Google Images'``, -``'fanart.tv'``, ``'iTunes Store'``, ``'Wikipedia (queried through DBpedia)'``, -``'Filesystem'`` +The values written to ``art_source`` are the same names used in the ``sources`` +configuration value. Embedding Album Art -------------------