diff --git a/src/Templates/Error.hs b/src/Templates/Error.hs index 64d36d5..0963992 100644 --- a/src/Templates/Error.hs +++ b/src/Templates/Error.hs @@ -5,6 +5,7 @@ module Templates.Error (errorPage) where import qualified Data.Text.Lazy as TL import Text.RawString.QQ +import Text.HTML.SanitizeXSS errorPage :: TL.Text -> TL.Text errorPage msg = [r| @@ -17,7 +18,7 @@ errorPage msg = [r|

viddl

-

|] <> msg <> [r|

+

|] <> (TL.fromStrict (sanitize (TL.toStrict msg))) <> [r|


viddl is free open source software and is powered by youtube-dl.

diff --git a/src/YTDL.hs b/src/YTDL.hs index 70573e7..d9ce528 100644 --- a/src/YTDL.hs +++ b/src/YTDL.hs @@ -9,6 +9,7 @@ import qualified Data.ByteString.Lazy.UTF8 as BCU import System.Directory import System.Exit import System.Process +import System.IO data Resolution = P144 @@ -61,9 +62,13 @@ ytdl url res = ReaderT $ \cfg -> do print (resToArgs res <> ["-o", fileName, url]) ytdlProc <- createProcess (proc "youtube-dl" (resToArgs res <> ["-o", fileName, url] <> extraYtdlArgs)) + { std_out = CreatePipe + , std_err = CreatePipe } case ytdlProc of - (_, _, _, ph) -> do + (_, Just hout, Just herr, ph) -> do + err <- hGetContents herr + out <- hGetContents hout exitCode <- waitForProcess ph case exitCode of ExitSuccess -> do @@ -77,4 +82,11 @@ ytdl url res = ReaderT $ \cfg -> do removeDirectoryRecursive dir pure (Left "An unknown error prevented the output file from being created") - (ExitFailure status) -> pure (Left ("execution failed with status " <> show status)) + (ExitFailure status) -> pure (Left (concat ["execution failed with status '" + , show status + , "'
"
+              , out, err
+              , "' 
" + ])) + + _ -> pure (Left "Unable to spawn process for downloading") diff --git a/viddl.cabal b/viddl.cabal index 0e4b015..aeadcb8 100644 --- a/viddl.cabal +++ b/viddl.cabal @@ -30,6 +30,7 @@ library , pureMD5 , utf8-string , transformers + , xss-sanitize hs-source-dirs: src default-language: Haskell2010 @@ -52,5 +53,6 @@ executable viddl , pureMD5 , utf8-string , transformers + , xss-sanitize hs-source-dirs: src default-language: Haskell2010