From: Cameron Ball Date: Thu, 13 Jun 2019 07:54:10 +0000 (+0800) Subject: Automate downloading of video entries X-Git-Url: http://cameron1729.xyz/?p=xyz.git;a=commitdiff_plain;h=d1034b25f30a59d8e94157b0b98530d2e04f77cd Automate downloading of video entries --- diff --git a/app/Main.hs b/app/Main.hs index d68cc4c..4d1f781 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -10,7 +10,7 @@ import Prelude hiding (init) import Data.List (intercalate) import Text.JSON import Text.JSON.Generic -import Data.Text hiding (intercalate, unlines, init, length) +import Data.Text hiding (intercalate, unlines, init, length, splitAt) import Data.Time.Clock.POSIX import System.File.Tree hiding (mapM, mapM_) import System.Directory (doesFileExist) @@ -61,12 +61,20 @@ entry :: IO () entry = do putStrLn "Enter a name for this entry:" entryName <- getLine + putStrLn "YouTube video ID?" + ytUrl <- getLine + ytFilename <- if (ytUrl /= "") + then putStrLn "Video filename?" >> getLine >>= return . ("::" ++) . (++ ".webm") + else return "" + entryNum <- fmap ((+1) . length) $ allFilesIn "entries" stamp <- fmap round getPOSIXTime let filename = "entries/" ++ (show entryNum) ++ "-" ++ (unpack . (toLower. replace " " "-") $ pack entryName) ++ ".txt" - writeFile filename (show stamp ++ "::" ++ entryName ++ "\n") + writeFile filename (show stamp ++ "::" ++ entryName ++ ytFilename ++ "\nEntry goes here!\nᚳᚱᛒ\nhttps://www.youtube.com/watch?v=" ++ ytUrl ++ "") putStrLn $ "Created " ++ filename - callCommand $ "emacsclient " ++ filename ++ " &" + callCommand $ "nano " ++ filename + callCommand $ "youtube-dl -f 'webm[height<1080]+bestaudio' \"https://www.youtube.com/watch?v=" ++ ytUrl ++ "\" -o 'build/videos/" ++ (snd . splitAt 2 $ ytFilename) ++ "'" + build usage :: IO () usage = putStr . ununlines $ [ @@ -78,9 +86,9 @@ usage = putStr . ununlines $ [ ] ] -parse ["init"] = init >> exit -parse ["build"] = continueIfValidProject build >> exit -parse ["entry"] = continueIfValidProject entry >> exit +parse ["init"] = init >> exitSuccess +parse ["build"] = continueIfValidProject build >> exitSuccess +parse ["entry"] = continueIfValidProject entry >> exitSuccess parse [_] = usage >> exit parse [] = usage >> exit