flac2mp3 icon indicating copy to clipboard operation
flac2mp3 copied to clipboard

Delete files from target that vanished on source

Open kosli opened this issue 8 years ago • 10 comments

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 ;-)

kosli avatar Jan 19 '17 14:01 kosli

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

robinbowes avatar Jan 20 '17 11:01 robinbowes

@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.

kosli avatar Jan 20 '17 13:01 kosli

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

robinbowes avatar Jan 20 '17 13:01 robinbowes

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

kosli avatar Jan 20 '17 13:01 kosli

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

carlasplund avatar Jan 20 '17 13:01 carlasplund

@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 avatar Jan 20 '17 14:01 kosli

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

kosli avatar Jan 20 '17 15:01 kosli

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

robinbowes avatar Jan 20 '17 15:01 robinbowes

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

kosli avatar Jul 17 '17 23:07 kosli

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

trip5 avatar Dec 31 '19 14:12 trip5