3 import System.Environment (getArgs)
4 import qualified Data.ByteString.Char8 as BC
5 import qualified Bencode as Benc
6 import qualified Metainfo as MInfo
7 import qualified Tracker as T
8 import qualified Text.ParserCombinators.Parsec as Parsec
11 printError :: Parsec.ParseError -> IO ()
12 printError e = putStrLn $ "parse error: " ++ show e
15 genPeerId = "-HS0001-20150215"
20 torrentStr <- BC.readFile (head args)
21 case (Benc.decode torrentStr) of
22 Right d -> case (MInfo.mkMetaInfo d) of
23 Nothing -> putStrLn "parse error"
25 body <- (Benc.decode . BC.pack) <$> T.connect (MInfo.announce m) (T.prepareRequest d genPeerId)
27 Left e -> printError e