Unpackerr / unpackerr

Extracts downloads for Radarr, Sonarr, Lidarr, Readarr, and/or a Watch folder - Deletes extracted files after import
https://unpackerr.zip
MIT License
998 stars 36 forks source link

Support for splitting single-file FLAC files with cue. #141

Open sdfg2 opened 3 years ago

sdfg2 commented 3 years ago

Hello,

I love this, it's amazing, I was wondering if at some point it might support extracting single-file flacs using something like https://github.com/ftrvxmtrx/split2flac ?

davidnewhall commented 3 years ago

Unfortunately, no, that is not something this application is going to do. This app has no external dependencies, and I don't know the first thing about cutting up music files like that. Future versions will probably have triggers, so you can execute a script (like the one you linked) after an extraction is finished.

EDIT: 1/3/22: While unpackerr still doesn't support this feature, command hooks have been added. Unfortunately these files are not often compressed so the command hook never fires for these. The script below may be useful to others that stumble into this thread.

sdfg2 commented 3 years ago

Ok thanks!

mprachar commented 2 years ago

Hello @sdfg2 Unpackerr is working great for me as well, and I actually came over here to request the same thing - did you ever find a solution?

davidnewhall commented 2 years ago

Do these Flac files come in a compressed archive? (rar/zip files)

mprachar commented 2 years ago

No, what happens is the FLAC file is one continuous file, and there will also be a second file (*.cue) that contains the instructions on how to split it into separate tracks.

There are a variety of open source libraries and command line programs that simplify the process.

davidnewhall commented 2 years ago

It sounds like the downloader application needs to trigger the script in this case. I still just don't know how this process would fit into what unpackerr does. Surely someone has solved this, somewhere.... Wishing you both the best of luck!

mprachar commented 2 years ago

Thanks for considering!

I think it seems sensible as it’s a common post-download step that needs to be done before a *arr application can complete the import process. I also understand it’s not quite a straightforward as decompression/extraction.

I’ll keep looking, meanwhile if you do wind up adding a step for your application to trigger a script I’ll give that a shot.

Best Regards, Mike

davidnewhall commented 2 years ago

I’ll keep looking, meanwhile if you do wind up adding a step for your application to trigger a script I’ll give that a shot.

I did add this, but if the Flac files are not compressed to begin with, Unpackerr won't do anything with them. I'll keep thinking about this, and more thoughts are welcomed.

sdfg2 commented 2 years ago

Hello @sdfg2 Unpackerr is working great for me as well, and I actually came over here to request the same thing - did you ever find a solution?

Yup! I created a bash script that runs on completion of a torrent in transmission.

#!/bin/bash
#
#
#  Simple transmission script for splitting single file albums into multiple tracks.
#
#  Determines if the completed torrent is a directory, if so iterate through all directories in the torrent directory
#  looking for single flac/ape/m4a/wv/wav files.  If there's a single file, check for a matching name .cue file.
#  If there is, extract the single file album using https://github.com/ftrvxmtrx/split2flac
#

shopt -s nullglob

startdir="$TR_TORRENT_DIR/$TR_TORRENT_NAME"
#echo `date` "Download complete: $startdir"

if [ -d "$startdir" ]; then
    while IFS= read -r -d '' dir; do
        cd "$dir"
        echo "Checking $dir"
        cuefiles=`find "$dir" -type f -regextype posix-extended -regex '.*.(cue)' -printf x | wc -c`
        if [ "$cuefiles" -gt "0" ]; then
            echo "    ...$cuefiles cue files found"
            while IFS= read -r -d '' flacname; do
                flacclean=${flacname%.*}
                echo "    ...trying $flacclean"
                if [ -f "$flacclean.cue" ] || [ -f "$flacname.cue" ]; then
                    if [ -f "$flacclean.cue" ]; then
                        cueformat=`file -b --mime-encoding "$flacclean.cue"`
                    fi
                    if [ -f "$flacname.cue" ]; then
                        cueformat=`file -b --mime-encoding "$flacname.cue"`
                    fi
                    echo "    ...cueformat $cueformat"
                    echo "    ...extracting $flacname"
                    split2flac -nc -nC -d -D -F -cuecharset $cueformat "$flacname" && echo "    ...complete" || echo "    ...error"
                    find "$dir" -type f -exec chmod 664 {} \;
                    find "$dir" -type d -exec chmod 775 {} \;
                    if [ -f "00.flac" ]; then
                        rm 00.flac
                    fi
                fi
            done < <(find "$dir" -type f -regextype posix-extended -regex '.*.(flac|ape|m4a|wv|wav)' -print0)
        else
            echo "    ...nothing to do"
        fi
    done < <(find "$startdir" -type d -print0)
else
    echo "    ...not a directory, nothing to do"
fi
echo "    Done!"

It relies on split2flac. It's a nasty bodge, and it could probably be refined/optimized/whatever up the wazoo, but this works for me. There will be outlier cases that it fails on and requires manual intervention. Also I don't know what's up with the encoding on some of these cue files but it will actively create multi-gigabyte files if it trips up on something - I keep meaning to put some kind of timeout and cleanup but never get round to it.

As always DO NOT RUN A BASH SCRIPT FROM A STRANGER ON THE INTERNET IF YOU CANNOT UNDERSTAND WHAT IT DOES AND HOW.

davidnewhall commented 2 years ago

fwiw, unpackerr has command hooks now, but it will only work on files that are compressed. That's probably useless for this feature request. The above script looks like a good place to start. I might recommend to @sdfg2 to commit that into a git repo or at least a gist. This way others can contribute code and ideas. It can slowly grow into something more awesome.

I'm going to continue to leave this issue open to increase visibility. I'm open to ideas too. If someone can point me to a Go library that handles the FLAC-cutting stuff I'd find this feature to be much easier to implement. EDIT: This may do it, and now I need to learn more about FLAC. And acquire some... https://pkg.go.dev/github.com/mewkiz/flac

mann1x commented 1 year ago

@davidnewhall

From the same author of split2flac

https://github.com/nilzeronull/unflac https://sr.ht/~ft/unflac/

Works very well, output directory can be set with arg -o Only need to specify the .cue as input Does have a minor issue with processing any "uncommon" character in the cue filename (including dash) so it must be sanitized

davidnewhall commented 1 year ago

Not super fond of calling out to ffprobe.

mann1x commented 1 year ago

Unfortunately there's nothing else that does it... at least I didn't find it

davidnewhall commented 1 year ago

I linked a go flac library above. Just needs time, and I don't really do audio stuff, so this is new to me. https://github.com/mewkiz/flac/blob/v1.0.8/meta/cuesheet.go#L15

It can even parse out the album cover. Seems pretty cool. https://github.com/mewkiz/flac/blob/v1.0.8/meta/meta_test.go#L246-L268

mann1x commented 1 year ago

I'm not really good at go so I can't help much... Yes the library looks very complete. But maybe, if it's appropriate, the unflac script could be something effortless to start with the aim to replace it later with something proper.

davidnewhall commented 1 year ago

I'm not one to do things half way unfortunately. If someone else wanted to try to make unpackerr call out to ff tools, I could consider merging it, but I wont spend time on that. I may spend time on the flac library at some point.

mann1x commented 1 year ago

Understandable. If you give me a hint where to start, I can try. Don't have much time as I have a few years backlog on my open source tools to maintain... But I didn't realize how incredibly often music releases are in cue/flac. I have to spend quite some time doing it manually and it's painful, I could invest that time in it.

davidnewhall commented 1 year ago

There's a pretty tight integration with the xtractr library. Unpackerr makes a call to an xtractr method to find "Extractable" files. So the first thing you'd need to do is change how that call works so it can also find flac+cue. I don't think that can go in the xtractr library, so a new function needs to be written to check for cue/flac. Once you find them, pass them into the code you linked. And by that, I mean rewrite that code into a sub-package in unpackerr. The other problem is that code has no license, so you can't really copy/paste it.

mann1x commented 1 year ago

Thanks, that's a good start.

The code has been published at least once with the MIT license as a package:

https://voidlinux.pkgs.org/current/voidlinux-main-aarch64/unflac-1.0_2.aarch64.xbps.html

I will ask the author to provide one.

mprachar commented 1 year ago

Lookig forward to this if you get it working!

Best Regards, Mike


From: mann1x @.> Sent: Saturday, May 6, 2023 1:16 AM To: Unpackerr/unpackerr @.> Cc: Mike Prachar @.>; Comment @.> Subject: Re: [Unpackerr/unpackerr] Support for splitting single-file FLAC files with cue. (#141)

Thanks, that's a good start.

The code has been published at least once with the MIT license as a package:

https://voidlinux.pkgs.org/current/voidlinux-main-aarch64/unflac-1.0_2.aarch64.xbps.html

I will ask the author to provide one.

— Reply to this email directly, view it on GitHubhttps://github.com/Unpackerr/unpackerr/issues/141#issuecomment-1537086908, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFOEDLGW6CFJRAHLG6BXDVLXEYCERANCNFSM5BJZZB3Q. You are receiving this because you commented.Message ID: @.***>