Repository: beetbox/beets

Issue:
fetchart | tracks don't have cover, but beet says "...has album art"
Using the <code>fetchart</code> plugin to grab an image fails, because it still thinks my tracks still has albumart when indeed it doesn't.

Ofcourse, I then made sure there was no coverart
<code>$ beet clearart query</code> 
and then then re-checked the fetchart, but no luck.
 <code>$ beet fetchart query</code>

reason is I issued a <code>--force</code> (generically websearch) parameter to grab an imediate image link. 
<code>$ beet fetchart -f query</code>

Now I want to test fetchart's <code>sources:</code>, especially with itunes but I can't if beets say's that the query results already has an album art when there is none on the tag/directory

fetchart | tracks don't have cover, but beet says "...has album art"
Using the <code>fetchart</code> plugin to grab an image fails, because it still thinks my tracks still has albumart when indeed it doesn't.

Ofcourse, I then made sure there was no coverart
<code>$ beet clearart query</code> 
and then then re-checked the fetchart, but no luck.
 <code>$ beet fetchart query</code>

reason is I issued a <code>--force</code> (generically websearch) parameter to grab an imediate image link. 
<code>$ beet fetchart -f query</code>

Now I want to test fetchart's <code>sources:</code>, especially with itunes but I can't if beets say's that the query results already has an album art when there is none on the tag/directory



Discussion:
The `clearart` command removes embedded art, not associated files. Running `fetchart` with the `-f` flag should query your sources again. Can you expand on what goes wrong with `beet fetchart -f` now?

because fetchart indicates that the query has album art I needed to remove the embeded/physical image. BTW, I don't personally keep anything else besides music files in my music library directory.

Sorry, I should have been more explicit—what does the command output?

When I run it, even twice in a row:

```
$ beet fetchart -f
Aesop Rock - None Shall Pass: found album art
$ beet fetchart -f
Aesop Rock - None Shall Pass: found album art
```

it fetches new art each time, even though the album already has an image associated.

So, even though my query has no coverart embeded or in directory, beet still can't fetch art as it mentions it still has an album art.

I've removed coverart for this one album, then attempted to fetchart after removal, but failed as it reports saying still 'has album art'.

$ beet clearart album: III
Clearing album art from items:
BADBADNOTGOOD - Triangle
BADBADNOTGOOD - Can't Leave the Night
BADBADNOTGOOD - Kaleidoscope
BADBADNOTGOOD - Eyes Closed
BADBADNOTGOOD - Hedron
BADBADNOTGOOD - Differently, Still
BADBADNOTGOOD - Since You Asked Kindly
BADBADNOTGOOD - CS60
BADBADNOTGOOD - Sustain
BADBADNOTGOOD feat. Leland Whitty - Confessions
$ beet fetchart album: III
BADBADNOTGOOD - III: has album art

There is no coverart in the directory aswell.

$ ls -all
total 344232
drwxrwxrwx 1 root root     4096 Dec  1 20:55 .
drwxrwxrwx 1 root root        0 Dec  1 20:38 ..
-rwxrwxrwx 1 root root 25609485 Dec  1 21:09 01-01 Triangle.flac
-rwxrwxrwx 1 root root 29453785 Dec  1 21:09 01-02 Can't Leave the Night.flac
-rwxrwxrwx 1 root root 32617426 Dec  1 21:09 01-03 Confessions.flac
-rwxrwxrwx 1 root root 48488938 Dec  1 21:09 01-04 Kaleidoscope.flac
-rwxrwxrwx 1 root root 37144117 Dec  1 21:09 01-05 Eyes Closed.flac
-rwxrwxrwx 1 root root 36326432 Dec  1 21:09 01-06 Hedron.flac
-rwxrwxrwx 1 root root 29699646 Dec  1 21:09 01-07 Differently, Still.flac
-rwxrwxrwx 1 root root 29768000 Dec  1 21:09 01-08 Since You Asked Kindly.flac
-rwxrwxrwx 1 root root 43514948 Dec  1 21:09 01-09 CS60.flac
-rwxrwxrwx 1 root root 39848177 Dec  1 21:09 01-10 Sustain.flac

(please remove this 'parenthesized' text and add the appropriate markdown syntax to emphasize code, I couldn't have avoided it to be in paragraph form)

As I explained above, you do not need to run `clearart`, but you _do_ need to use the `-f` flag with `fetchart`. What happens when you run that?

@sampsyo the <code>-f</code> flag checks some web-source i'm actually not sure of and it's always the same image too regardless of my <code>sources:</code> order.

I know this, becuase I set my <code>sources: itunes</code> only and it still pulls that web-source image instead as it's completely different from the itunes album page.

According to the wiki:
"...(-f flag) searches for art in Web databases regardless (of sources)"

The `-f` flag searches your configured source list (including iTunes).

If you're suspicious that the plugin isn't searching the right sources, you can try verbose mode to see if there are any clues:

```
$ beet -v fetchart -f
```

The `clearart` command removes embedded art, not associated files. Running `fetchart` with the `-f` flag should query your sources again. Can you expand on what goes wrong with `beet fetchart -f` now?

because fetchart indicates that the query has album art I needed to remove the embeded/physical image. BTW, I don't personally keep anything else besides music files in my music library directory.

Sorry, I should have been more explicit—what does the command output?

When I run it, even twice in a row:

```
$ beet fetchart -f
Aesop Rock - None Shall Pass: found album art
$ beet fetchart -f
Aesop Rock - None Shall Pass: found album art
```

it fetches new art each time, even though the album already has an image associated.

So, even though my query has no coverart embeded or in directory, beet still can't fetch art as it mentions it still has an album art.

I've removed coverart for this one album, then attempted to fetchart after removal, but failed as it reports saying still 'has album art'.

$ beet clearart album: III
Clearing album art from items:
BADBADNOTGOOD - Triangle
BADBADNOTGOOD - Can't Leave the Night
BADBADNOTGOOD - Kaleidoscope
BADBADNOTGOOD - Eyes Closed
BADBADNOTGOOD - Hedron
BADBADNOTGOOD - Differently, Still
BADBADNOTGOOD - Since You Asked Kindly
BADBADNOTGOOD - CS60
BADBADNOTGOOD - Sustain
BADBADNOTGOOD feat. Leland Whitty - Confessions
$ beet fetchart album: III
BADBADNOTGOOD - III: has album art

There is no coverart in the directory aswell.

$ ls -all
total 344232
drwxrwxrwx 1 root root     4096 Dec  1 20:55 .
drwxrwxrwx 1 root root        0 Dec  1 20:38 ..
-rwxrwxrwx 1 root root 25609485 Dec  1 21:09 01-01 Triangle.flac
-rwxrwxrwx 1 root root 29453785 Dec  1 21:09 01-02 Can't Leave the Night.flac
-rwxrwxrwx 1 root root 32617426 Dec  1 21:09 01-03 Confessions.flac
-rwxrwxrwx 1 root root 48488938 Dec  1 21:09 01-04 Kaleidoscope.flac
-rwxrwxrwx 1 root root 37144117 Dec  1 21:09 01-05 Eyes Closed.flac
-rwxrwxrwx 1 root root 36326432 Dec  1 21:09 01-06 Hedron.flac
-rwxrwxrwx 1 root root 29699646 Dec  1 21:09 01-07 Differently, Still.flac
-rwxrwxrwx 1 root root 29768000 Dec  1 21:09 01-08 Since You Asked Kindly.flac
-rwxrwxrwx 1 root root 43514948 Dec  1 21:09 01-09 CS60.flac
-rwxrwxrwx 1 root root 39848177 Dec  1 21:09 01-10 Sustain.flac

(please remove this 'parenthesized' text and add the appropriate markdown syntax to emphasize code, I couldn't have avoided it to be in paragraph form)

As I explained above, you do not need to run `clearart`, but you _do_ need to use the `-f` flag with `fetchart`. What happens when you run that?

@sampsyo the <code>-f</code> flag checks some web-source i'm actually not sure of and it's always the same image too regardless of my <code>sources:</code> order.

I know this, becuase I set my <code>sources: itunes</code> only and it still pulls that web-source image instead as it's completely different from the itunes album page.

According to the wiki:
"...(-f flag) searches for art in Web databases regardless (of sources)"

The `-f` flag searches your configured source list (including iTunes).

If you're suspicious that the plugin isn't searching the right sources, you can try verbose mode to see if there are any clues:

```
$ beet -v fetchart -f
```


Resolving patch:
diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py
--- a/beetsplug/fetchart.py
+++ b/beetsplug/fetchart.py
@@ -567,7 +567,7 @@ def batch_fetch_art(self, lib, albums, force):
         fetchart CLI command.
         """
         for album in albums:
-            if album.artpath and not force:
+            if album.artpath and not force and os.path.isfile(album.artpath):
                 message = ui.colorize('text_highlight_minor', 'has album art')
             else:
                 # In ordinary invocations, look for images on the


Test patch:
diff --git a/test/test_art.py b/test/test_art.py
--- a/test/test_art.py
+++ b/test/test_art.py
@@ -30,6 +30,7 @@
 from beets import importer
 from beets import config
 from beets import logging
+from beets import util
 from beets.util.artresizer import ArtResizer, WEBPROXY
 
 
@@ -357,6 +358,18 @@ def test_do_not_delete_original_if_already_in_place(self):
         self.afa_response = artdest
         self._fetch_art(True)
 
+    def test_fetch_art_if_imported_file_deleted(self):
+        # See #1126. Test the following scenario:
+        #   - Album art imported, `album.artpath` set.
+        #   - Imported album art file subsequently deleted (by user or other
+        #     program).
+        # `fetchart` should import album art again instead of printing the
+        # message "<album> has album art".
+        self._fetch_art(True)
+        util.remove(self.album.artpath)
+        self.plugin.batch_fetch_art(self.lib, self.lib.albums(), force=False)
+        self.assertExists(self.album.artpath)
+
 
 class ArtForAlbumTest(UseThePlugin):
     """ Tests that fetchart.art_for_album respects the size