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)
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ᚳᚱᛒ\n<a href=\"https://www.youtube.com/watch?v=" ++ ytUrl ++ "\">https://www.youtube.com/watch?v=" ++ ytUrl ++ "</a>")
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 $ [
]
]
-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