Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #314: Delete old album art during re-import #1681

Merged
merged 9 commits into from
Nov 4, 2015
Merged

Conversation

sampsyo
Copy link
Member

@sampsyo sampsyo commented Nov 2, 2015

Part of #1679 by @reiv.

With a few changes to importer.py, the re-import workflow deletes orphaned album art by keeping track of which files aren't reused by fetchart during the import process.

@sampsyo sampsyo changed the title Fix #314: delete old album art during re-import Fix #314: Delete old album art during re-import Nov 2, 2015
# to None, making self.prune() a no-op; hence this workaround of
# calling util.prune_dirs() directly.
util.prune_dirs(os.path.dirname(old_art_path),
clutter=config['clutter'].as_str_seq())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should leave any changes to pruning to a separate fix—let's just focus on album art for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, unless pruning for import -L works fine except for album art and this is just needed to keep the current functionality intact.

@sampsyo
Copy link
Member Author

sampsyo commented Nov 2, 2015

Here, we should probably write a test for two different situations:

  • No metadata changes, so the album stays in the same location.
  • The metadata changes so that the album needs to be moved to a new directory, and the art moved along with it.

In both cases, we should verify that we end up with exactly one image file (not two).

Also, while this strategy might work, it does have a drawback: we have to copy the image and then delete the old file. We should keep in mind an alternative, where either the importer or the fetchart plugin knows that this is a re-import and just re-associates the old image file with the new album without actually copying it.

@reiv
Copy link
Contributor

reiv commented Nov 3, 2015

I'm fairly certain that #1683 takes care of the first case, but it can't hurt to add more tests. As for the second case, a move could also be triggered by modifying the path templates, though I think we can treat that the same way as a metadata change.

I've taken a gander at the tests for re-imports located in test_importer.py and it looks as though it's meant for situations where files are being re-imported from outside the library, rather than from inside (correct me if I'm wrong). Any pointers on setting up a test case for the latter?

Regarding your second point: I've been thinking about this as well. A better approach might indeed be to let the importer handle it. Specifically, we would need to grab the artpath from a replaced album and assign it to the artpath of the corresponding imported album. Then calling item.move() in manipulate_files() should automatically move the art along with it.

@sampsyo
Copy link
Member Author

sampsyo commented Nov 3, 2015

I've taken a gander at the tests for re-imports located in test_importer.py and it looks as though it's meant for situations where files are being re-imported from outside the library, rather than from inside (correct me if I'm wrong). Any pointers on setting up a test case for the latter?

Hmm; the way I read it, the setUp method adds the music to the library, and then the _setup_import_session call instructs the tests to import the same music again. So think this is indeed importing already-in-the-library files, right?

Regarding your second point: I've been thinking about this as well. A better approach might indeed be to let the importer handle it. Specifically, we would need to grab the artpath from a replaced album and assign it to the artpath of the corresponding imported album. Then calling item.move() in manipulate_files() should automatically move the art along with it.

Yes, exactly! That would be ideal. The remaining decision is whether the importer should be responsible or fetchart should. I lean toward the former: a re-import can just preserve the album art as it was before. Then we would need to ensure that the fetchart plugin doesn't interfere with that logic.

Revert "PEP8 amendments"

This reverts commit 413fe6b.

Revert "Importer: Delete orphaned album art on..."

This reverts commit 629a80a.
Ensure that album art is preserved when an album is re-imported.
Copy the replaced album's artpath attribute to the new album. This
causes the image file to be moved along with the music files.
@reiv
Copy link
Contributor

reiv commented Nov 3, 2015

Going with this approach simplified things a lot, actually; the fix was a one-liner.

Now we'd have to make fetchart a bit smarter, too. Is there currently a way for plugins to distinguish between re-imports and regular imports?

Make sure that when an album is re-imported and its files are
moved, the artwork isn't left behind in the old folder.
@sampsyo
Copy link
Member Author

sampsyo commented Nov 4, 2015

Awesome! I'm so excited the fix could be that simple. Woohoo!

It depends on when the plugins run, but ideally, a plugin should be able to inspect the task's replaced_albums field. If that's non-empty, then it's a re-import. Would that work?

@reiv
Copy link
Contributor

reiv commented Nov 4, 2015

Awesome! I'm so excited the fix could be that simple. Woohoo!

Me too! Turns out the mechanism was already there, it was just missing a single cog for it to work.

Anyway, if the fetchart plugin has access to the album associated with the task, then instead of ignoring re-imports altogether, we could check if an album already has its artpath set (again making sure that the image file actually exists), and if so, skip it.

When re-importing an album, we don't want fetchart to interfere
with any existing album art.
@reiv
Copy link
Contributor

reiv commented Nov 4, 2015

Can we merge this PR?

@sampsyo
Copy link
Member Author

sampsyo commented Nov 4, 2015

Yes, looks 100% ready. Thanks again! ✨

reiv added a commit that referenced this pull request Nov 4, 2015
Fix #314: Delete old album art during re-import
@reiv reiv merged commit a7952b1 into master Nov 4, 2015
@reiv reiv deleted the 314-reimport-art branch November 4, 2015 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants