module Main (main) where import System.Environment (getArgs) import Control.Monad.Reader (runReaderT, liftIO) import EpubParser import qualified Data.Text.IO as TIO import qualified Data.Text as T main :: IO () main = do args <- getArgs case args of [] -> putStrLn "Usage: svitak " (path:_) -> runSvitak path runSvitak :: FilePath -> IO () runSvitak path = do result <- openEpub path case result of Left err -> putStrLn err Right arch -> do let maybeOpfPath = getOpfPath arch case maybeOpfPath of Nothing -> putStrLn "Error: Could not find OPF metadata file." Just opfPath -> do let tags = getOpfTags arch opfPath let env = myEnv arch opfPath tags runReaderT printFirstRealChapter env printFirstRealChapter :: EpubAction () printFirstRealChapter = do chapterPaths <- resolveSpine findText chapterPaths where findText [] = liftIO $ putStrLn "End of book!" findText (p:ps) = do liftIO $ putStrLn $ "Checking: " ++ p ++ "..." text <- getChapter p let cleanText = T.strip text if T.null cleanText then findText ps else do liftIO $ putStrLn "\n Found text:" liftIO $ putStrLn "--------------------------------" liftIO $ TIO.putStrLn $ T.take 500 cleanText liftIO $ putStrLn "..."