fixed bugs which arose from inconsistency between machines

This commit is contained in:
Rachel Lambda Samuelsson 2021-07-04 23:25:47 +02:00
parent fb094b9ea9
commit c7f5d7f0c2

View File

@ -21,7 +21,7 @@ data Resolution
wrapResString :: String -> [String] wrapResString :: String -> [String]
wrapResString str = ["-f", concat ["bestvideo[ext=mp4,height<=", str, wrapResString str = ["-f", concat ["bestvideo[ext=mp4,height<=", str,
"]+bestaudio[ext=m4a]/mp4[height<=", str, "]"]] "]+bestaudio[ext=m4a]/mp4[height<=", str, "]"], "--merge-output-format", "mp4"]
resToArgs :: Resolution -> [String] resToArgs :: Resolution -> [String]
resToArgs (P144) = wrapResString "144" resToArgs (P144) = wrapResString "144"
@ -30,7 +30,7 @@ resToArgs (P360) = wrapResString "360"
resToArgs (P480) = wrapResString "480" resToArgs (P480) = wrapResString "480"
resToArgs (P720) = wrapResString "720" resToArgs (P720) = wrapResString "720"
resToArgs (P1080) = wrapResString "1080" resToArgs (P1080) = wrapResString "1080"
resToArgs (PMAX) = ["-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4"] resToArgs (PMAX) = ["-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4", "--merge-output-format", "mp4"]
resToArgs (Audio) = ["-x", "--audio-format", "mp3"] resToArgs (Audio) = ["-x", "--audio-format", "mp3"]
ytdl :: String -> Resolution -> IO (Either String FilePath) ytdl :: String -> Resolution -> IO (Either String FilePath)
@ -55,13 +55,12 @@ ytdl url res = do
createDirectoryIfMissing True dir createDirectoryIfMissing True dir
print (resToArgs res <> ["-o", fileName, url])
ytdlProc <- createProcess (proc "youtube-dl" (resToArgs res <> ["-o", fileName, url])) ytdlProc <- createProcess (proc "youtube-dl" (resToArgs res <> ["-o", fileName, url]))
{ std_out = CreatePipe
, std_err = CreatePipe }
case ytdlProc of case ytdlProc of
(_, _, Just herr, ph) -> do (_, _, _, ph) -> do
err <- hGetContents herr
exitCode <- waitForProcess ph exitCode <- waitForProcess ph
case exitCode of case exitCode of
ExitSuccess -> do ExitSuccess -> do
@ -73,9 +72,9 @@ ytdl url res = do
_ <- forkIO $ threadDelay 300000000 >> removeDirectoryRecursive dir _ <- forkIO $ threadDelay 300000000 >> removeDirectoryRecursive dir
pure (Right fileName) pure (Right fileName)
else do else do
removeDirectoryRecursive dir -- removeDirectoryRecursive dir
pure (Left "An unknown error prevented the output file from being created") pure (Left "An unknown error prevented the output file from being created")
(ExitFailure status) -> pure (Left (concat ["execution failed with status ", show status, ": ", err])) (ExitFailure status) -> pure (Left ("execution failed with status " <> show status))
_ -> pure (Left "Unable to create ytdlProcess for downloading video") _ -> pure (Left "Unable to create ytdlProcess for downloading video")