module Vimeta.UI.CommandLine.Movie
( Options,
optionsParser,
run,
)
where
import Network.API.TheMovieDB
import Options.Applicative
import System.FilePath
import Vimeta.Core
import Vimeta.UI.CommandLine.Common
import Vimeta.UI.Common.Movie
import Vimeta.UI.Term.Movie
data Options = Options
{ optsMovieID :: Maybe ItemID,
optsFile :: FilePath,
optsCommon :: CommonOptions
}
optionsParser :: Parser Options
optionsParser =
Options <$> optional (option auto getMovieID)
<*> argument str (metavar "FILE")
<*> commonOptions
where
getMovieID =
mconcat
[ short 'i',
long "id",
metavar "ID",
help "Movie ID assigned by TheMovieDB.org"
]
run :: Options -> IO (Either String ())
run opts = execVimeta (updateConfig $ optsCommon opts) $
case optsMovieID opts of
Just mid -> do
movie <- tmdb (fetchMovie mid)
tagMovie (optsFile opts) movie
Nothing -> do
movie <- movieSearch initialTitle
tagMovie (optsFile opts) movie
where
initialTitle :: Text
initialTitle = toText $ dropExtension (takeFileName $ optsFile opts)