Case for when there is no video
authorCameron Ball <cameron@moodle.com>
Thu, 13 Jun 2019 08:00:22 +0000 (16:00 +0800)
committerCameron Ball <cameron@moodle.com>
Thu, 13 Jun 2019 08:00:22 +0000 (16:00 +0800)
app/Main.hs

index 4d1f781..0b0c25b 100644 (file)
@@ -67,13 +67,19 @@ entry = do
     then putStrLn "Video filename?" >> getLine >>= return . ("::" ++) . (++ ".webm")
     else return ""
 
+  ytLink <- if (ytUrl /= "")
+    then return $ "\n<a href=\"https://www.youtube.com/watch?v=" ++ ytUrl ++ "\">https://www.youtube.com/watch?v=" ++ ytUrl ++ "</a>"
+    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 ++ ytFilename ++ "\nEntry goes here!\nᚳᚱᛒ\n<a href=\"https://www.youtube.com/watch?v=" ++ ytUrl ++ "\">https://www.youtube.com/watch?v=" ++ ytUrl ++ "</a>")
+  writeFile filename (show stamp ++ "::" ++ entryName ++ ytFilename ++ "\nEntry goes here!\nᚳᚱᛒ" ++ ytLink)
   putStrLn $ "Created " ++ 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)   ++ "'"
+  if (ytUrl /= "")
+    then callCommand $ "youtube-dl -f 'webm[height<1080]+bestaudio' \"https://www.youtube.com/watch?v=" ++ ytUrl ++ "\" -o 'build/videos/" ++ (snd . splitAt 2 $ ytFilename)   ++ "'"
+    else return ()
   build
 
 usage :: IO ()