Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Convert audio names to md5 digest
Browse files Browse the repository at this point in the history
  • Loading branch information
akilegaspi committed Jan 14, 2019
1 parent f4db3f0 commit baa2bc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions komposition.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ library
build-depends: base >=4.10 && <5
, async
, binary
, bytestring
, deepseq
, directory
, exceptions
Expand Down Expand Up @@ -119,6 +120,7 @@ library
, pipes-safe
, primitive
, protolude
, pureMD5
, typed-process >= 0.2 && < 0.3
, row-types
, safe-exceptions
Expand Down
11 changes: 7 additions & 4 deletions src/Komposition/Import/Audio/Sox.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import Control.Effect.Carrier
import Control.Effect.Sum
import Control.Monad.Catch hiding (bracket)
import qualified Data.Char as Char
import qualified Data.ByteString.Lazy.Char8 as Lazy
import Data.Digest.Pure.MD5
import qualified Data.Text as Text
import Data.Time.Clock
import Pipes
Expand Down Expand Up @@ -167,8 +169,7 @@ transcodeAudioFileToWav
-> FilePath
-> Producer ProgressUpdate m FilePath
transcodeAudioFileToWav tempDir fullLength inPath = do
-- TODO: use md5 digest to avoid collisions
let outPath = tempDir </> takeBaseName inPath <> ".wav"
let outPath = tempDir </> createMD5BaseName inPath <> ".wav"
cmd =
Command
{ output = Command.FileOutput outPath
Expand Down Expand Up @@ -200,12 +201,11 @@ instance (MonadIO m, Carrier sig m) => Carrier (AudioImport :+: sig) (SoxAudioIm
(liftIO . removeDirectoryRecursive)
$ \tempDir -> do
fullLength <- getAudioFileDuration srcFile
-- TODO: use file md5 digest in filename (or for a subdirectory) to avoid collisions
chunks <-
divideProgress4
(transcodeAudioFileToWav tempDir fullLength srcFile)
(normalizeAudio tempDir)
(splitAudioBySilence (outDir </> "audio-chunks") (takeBaseName srcFile <> "-%5n.wav"))
(splitAudioBySilence (outDir </> "audio-chunks") (createMD5BaseName srcFile <> "-%5n.wav"))
dropSilentChunks
lift (mapM (filePathToAudioAsset outDir) chunks)
Unclassified -> k $ do
Expand All @@ -225,6 +225,9 @@ instance (MonadIO m, Carrier sig m) => Carrier (AudioImport :+: sig) (SoxAudioIm
-- TODO: Check that it can be processed, not just checking the extension
k (takeExtension p `elem` [".wav", ".mp3", ".m4a", ".aiff", ".aac"])

createMD5BaseName :: [Char] -> [Char]
createMD5BaseName = show .md5 . Lazy.pack . takeBaseName

runSoxAudioImport :: (MonadIO m, Carrier sig m) => Eff (SoxAudioImportC m) a -> m a
runSoxAudioImport = runSoxAudioImportC . interpret

Expand Down

0 comments on commit baa2bc0

Please sign in to comment.