complexlogic / rsgain

A simple, but powerful ReplayGain 2.0 tagging utility
Other
288 stars 20 forks source link

Wishlist - Add option to skip files that already have ReplayGain tagging #16

Closed diizzyy closed 2 years ago

diizzyy commented 2 years ago

A nice feature would be if rsgain could offer an option to skip files that already have tagging instead of rescanning everything

complexlogic commented 2 years ago

This was a feature request in loudgain too, see loudgain/7. There is some good discussion there of benefits and drawbacks.

Adding a simple check if ReplayGain tags exist is relatively straightforward. Verifying that the ReplayGain tags are complete, correct, and match the requested settings is much more complicated. I would prefer not to validate the correctness of the tags due to the large amount of additional logic required, and potential to introduce bugs.

We could have a simple option to check if tags exist only. The user would be responsible to ensure that their files with with pre-existing ReplayGain tags are valid and and match their current settings (e.g. target loudness).

I made a quick experimental branch for the feature skip_existing and pushed it. Get it with:

git clone -b skip_existing https://github.com/complexlogic/rsgain

You can invoke the feature with -S or --skip-existing in Easy Mode. It works by checking if the REPLAYGAIN_TRACK_GAIN tag exists before scanning. If it exists, the scan is skipped for that file. I've only implemented it for MP3 and FLAC/Ogg/Opus for now. I can extend it to the other formats later if this feature is successful.

Please let me know what you think.

diizzyy commented 2 years ago

Yeah, checking of existance would be "enough" imho. I'll give it a spin later today

diizzyy commented 2 years ago

Doesn't seem to work with m4a at least?

mkdir testdir
yt-dlp -f 140 "https://www.youtube.com/watch?v=NC5V-856SrM"
cp *More*.m4a ../untagged.m4a
cd ..
rsgain easy testdir
...
Files Scanned:     1
cp -Rp untagged.m4a ./testdir/
rsgain easy -S testdir
...
Files Scanned:     2

ffmpeg -i filenamegoes.here -f ffmetadata metdata.txt extracts ReplayGain meta data :-/

complexlogic commented 2 years ago

Doesn't seem to work with m4a at least?

Yes, that is correct. As I mentioned above:

I've only implemented it for MP3 and FLAC/Ogg/Opus for now

I'm trying to get some initial feedback on the feature before I put in the work to implement it for all formats.

diizzyy commented 2 years ago

Sorry, I'm not fully awake today. Listed formats works, perhaps add something in the statistics/log about it though? Files Scanned: 1 (of X due to ReplayGain tag detected)

complexlogic commented 2 years ago

perhaps add something in the statistics/log about it though?

Good idea.

Some more thoughts. I think if album tags are enabled, rsgain should check all of the files, and if a single file is missing tags then all of them will be scanned.

complexlogic commented 2 years ago

I just made some updates:

I ran it on my personal library of about 13k songs, mostly FLAC with a few MP3. It was able to get through the full library without rescanning anything.

Please give it a test and let me know if you find any issues.

diizzyy commented 2 years ago

Hi, it works but reporting is incorrect (second run)

rhash -r --sha256 testdir (same as testdir-untagged)
8c1acbcef75d06c661501c03ee044e0e66963992b8b2c913ffe5fc7bffcede98  testdir/opus/sample.opus
5c3363e39ba9f6274eeb7499bf9cabd47c5c010219e1f2f4d89440a6636c7d1c  testdir/flac/sample.flac
281e4f511453f293b27d0f58a18d6c585ab3e7a13885b7d5b5975509689e767b  testdir/m4a/sample.m4a
dd00a1b80494ff687a9df35a0d73b075749ae191ea21a1f63632533606998f43  testdir/mp3/sample.mp3
5659a9e1dbe088a3efc4bb0f5b922cd8183cd347c219883c38631d138e760ee5  testdir/wav/sample.wav

rsgain easy testdir
...
Files Scanned:     5
Negative Gains:    5 (100.0% of files)
Positive Gains:    0 (0.0% of files)
...

rhash -r --sha256 testdir
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/opus/sample.opus
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/flac/sample.flac
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/m4a/sample.m4a
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/mp3/sample.mp3
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/wav/sample.wav

cp -Rp testdir-untagged testdir/newfiles

rhash -r --sha256 testdir
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/opus/sample.opus
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/flac/sample.flac
5659a9e1dbe088a3efc4bb0f5b922cd8183cd347c219883c38631d138e760ee5  testdir/newfiles/wav/sample.wav
dd00a1b80494ff687a9df35a0d73b075749ae191ea21a1f63632533606998f43  testdir/newfiles/mp3/sample.mp3
8c1acbcef75d06c661501c03ee044e0e66963992b8b2c913ffe5fc7bffcede98  testdir/newfiles/opus/sample.opus
5c3363e39ba9f6274eeb7499bf9cabd47c5c010219e1f2f4d89440a6636c7d1c  testdir/newfiles/flac/sample.flac
281e4f511453f293b27d0f58a18d6c585ab3e7a13885b7d5b5975509689e767b  testdir/newfiles/m4a/sample.m4a
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/m4a/sample.m4a
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/mp3/sample.mp3
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/wav/sample.wav

rsgain easy -S testdir
...
Files Scanned:     6
Files Skipped:     4
Negative Gains:    6 (100.0% of files)
Positive Gains:    4 (66.7% of files)
...

rhash -r --sha256 testdir
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/opus/sample.opus
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/flac/sample.flac
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/newfiles/wav/sample.wav
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/newfiles/mp3/sample.mp3
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/newfiles/opus/sample.opus
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/newfiles/flac/sample.flac
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/newfiles/m4a/sample.m4a
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/m4a/sample.m4a
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/mp3/sample.mp3
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/wav/sample.wav
complexlogic commented 2 years ago

Thanks for the detailed test data, and good find on the statistic calculation bug for positive/negative gains. I didn't have any .wav support previously, so that is why 6 files were scanned on the second run instead of 5.

I just updated the feature branch with the following changes:

Please update and run your test suite again and let me know if there are any issues. This should be ready for merging unless you find any other bugs.

diizzyy commented 2 years ago

Something is still odd...

rhash -r --sha256 testdir (same as testdir-untagged)
8c1acbcef75d06c661501c03ee044e0e66963992b8b2c913ffe5fc7bffcede98  testdir/opus/sample.opus
5c3363e39ba9f6274eeb7499bf9cabd47c5c010219e1f2f4d89440a6636c7d1c  testdir/flac/sample.flac
51a8a5b9e587c7fa923a1d0a402ce79d940eadbb6219b16c803f031f200b7514  testdir/mp2/sample.mp2
281e4f511453f293b27d0f58a18d6c585ab3e7a13885b7d5b5975509689e767b  testdir/m4a/sample.m4a
5659a9e1dbe088a3efc4bb0f5b922cd8183cd347c219883c38631d138e760ee5  testdir/wav/sample.wav
20c8d0c2dcadebfd13ab4f080ee1ee5133be6f5997f53ad0aff0e66a88edd33e  testdir/ogg/sample.ogg
dd00a1b80494ff687a9df35a0d73b075749ae191ea21a1f63632533606998f43  testdir/mp3/sample.mp3

rsgain easy testdir
Files Scanned:     7
Negative Gains:    7 (100.0% of files)
Positive Gains:    0 (0.0% of files)

rhash -r --sha256 testdir
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/opus/sample.opus
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/flac/sample.flac
5672cfa3cc1294d1db324755ea470c48b62fabe99c49a877ce88e1b339190b98  testdir/mp2/sample.mp2
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/m4a/sample.m4a
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/wav/sample.wav
26f0db019b7a29c420efa1d1607045419bb5ac2b77d2ef3d84123d57589aab87  testdir/ogg/sample.ogg
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/mp3/sample.mp3

cp -Rp testdir-untagged testdir/newfiles

rhash -r --sha256 testdir
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/opus/sample.opus
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/flac/sample.flac
5672cfa3cc1294d1db324755ea470c48b62fabe99c49a877ce88e1b339190b98  testdir/mp2/sample.mp2
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/m4a/sample.m4a
5659a9e1dbe088a3efc4bb0f5b922cd8183cd347c219883c38631d138e760ee5  testdir/newfiles/wav/sample.wav
20c8d0c2dcadebfd13ab4f080ee1ee5133be6f5997f53ad0aff0e66a88edd33e  testdir/newfiles/ogg/sample.ogg
dd00a1b80494ff687a9df35a0d73b075749ae191ea21a1f63632533606998f43  testdir/newfiles/mp3/sample.mp3
5c3363e39ba9f6274eeb7499bf9cabd47c5c010219e1f2f4d89440a6636c7d1c  testdir/newfiles/flac/sample.flac
8c1acbcef75d06c661501c03ee044e0e66963992b8b2c913ffe5fc7bffcede98  testdir/newfiles/opus/sample.opus
51a8a5b9e587c7fa923a1d0a402ce79d940eadbb6219b16c803f031f200b7514  testdir/newfiles/mp2/sample.mp2
281e4f511453f293b27d0f58a18d6c585ab3e7a13885b7d5b5975509689e767b  testdir/newfiles/m4a/sample.m4a
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/wav/sample.wav
26f0db019b7a29c420efa1d1607045419bb5ac2b77d2ef3d84123d57589aab87  testdir/ogg/sample.ogg
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/mp3/sample.mp3

rsgain easy -S testdir
...
Files Scanned:     8
Files Skipped:     6
Negative Gains:    8 (100.0% of files)
Positive Gains:    0 (0.0% of files)
...

rhash -r --sha256 testdir
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/opus/sample.opus
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/flac/sample.flac
5672cfa3cc1294d1db324755ea470c48b62fabe99c49a877ce88e1b339190b98  testdir/mp2/sample.mp2
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/m4a/sample.m4a
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/newfiles/wav/sample.wav
26f0db019b7a29c420efa1d1607045419bb5ac2b77d2ef3d84123d57589aab87  testdir/newfiles/ogg/sample.ogg
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/newfiles/mp3/sample.mp3
e1ddc212a06ee3e202489264723d252f761a94d8711e5583a5d1bacc55fe75ba  testdir/newfiles/flac/sample.flac
78adfc1f1a763322c308d0135db3b8fd733d4e891a923b2c199be2d3fa8c8bfa  testdir/newfiles/opus/sample.opus
5672cfa3cc1294d1db324755ea470c48b62fabe99c49a877ce88e1b339190b98  testdir/newfiles/mp2/sample.mp2
d8dc071e25e57a7a3161d164498469b489dc8b923e295d97f7bd485fd9ff9c77  testdir/newfiles/m4a/sample.m4a
4c994aaba44a4e106a10121ece23db33b96f8e3b2b6a2555d6f7e8a56662889e  testdir/wav/sample.wav
26f0db019b7a29c420efa1d1607045419bb5ac2b77d2ef3d84123d57589aab87  testdir/ogg/sample.ogg
e2ba21942ecd4b0b7657b1438de7e95067bc896e2380e1d057c203500edc7a6d  testdir/mp3/sample.mp3

Using 8dbdedf

complexlogic commented 2 years ago

I was able to reproduce the issue. The reason is because the handling of Ogg files was incorrect. I fixed it with the latest commit.

Could you git pull try one more time? Thanks for your support with testing.

diizzyy commented 2 years ago

It now works as intended! Thanks!