Conversation
Signed-off-by: darrell-k <darrell@darrell.org.uk>
michaelherger
left a comment
There was a problem hiding this comment.
Thanks a lot! I hope to find time to actually test this later today. All my comments are just of theoretical nature. Haven't even pulled this change yet. Bear with me.
Signed-off-by: darrell-k <darrell@darrell.org.uk>
Signed-off-by: darrell-k <darrell@darrell.org.uk>
Signed-off-by: darrell-k <darrell@darrell.org.uk>
…de I used Signed-off-by: darrell-k <darrell@darrell.org.uk>
Signed-off-by: darrell-k <darrell@darrell.org.uk>
Signed-off-by: darrell-k <darrell@darrell.org.uk>
|
Some rework just pushed. |
michaelherger
left a comment
There was a problem hiding this comment.
I'm sorry, another sh..load of comments. I haven't even test run this yet, but I believe there's potential for performance optimisations on the DB level.
| # Maybe a track instance was passed in, but no longer from updateStandaloneArtwork() which gives us | ||
| # the trackid instead, as we only need to instantiate a track if 'titleformatter' artwork naming is in use. | ||
| my $track = $trackAttributes && delete $trackAttributes->{_track}; | ||
| $track ||= Slim::Schema->find('Track', $trackAttributes->{_trackid}) if $trackAttributes->{_trackid}; |
There was a problem hiding this comment.
Can we delete the _trackid element here?
|
Just to let you know, I'm currently testing the
|
|
I'm going to resolve some of the comments in this thread, it's getting hard to follow! |
|
I'm about to push an update. The scanned pics SQL now identifies the albums that need processing so that all tracks can be processed together even if the album's tracks are located in multiple folders. This makes it simpler, especially when we come to enhance this to look for specific album artwork (eg box sets). I hope I've also covered all the comments above. I'm ready for more questions/comments! |
Signed-off-by: darrell-k <darrell@darrell.org.uk>
The other way somehow failed scans on my machine. I wasn't able to run the scanner without this modification on my dev Mac. Signed-off-by: Michael Herger <michael@herger.net>
Move SQLite function registration to `SQLiteHelper`
Signed-off-by: darrell-k <darrell@darrell.org.uk>
Seperate scanner helper table initialisation
|
I'm so utterly confused... does this change even touch the full wipe & rescan case? And didn't we change the code (in 9.2 or before) to use |
There was a problem hiding this comment.
This has been sitting in my computer for way too long. And I'm still rather confused... these changes only deal with updated artwork on a rescan, but not the initial scan? Is this because we're happy with the initial scan at this point (except for boxsets)?
And as I mentioned in some other comment we don't handle album artwork independently of the track artwork yet? I'm very much confused because I had retagged some of my files about a month ago to test this particular case.
EDIT: ok, it seems the album artwork vs. track artwork was part of my attempt to deal with boxsets in #1627. Aargh... just wasted half an afternoon 😞.
| ### I might have missed it, but I can't see where this might be called in main process async mode. | ||
| ### If it is, we'll need more work to populate scanned_pics in the main process or just keep a version of the old subroutine for that use. |
There was a problem hiding this comment.
I did what people do nowadays: I asked the AI assistant. It told me that the easiest way to have the scan run in the main process was to do a rescan album <album_id>. I'll give that a try.
There was a problem hiding this comment.
I don't think that would call updateStandaloneArtwork and Schema.pm will still calculate a coverid if it can't find the image in scanned_images (if I remember correctly!).
Yes (until we get on to the box set changes), except that in Schema.pm we now read coverid directly from the enhanced And unless your refactoring of |
|
This PR is still in draft mode. How do you feel about it? I think we/I should try to get things moving again. Shall I merge? |
|
Let me address the outstanding comments first. Give me a day. And then, you mean merge into your artwork-scan-db branch and not 9.2? I think we should do the box set stuff before merging to 9.2 (it should be easy to incorporate into |
I'm not understanding. Option (1) would follow what 9.2 is doing for
Either way, the data would be available to the contributor picture scan.
Yes, and also slimserver/Slim/Control/Commands.pm Lines 2760 to 2778 in c96f8f2 |
|
Ok, a month or two later I finally get it 🤦🏻. I'm not sure we should just add things there as deletion of found artwork references might actually be a bit more complex than tracks once we add box set handling, works etc. as we will have to look at parent folders too. We should probably not delete by folder, but by Do we populate the |
If we were to clear the data from
Yes for a single album scan, no for a single track scan, because we bypass slimserver/Slim/Utils/Scanner/Local.pm Lines 71 to 110 in c96f8f2 For the single album scan we are going to have to consider the parent folder question when we get on to box sets. For a single track scan, I think it's reasonable that artwork changes (unless embedded) is ignored. I would vote that for this PR we should go with the simple solution I'm suggesting and if it needs further amendment for box sets we can enhance it when we code that. NOTE: I thought I'd have a look at what 9.2 was doing and just found that it's not handling changed artwork properly anyway! Something else to incorporate in this PR!!! |
|
Should we merge what we have, and add more as we get more exposure? We don't have to fix everything in one go. |
|
Probably - I'll just check I haven't made anything worse. |
|
OK, the artwork problem in rescan album is hopefully fixed by calling I'm about to push the changes, hopefully this is ready to merge now, but I want to run all my tests again before I mark this "ready for review". That will be tomorrow afternoon. |
Signed-off-by: darrell-k <darrell@darrell.org.uk>
| # Populate enhanced scanned_pics table (status E = already exists in the tracks table, status N = new) | ||
| my $imageSth = $dbh->prepare_cached( qq{ | ||
| INSERT INTO scanned_pics | ||
| INSERT OR IGNORE INTO scanned_pics |
There was a problem hiding this comment.
They say that if you want to ignore only if it already exists, you should use INSERT ... ON CONFLICT DO NOTHING, rather than INSERT OR IGNORE. The latter would silently swallow other failures, like empty key values, which we might be interested to learn about. See eg. https://hoelz.ro/blog/with-sqlite-insert-or-ignore-is-often-not-what-you-want
| # XXX how best to delete files in non-recursive mode? | ||
| # Delete the directory itself and all children | ||
| $dbh->do("DELETE FROM scanned_files WHERE url = '${file}' OR url LIKE '${file}/%'"); | ||
| $dbh->do("DELETE FROM scanned_pics WHERE folder = '${path}'"); |
There was a problem hiding this comment.
I know, this has been around for 15+ years. But maybe it's time to do this correctly, using a prepared statement? Some paths when expanded this way might fail the query, eg. if they had quotes in them etc.
There was a problem hiding this comment.
This is a new change. As these are all purely scanner related, do we really want to bump the schema version? Keep in mind that this will force a full new rescan - for the only reason to run new scanner code. That's kind of stupid if all we change is the scanner process, but not the result (hopefully, anyway).
There was a problem hiding this comment.
On the other hand, IMO it's the "right" way to do it (following scanned_files). But I'm open to other ideas if we can ensure it's only created once, not dropped and recreated.
I could reinstate scannerInitialiseDB (or whatever I called it) from a previous commit. That could check for the table's existence and do nothing if it already exists. Checking for a table's existence is easier now we don't have to worry about mysql, but is it worth it?
There was a problem hiding this comment.
Or just CREATE TABLE IF NOT EXISTS, of course!
There was a problem hiding this comment.
You're right: a new schema version file the right thing to do. 9.2 is still in development.
Do we really need the additional index on tracks.cover? I think we never use that criteria without another more restrictive condition like eg. the album. Maintaining the index might take more time than we gain checking all tracks of an album with the help of the index vs. without?
|
I merged in 9.2 locally before this latest push, which was probably a mistake, I forgot this PR was against the https://github.com/LMS-Community/slimserver/tree/artwork-scan-db branch. It also seems to have caused a DCO problem with some of the commits that were in that merge. And I still have to address the two recent comments about SQL changes. |
|
You could |
d51b4cf to
1579034
Compare
Signed-off-by: darrell-k <darrell@darrell.org.uk>
Done. looks better now. |
|
@michaelherger I found an inconsistency with Consider a music file with the following tags: Now, let's look at 3 scanning scenarios:
Therefore, as things stand, there is no correct image naming possible when using DISC and/or DISCC because depending on the scan type we'll be looking for different names. I've fixed this in I am about to push the change to this PR. Please let me know what you think. I've added some comments in the code which hopefully explain my approach. My code could well require some tidying up. Am I doing something crazy? |
Signed-off-by: darrell-k <darrell@darrell.org.uk>
I think you're not happy with this yourself... We know the title format. So we can do an educated guess: if And we not only have the format, we can also "massage" the data as we like, convert numbers to strings etc. |
|
Hardly tested - I hope you get the idea: diff --git a/Slim/Music/Artwork.pm b/Slim/Music/Artwork.pm
index cf328a03a..c7d0938b9 100644
--- a/Slim/Music/Artwork.pm
+++ b/Slim/Music/Artwork.pm
@@ -100,16 +100,33 @@ sub findStandaloneArtwork {
if ( my $coverName = Slim::Music::TitleFormatter::infoFormat( $track, $formatStr, undef, $meta ) ) {
$coverName .= $suffix;
- if ( main::ISWINDOWS ) {
+ my $addCleanCoverName = sub {
# Remove illegal characters from filename.
- $coverName =~ s/\\|\/|\:|\*|\?|\"|<|>|\|//g;
- }
+ $coverName =~ s/\\|\/|\:|\*|\?|\"|<|>|\|//g if main::ISWINDOWS;
+
+ # Generating a pathname from tags is dangerous because the filesystem
+ # encoding may not match the locale, but that is the best guess that we have.
+ unshift @files, Slim::Utils::Unicode::encode_locale($coverName) if $coverName;
+ };
+
+ $addCleanCoverName->();
- # Generating a pathname from tags is dangerous because the filesystem
- # encoding may not match the locale, but that is the best guess that we have.
- $coverName = Slim::Utils::Unicode::encode_locale($coverName);
+ # DISC/DISCC can come with or without leading zeros, so we need to format them to match the template
+ if ($coverFormat =~ /%DISC/) {
+ $meta ||= { $track->get_columns };
- unshift @files, $coverName;
+ my $formatNumbers = sub {
+ return $_[0] * 1 if $_[0] =~ /^0\d+$/;
+ return sprintf("%02d", $_[0]);
+ };
+
+ $meta->{DISC} = $meta->{disc} = $formatNumbers->($meta->{disc}) if ($meta->{disc});
+ $meta->{DISCC} = $meta->{discc} = $formatNumbers->($meta->{discc}) if ($meta->{discc});
+
+ $coverName = Slim::Music::TitleFormatter::infoFormat( undef, $formatStr, undef, $meta );
+ $coverName .= $suffix;
+ $addCleanCoverName->();
+ }
if ( $artDir && -d $artDir ) {
$candidateForArtfolder = $coverName;With a format of |
Well, I'm quite happy. I actually enjoyed coding that :) and I don't think ignoring leading zeros in other format elements would be a problem. Would people really tag "foobar 1" and "foobar 01" in, say, GROUPING and use in their image filenames? I didn't want to limit it to a specific number of leading zeros. But then we're storing DISC and DISCC in I'll look at doing this by passing an array back from |
|
@michaelherger just saw your suggested code. I'll run it through my tests. |
|
I did a little testing, I had to replace with because the extra use of And I also had to retrieve with because discc isn't a track column. There's also a problem when using DISC and DISCC: For a new track we get: Anyway, that's enough for tonight, it's bedtime! |
|
Maybe we are overthinking this and should just accept the risk of failing some specific formats... because there's more oddities: I believe the title formatter would strip out
You can expect people to do anything, really. Maybe it's "party hits ('01-'09)" referring to years? But sometimes they'll just have to live with certain side-effects of their doing 😉. I'd rather simplify our code and not deal with leading zeros at this point. Or we'll never end this PR trying to cover each and every edge case. |
| my $a_rank = $rank{ (fileparse($a, qr/\.[^.]*/))[0] } // 999_999; | ||
| my $b_rank = $rank{ (fileparse($b, qr/\.[^.]*/))[0] } // 999_999; |
There was a problem hiding this comment.
Please use scalar for improved readability:
rank{ scalar fileparse($b, qr/\.[^.]*/) } // 999_999;fileparse would return the first element in scalar context.
I'm thinking of box sets. After discussion we decided we should use the existing TitleFormatter functionality instead of invent a new mechanism and template rules for dealing with multiple artwork files in the same folder. DISC would be a very important attribute in that scenario. "party hits ('01-'09)" would only be a problem if the user had both "party hits ('01-'09).jpg" and "party hits ('1-'9).jpg" in the same folder. In that case, with my zero-suppression technique we'd match both and use the first we found. I think this really is an edge case. I also think my latest commit has another minor advantage - it simplifies the scanned_pics SQL. But if you really don't like that approach, I would propose changing TitleFormatter to always zero-suppress DISC and DISCC elements in the returned template. This would potentially change current behaviour, mainly in a full rescan, but at least it would be consistent. |
Ok, gotcha. I need some more time to look into/think about this. What I didn't like about your change as the heavy manipulation back and forth of those filenames. I was wondering whether we should have something similar to the |
To be honest, looking at However, I'm also finding other inconsistencies in
I'm working on avoiding all this pain by NOT calling Then we would always be able to retrieve clean Track, Album etc objects for It would mean having This would also make the future addition of looking for images in the common parent folder for multiple folder albums easier, because there would be a single method doing all the work in all circumstances. I'll create a PR against my own branch so you can have a look. |
|
I'm sorry, you're moving too fast. I've been told to slow down. I can't keep up with your pace. |
|
I'm not trying to put pressure on. Sorry if it seems that way. I really value your input, but if you would prefer to put this to one side until I mark the PR "Ready for review", that's fine too. Thanks again. |
As discussed. I hope it all makes sense.
The diff generated by git for
updateStandaloneArtwork()is a bit of a mess, probably best to view the new routine as a complete replacement for the old one.This redesign enhances the new
scanned_picstable so that it can driveupdateStandaloneArtwork().coveridcolumn so that we can read it directly from the table (in the scanner process) when we need to updatetracksoralbums. In order for this to work, all externalcoveridgeneration will now use the image path, not the music file URL.statuscolumn so we can differentiate new, existing and deleted images.urlcolumn is renamed topathas it will now hold the file system path of the image, not a file:// URL. This makes things much easier.dircolumn as discussed.In performance testing, this runs faster, even though we are now calling
findStandaloneArtwork()for every track where an image change has been detected, rather than only once for each album/image group.This change enables
TitleFormatterto do its work correctly in cases when the user has specified a variable cover id which includes a "sub-album" field likediscnumberorgrouping. This means that disc or grouping-specific images can be applied to tracks using this existing mechanism when everything for the album is in the same directory.I've added some comments to new/changed code in order to aid understanding.
I'm sure at this stage there is stuff I've missed.