Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sdfg2 opened this issue Jul 31, 2021 · 20 comments
Open

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

sdfg2 opened this issue Jul 31, 2021 · 20 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sdfg2
Copy link

sdfg2 commented Jul 31, 2021

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
Copy link
Collaborator

davidnewhall commented Jul 31, 2021

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
Copy link
Author

sdfg2 commented Jul 31, 2021

Ok thanks!

@sdfg2 sdfg2 closed this as completed Jul 31, 2021
@mprachar
Copy link

mprachar commented Oct 4, 2021

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
Copy link
Collaborator

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

@mprachar
Copy link

mprachar commented Oct 5, 2021 via email

@davidnewhall
Copy link
Collaborator

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
Copy link

mprachar commented Oct 5, 2021 via email

@davidnewhall
Copy link
Collaborator

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.

@davidnewhall davidnewhall reopened this Oct 5, 2021
@sdfg2
Copy link
Author

sdfg2 commented Oct 10, 2021

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
Copy link
Collaborator

davidnewhall commented Jan 4, 2022

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

@davidnewhall davidnewhall changed the title Support for single-file flacs Support for splitting single-file FLAC files with cue. Jan 4, 2022
@davidnewhall davidnewhall added enhancement New feature or request help wanted Extra attention is needed labels Dec 12, 2022
@mann1x
Copy link

mann1x commented May 6, 2023

@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
Copy link
Collaborator

Not super fond of calling out to ffprobe.

@mann1x
Copy link

mann1x commented May 6, 2023

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

@davidnewhall
Copy link
Collaborator

davidnewhall commented May 6, 2023

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
Copy link

mann1x commented May 6, 2023

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
Copy link
Collaborator

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
Copy link

mann1x commented May 6, 2023

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
Copy link
Collaborator

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
Copy link

mann1x commented May 6, 2023

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
Copy link

mprachar commented May 7, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Development

No branches or pull requests

4 participants