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

[FEATURE] Add missing options from EAC #43

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ It calls metaflac to clean the FLAC files.`,
}

if !rootCmdArgs.DryRun {
err := utils.Clean(
var output, err = utils.Clean(
rootCmdArgs.MetaflacCommandPath,
cleanCmdArgs.CleanArguments,
flacFile,
Expand All @@ -124,6 +124,10 @@ It calls metaflac to clean the FLAC files.`,
flacFile,
resultCode,
)

if rootCmdArgs.Verbose {
log.Fatalln(output)
}
}

os.Exit(1)
Expand Down Expand Up @@ -163,10 +167,13 @@ func init() {
"ALBUMARTIST",
"ARTIST",
"COMMENT",
"COMPOSER",
"DISCNUMBER",
"FLAC_ARGUMENTS",
"GENRE",
"LYRICS",
"METAFLAC_ARGUMENTS",
"PERFORMER",
"REPLAYGAIN_REFERENCE_LOUDNESS",
"REPLAYGAIN_ALBUM_GAIN",
"REPLAYGAIN_ALBUM_PEAK",
Expand Down
31 changes: 27 additions & 4 deletions cmd/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,36 @@ It calls flac to encode the FLAC files.`,
}

if needToEncode || rootCmdArgs.Force {
encodeCmdArgs.EncodeArguments = append(
encodeCmdArgs.EncodeArguments,
"--force",
"--silent",
)

if !rootCmdArgs.DryRun {
utils.Encode(
var output, err = utils.Encode(
rootCmdArgs.FlacCommandPath,
encodeCmdArgs.EncodeArguments,
flacFile,
)

if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
resultCode := exitError.ExitCode()

log.Fatalf(
"ERROR - cannot encode file \"%s\" (exit code %d)",
flacFile,
resultCode,
)

if rootCmdArgs.Verbose {
log.Fatalln(output)
}
}

os.Exit(1)
}
}

if rootCmdArgs.Verbose {
Expand Down Expand Up @@ -173,10 +197,9 @@ func init() {
"a",
[]string{
"--compression-level-8",
"--delete-input-file",
"--force",
"--exhaustive-model-search",
"--no-padding",
"--silent",
"--qlp-coeff-precision-search",
"--verify",
"--warnings-as-errors",
},
Expand Down
6 changes: 5 additions & 1 deletion cmd/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ It calls metaflac to calculate and add the ReplayGain tags to the FLAC files.`,

if needToNormalize || rootCmdArgs.Force {
if !rootCmdArgs.DryRun {
err := utils.Normalize(
var output, err = utils.Normalize(
rootCmdArgs.MetaflacCommandPath,
normalizeCmdArgs.NormalizeArguments,
flacFiles,
Expand All @@ -159,6 +159,10 @@ It calls metaflac to calculate and add the ReplayGain tags to the FLAC files.`,
flacFiles,
resultCode,
)

if rootCmdArgs.Verbose {
log.Fatalln(output)
}
}

os.Exit(1)
Expand Down
6 changes: 5 additions & 1 deletion cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ It calls metaflac to verify the FLAC files.`,
flacFile := args[0]

if !rootCmdArgs.DryRun {
err := utils.Verify(
var output, err = utils.Verify(
rootCmdArgs.FlacCommandPath,
verifyCmdArgs.VerifyArguments,
flacFile,
Expand All @@ -77,6 +77,10 @@ It calls metaflac to verify the FLAC files.`,
flacFile,
resultCode,
)

if rootCmdArgs.Verbose {
log.Fatalln(output)
}
}

os.Exit(1)
Expand Down
8 changes: 5 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ tags-to-keep:
- "ALBUMARTIST"
- "ARTIST"
- "COMMENT"
- "COMPOSER"
- "DISCNUMBER"
- "FLAC_ARGUMENTS"
- "GENRE"
- "LYRICS"
- "METAFLAC_ARGUMENTS"
- "PERFORMER"
- "REPLAYGAIN_REFERENCE_LOUDNESS"
- "REPLAYGAIN_ALBUM_GAIN"
- "REPLAYGAIN_ALBUM_PEAK"
Expand All @@ -53,10 +56,9 @@ tags-to-keep:
# Arguments passed to flac to encode the file
encode-arguments:
- "--compression-level-8"
- "--delete-input-file"
- "--force"
- "--exhaustive-model-search"
- "--no-padding"
- "--silent"
- "--qlp-coeff-precision-search"
- "--verify"
- "--warnings-as-errors"

Expand Down
6 changes: 3 additions & 3 deletions docs/02_COMMANDS_AND_FLAGS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
Generate this file with the following command:

```sh
```bash
echo "# Commands and flags" > ./docs/02_COMMANDS_AND_FLAGS.md
echo "" >> ./docs/02_COMMANDS_AND_FLAGS.md

Expand Down Expand Up @@ -122,7 +122,7 @@ Examples:
Flags:
-a, --clean-arguments strings arguments passed to metaflac to clean the file (default [--remove,--dont-use-padding,--block-type=APPLICATION,--block-type=CUESHEET,--block-type=PADDING,--block-type=PICTURE,--block-type=SEEKTABLE])
-h, --help help for clean
-t, --tags-to-keep strings tags to keep in the file (default [ALBUM,ALBUMARTIST,ARTIST,COMMENT,DISCNUMBER,FLAC_ARGUMENTS,GENRE,METAFLAC_ARGUMENTS,REPLAYGAIN_REFERENCE_LOUDNESS,REPLAYGAIN_ALBUM_GAIN,REPLAYGAIN_ALBUM_PEAK,REPLAYGAIN_TRACK_GAIN,REPLAYGAIN_TRACK_PEAK,TITLE,TOTALDISCS,TOTALTRACKS,TRACKNUMBER,YEAR])
-t, --tags-to-keep strings tags to keep in the file (default [ALBUM,ALBUMARTIST,ARTIST,COMMENT,COMPOSER,DISCNUMBER,FLAC_ARGUMENTS,GENRE,LYRICS,METAFLAC_ARGUMENTS,PERFORMER,REPLAYGAIN_REFERENCE_LOUDNESS,REPLAYGAIN_ALBUM_GAIN,REPLAYGAIN_ALBUM_PEAK,REPLAYGAIN_TRACK_GAIN,REPLAYGAIN_TRACK_PEAK,TITLE,TOTALDISCS,TOTALTRACKS,TRACKNUMBER,YEAR])

Global Flags:
-C, --config-file string config file to use (optional - will use "config.yaml" or "~/.panosse/config.yaml" if available)
Expand Down Expand Up @@ -157,7 +157,7 @@ Examples:
$ find . -type f -name "*.flac" -print0 | sort -z | xargs -0 -n 1 panosse encode

Flags:
-a, --encode-arguments strings arguments passed to flac to encode the file (default [--compression-level-8,--delete-input-file,--force,--no-padding,--silent,--verify,--warnings-as-errors])
-a, --encode-arguments strings arguments passed to flac to encode the file (default [--compression-level-8,--exhaustive-model-search,--no-padding,--qlp-coeff-precision-search,--verify,--warnings-as-errors])
--encode-if-encode-argument-tags-mismatch encode if encode argument tags mismatch (missing or different) (default true)
--encode-if-flac-versions-mismatch encode if flac versions mismatch between host's flac version and file's flac version (default true)
-h, --help help for encode
Expand Down
14 changes: 7 additions & 7 deletions utils/flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"regexp"
)

func Encode(flacCommand string, encodeSettings []string, flacFile string) error {
func Encode(flacCommand string, encodeSettings []string, flacFile string) (string, error) {
commandExec := exec.Command(flacCommand, append(encodeSettings, flacFile)...)
err := commandExec.Run()
commandOutput, err := commandExec.CombinedOutput()

return err
return string(commandOutput), err
}

const FlacVersionFromFlacCommandRegex = "flac ([\\d]+.[\\d]+.[\\d]+)"
Expand All @@ -36,7 +36,7 @@ func GetFlacVersionFromFlacCommand(flacCommand string) (string, error) {
commandOutput, err := commandExec.CombinedOutput()

if err != nil {
return "", err
return string(commandOutput), err
}

// Define the regular expression
Expand All @@ -58,9 +58,9 @@ func GetFlacVersionFromFlacCommand(flacCommand string) (string, error) {
return flacVersion, nil
}

func Verify(flacCommand string, verifyCommandArguments []string, flacFile string) error {
func Verify(flacCommand string, verifyCommandArguments []string, flacFile string) (string, error) {
commandExec := exec.Command(flacCommand, append(verifyCommandArguments, flacFile)...)
err := commandExec.Run()
commandOutput, err := commandExec.CombinedOutput()

return err
return string(commandOutput), err
}
34 changes: 17 additions & 17 deletions utils/metaflac.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ import (
"strings"
)

func Clean(metaflacCommandPath string, arguments []string, flacFile string) error {
func Clean(metaflacCommandPath string, arguments []string, flacFile string) (string, error) {
commandExec := exec.Command(metaflacCommandPath, append(arguments, flacFile)...)
err := commandExec.Run()
commandOutput, err := commandExec.CombinedOutput()

return err
return string(commandOutput), err
}

func Normalize(metaflacCommandPath string, arguments []string, flacFiles []string) error {
func Normalize(metaflacCommandPath string, arguments []string, flacFiles []string) (string, error) {
commandExec := exec.Command(metaflacCommandPath, append(arguments, flacFiles...)...)
err := commandExec.Run()
commandOutput, err := commandExec.CombinedOutput()

return err
return string(commandOutput), err
}

func GetTag(metaflacCommandPath string, tag string, flacFile string) (string, error) {
commandExec := exec.Command(metaflacCommandPath, "--show-tag", tag, flacFile)
commandOutput, err := commandExec.CombinedOutput()

if err != nil {
return "", err
return string(commandOutput), err
}

tagContents := strings.Split(strings.TrimSpace(string(commandOutput)), "=")
Expand All @@ -56,25 +56,25 @@ func GetTag(metaflacCommandPath string, tag string, flacFile string) (string, er
return tagContent, nil
}

func SetTag(metaflacCommandPath string, tag string, tagContent string, flacFile string) error {
func SetTag(metaflacCommandPath string, tag string, tagContent string, flacFile string) (string, error) {
commandExec := exec.Command(metaflacCommandPath, "--set-tag", tag+"="+tagContent, flacFile)
err := commandExec.Run()
commandOutput, err := commandExec.CombinedOutput()

return err
return string(commandOutput), err
}

func RemoveAllTags(metaflacCommandPath string, flacFile string) error {
func RemoveAllTags(metaflacCommandPath string, flacFile string) (string, error) {
commandExec := exec.Command(metaflacCommandPath, "--remove-all-tags", flacFile)
err := commandExec.Run()
commandOutput, err := commandExec.CombinedOutput()

return err
return string(commandOutput), err
}

func RemoveTag(metaflacCommandPath string, tag string, flacFile string) error {
func RemoveTag(metaflacCommandPath string, tag string, flacFile string) (string, error) {
commandExec := exec.Command(metaflacCommandPath, "--remove-tag", tag, flacFile)
err := commandExec.Run()
commandOutput, err := commandExec.CombinedOutput()

return err
return string(commandOutput), err
}

const FlacVersionFromFlacFileRegex = "reference libFLAC ([\\d]+.[\\d]+.[\\d]+) [\\d]+"
Expand All @@ -84,7 +84,7 @@ func GetFlacVersionFromFlacFile(metaflacCommandPath string, flacFile string) (st
commandOutput, err := commandExec.CombinedOutput()

if err != nil {
return "", err
return string(commandOutput), err
}

// Define the regular expression
Expand Down