-- | Ensures the configured transcoder works, returning it as a capability. Will
-- throw a synchronous exception if the transcoder can't be run.
initTranscoder :: TranscoderConfig -> IO (Maybe Transcoder)
initTranscoder tconf@TranscoderConfig {..} = case (transcoderHost, transcoderDir) of
    (Nothing, Nothing) -> return Nothing
    _ -> Just <$> do
        cmd <- getDataFileName "transctl.sh"
        let t =
                Transcoder cmd
                    (["-v", showVersion version]
                    ++ maybe [] (\d -> ["-d", d]) transcoderDir
                    ++ maybe [] (\h -> ["-h", h]) transcoderHost
                    ++ maybe [] (\m -> ["-m", m]) transcoderMount
                    )
                    tconf
        (r, out, err) <- runTranscoder t ["-t"]
        case r of
            ExitSuccess -> return t
            ExitFailure e ->
                fail
                    ("initTranscoder test: "
                    ++ show e
                    ++ "\n=== STDOUT ===\n"
                    ++ out
                    ++ "\n=== STDERR ===\n"
                    ++ err)
initTranscoder :: TranscoderConfig -> IO (Maybe Transcoder)
initTranscoder tconf@TranscoderConfig {..} = case (transcoderHost, transcoderDir) of
    (Nothing, Nothing) -> return Nothing
    _ -> Just <$> do
        cmd <- getDataFileName "transctl.sh"
        let t =
                Transcoder cmd
                    (["-v", showVersion version]
                    ++ maybe [] (\d -> ["-d", d]) transcoderDir
                    ++ maybe [] (\h -> ["-h", h]) transcoderHost
                    ++ maybe [] (\m -> ["-m", m]) transcoderMount
                    )
                    tconf
        (r, out, err) <- runTranscoder t ["-t"]
        case r of
            ExitSuccess -> return t
            ExitFailure e ->
                fail
                    ("initTranscoder test: "
                    ++ show e
                    ++ "\n=== STDOUT ===\n"
                    ++ out
                    ++ "\n=== STDERR ===\n"
                    ++ err)
initTranscoder tconf@TranscoderConfig {..} = case (transcoderHost, transcoderDir) of
    (Nothing, Nothing) -> return Nothing
    _ -> Just <$> do
        cmd <- getDataFileName "transctl.sh"
        let t =
                Transcoder cmd
                    (["-v", showVersion version]
                    ++ maybe [] (\d -> ["-d", d]) transcoderDir
                    ++ maybe [] (\h -> ["-h", h]) transcoderHost
                    ++ maybe [] (\m -> ["-m", m]) transcoderMount
                    )
                    tconf
        (r, out, err) <- runTranscoder t ["-t"]
        case r of
            ExitSuccess -> return t
            ExitFailure e ->
                fail
                    ("initTranscoder test: "
                    ++ show e
                    ++ "\n=== STDOUT ===\n"
                    ++ out
                    ++ "\n=== STDERR ===\n"
                    ++ err)