Last active
October 19, 2020 12:11
-
-
Save ners/76e22f7ad9baf12ea924c5a7c0c92d17 to your computer and use it in GitHub Desktop.
Recursively look for FLAC files and convert them to AAC, retaining metadata.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad | |
| import Control.Monad.Extra | |
| import Development.Shake | |
| import Development.Shake.Command | |
| import Development.Shake.FilePath | |
| import Development.Shake.Util | |
| main :: IO () | |
| main = shakeArgs shakeOptions { shakeFiles = ".shake" } $ do | |
| want ["aac"] | |
| phony "aac" $ do | |
| sources <- getDirectoryFiles inputFolder $ ("//*." ++) <$> inputFormats | |
| let targets = [ x -<.> "m4a" | x <- sources, isNotHidden x ] | |
| need targets | |
| "//*.m4a" %> \out -> do | |
| let flacsrc = inputFolder </> out -<.> "flac" | |
| let flactag = out -<.> "json" | |
| need [flacsrc, flactag] | |
| Stdout normflac <- command [BinaryPipes] "sox" ["-q", flacsrc, "-r", "44100", "-b", "16", "-t", "flac", "-"] | |
| Stdout deflac <- command [StdinBS normflac, BinaryPipes] "flac" ["-s", "-d", "-c", "-"] | |
| command_ | |
| [StdinBS deflac] | |
| "fdkaac" | |
| [ "--ignorelength" | |
| , "--silent" | |
| , "--bitrate-mode" | |
| , "4" | |
| , "--tag-from-json" | |
| , flactag ++ "?format.tags" | |
| , "-o" | |
| , out | |
| , "-" | |
| ] | |
| -- cmd_ "mp4art --add cover.jpg" [out] | |
| "//*.json" %> \out -> do | |
| let flacsrc = inputFolder </> out -<.> "flac" | |
| need [flacsrc] | |
| command_ [FileStdout out] "ffprobe" ["-v", "0", "-of", "json", "-show_format", flacsrc] | |
| where | |
| inputFolder = "../Music" | |
| inputFormats = ["flac"] | |
| isNotHidden path = all (\(x:_) -> x /= '.') $ splitPath path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment