1 import System
.IO
(readFile
, FilePath
(..))
2 import System
.Environment
(getArgs
, getProgName
)
4 import Text
.Printf
(printf
)
14 , directors ::
[String
]
16 , countries ::
[String
]
18 , userRating :: Maybe Int
19 , pressRating :: Maybe Int
23 , budgetUnit :: String
27 data Arg
= XML
| MoviesDir
deriving (Show
, Eq
)
28 type Args
= [(Arg
, String
)]
32 progName
<- getProgName
33 case checkArgs
$ readArgs args
of
34 Nothing
-> printf usage progName
36 let dir
= case lookup MoviesDir args
of
39 paths
<- moviePaths dir
40 file
<- readFile
"../xml/test.xml"
41 print
$ parseXMLDoc file
43 movieExtenstions
= ["avi", "mkv", "rmvb", "ogm", "divx"]
44 usage
= "Usage : %s -x <XML file> [-d <Movies dir>]\n"
46 checkArgs :: Maybe Args
-> Maybe Args
47 checkArgs Nothing
= Nothing
48 checkArgs
(Just args
) = if any
(\
(a
, _
) -> a
== XML
) args
52 readArgs ::
[String
] -> Maybe Args
53 readArgs
(name:value:rest
)
54 | name
== "-x" = (XML
, value
) <:
> readArgs rest
55 | name
== "-d" = (MoviesDir
, value
) <:
> readArgs rest
58 _
<:
> Nothing
= Nothing
59 arg
<:
> Just args
= Just
$ arg : args
60 readArgs
(_:
[]) = Nothing
61 readArgs
(_
) = Just
[]
63 moviePaths :: FilePath
-> IO
[FilePath
]
64 moviePaths dir
= undefined
66 readXMLFile :: FilePath
-> IO Movies
67 readXMLFile file
= undefined
71 writeXMLFile :: Movies
-> FilePath
-> IO
()
72 writeXMLFile movies file
= undefined
74 filesPath :: FilePath
-> IO
[FilePath
]
75 filesPath basePath
= undefined
77 movieName :: FilePath
-> String
80 -- Int is the module id.
81 data SearchResult
= OK
(Int
, Movie
)
82 | Many
[(Int
, String
)] -- String is the name of the movie.
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
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.
96 searchAMovie :: String
-> Module
-> IO SearchResult
97 searchAMovie filename mod
= undefined