robinbowes / flac2mp3

flac2mp3 is a tool to convert audio files from flac to mp3 format including the copying of tags.
GNU General Public License v3.0
142 stars 29 forks source link

Delete files from target that vanished on source #49

Open kosli opened 7 years ago

kosli commented 7 years ago

I thought that when files in the source directory are being deleted, they will be deleted on the target too? e.g. delete a FLAC file -> it should remove the correpsonding MP3 delete any other file in source, while copyfiles is used, it should be removed in the target dir.

Or perhaps I haven't used flac2mp3 for too long and thought this feature was there. So this is a feature request then ;-)

robinbowes commented 7 years ago

I'd be reluctant to add that sort of feature - I'm not keen on deleting stuff that the tool is not managing.

kosli commented 7 years ago

@robinbowes how do you mean "stuff that the tool is not managing"? my understanding of the concept of flac2mp3 is that the target directory is in the "possession" of flac2mp3, so flac2mp3 can delete files there without having to worry about them. how do you handle otherwise e.g. when you rename (or move, or delete) a file in the source folder? you delete it manually in the target dir? i thought the idea of flac2mp3 is to have a "mirrored" target directory, which looks the same as the source, just that the flac files are converted to mp3.

robinbowes commented 7 years ago

Yes, that is indeed the operating model. It still makes me nervous deleting things.

kosli commented 7 years ago

it could just be an additional option to delete data on the target, like it is with the copyfiles?

carlasplund commented 7 years ago

Robin's script doesn't handle file renames, it will result in multiple files in the destination directory. And deleted files in the source dir will not have an effect on the destination dir. I have a fork of flac2mp3 where exactly this, and many other issues are addressed. I recommend giving it a try: https://github.com/carlasplund/flac2mp3/tree/develop (i.e. the develop branch). Two of the added options in my fork are: --copyfiles Copy non-flac files to dest directories --delete Delete surplus files and directories in destination, keeping in sync with source dir

kosli commented 7 years ago

@carlasplund cool, thanks for the info. i looked at some of the forks but didn't find yours with the delete option. maybe @robinbowes wants to take a look at yours commits (especially https://github.com/carlasplund/flac2mp3/commit/3d0758d0445e41e542137ab15875792359c71276 ) and mrege some of them? :-) will try it out right now. thanks.

kosli commented 7 years ago

works like a charm. i had to change the --preset option as this is not supported (yet) in your version :-)

robinbowes commented 7 years ago

I really need to give this code some love - it's been too long :)

kosli commented 7 years ago

this one from @carlasplund would be really nice to have it in your master :-) https://github.com/carlasplund/flac2mp3/commit/3d0758d0445e41e542137ab15875792359c71276

trip5 commented 4 years ago

Figured this isn't a bad place to share the init script I made for the Docker container, since most of it is exactly what everyone above is talking about above. Not the cleanest script, since I'm not a coder and basically cobbled it together from various sources but it works. On my Syno 918+, takes about 5 minutes for 9000 files. Works on a very bare Alpine linux distro so it should work everywhere.

if ["$SYNCDELETE" == "1" ] ; then
echo Syncing deletions...
find /in>/tmp/in.txt
sed 's/.flac/.mp3/g; s+/in+/out+g' /tmp/in.txt>/tmp/inx.txt
find /out>/tmp/out.txt
grep -vxF -f /tmp/inx.txt /tmp/out.txt>/tmp/clean.txt
while read line; do rm "$line"; done < /tmp/clean.txt
find /out/. -depth -type d -exec rmdir {} + 2>/dev/null
rm /tmp/*.txt
fi
perl /flac2mp3/flac2mp3.pl $ARGS /in /out
exit 0