ADD treatement of the arguments
[pompage.git] / src / Pompage.hs
1 import System.IO (readFile, FilePath(..))
2 import System.Environment (getArgs, getProgName)
3 import Data.List
4 import Text.Printf (printf)
5 import Text.XML.Light
6
7 type Movies = [Movie]
8
9 data Movie = Movie {
10 files :: [FilePath]
11 , id :: Int
12 , title :: String
13 , year :: Maybe Int
14 , directors :: [String]
15 , actors :: [String]
16 , countries :: [String]
17 , length :: Maybe Int
18 , userRating :: Maybe Int
19 , pressRating :: Maybe Int
20 , genre :: [String]
21 , synopsis :: String
22 , budget :: Int
23 , budgetUnit :: String
24 , url :: String
25 } deriving (Show)
26
27 data Arg = XML | MoviesDir deriving (Show, Eq)
28 type Args = [(Arg, String)]
29
30 main = do
31 args <- getArgs
32 progName <- getProgName
33 case checkArgs $ readArgs args of
34 Nothing -> printf usage progName
35 Just args -> do
36 let dir = case lookup MoviesDir args of
37 Just d -> d
38 Nothing -> "."
39 paths <- moviePaths dir
40 file <- readFile "../xml/test.xml"
41 print $ parseXMLDoc file
42
43 movieExtenstions = ["avi", "mkv", "rmvb", "ogm", "divx"]
44 usage = "Usage : %s -x <XML file> [-d <Movies dir>]\n"
45
46 checkArgs :: Maybe Args -> Maybe Args
47 checkArgs Nothing = Nothing
48 checkArgs (Just args) = if any (\(a, _) -> a == XML) args
49 then Just args
50 else Nothing
51
52 readArgs :: [String] -> Maybe Args
53 readArgs (name:value:rest)
54 | name == "-x" = (XML, value) <:> readArgs rest
55 | name == "-d" = (MoviesDir, value) <:> readArgs rest
56 | otherwise = Nothing
57 where
58 _ <:> Nothing = Nothing
59 arg <:> Just args = Just $ arg : args
60 readArgs (_:[]) = Nothing
61 readArgs (_) = Just []
62
63 moviePaths :: FilePath -> IO [FilePath]
64 moviePaths dir = undefined
65
66 readXMLFile :: FilePath -> IO Movies
67 readXMLFile file = undefined
68
69
70
71 writeXMLFile :: Movies -> FilePath -> IO ()
72 writeXMLFile movies file = undefined
73
74 filesPath :: FilePath -> IO [FilePath]
75 filesPath basePath = undefined
76
77 movieName :: FilePath -> String
78 movieName = undefined
79
80 -- Int is the module id.
81 data SearchResult = OK (Int, Movie)
82 | Many [(Int, String)] -- String is the name of the movie.
83 | NotFound
84
85 data Module = Module {
86 search :: String -> IO SearchResult
87 -- Int is the module id. FilePath is a path to the image like "../img/4353"
88 , downloadImage :: Int -> FilePath
89 }
90
91 {-
92 Gets a movie by asking the given module to find a movie.
93 A movie is seeked by its the filename.
94 If there is many possibilities then it will ask the user.
95 -}
96 searchAMovie :: String -> Module -> IO SearchResult
97 searchAMovie filename mod = undefined
98
99