3 import System.Environment (getArgs)
5 import qualified Data.ByteString.Char8 as BC
6 import qualified Bencode as Benc
7 import qualified Metainfo as MInfo
8 import qualified Tracker as T
9 import qualified Text.ParserCombinators.Parsec as Parsec
12 printError :: Parsec.ParseError -> IO ()
13 printError e = putStrLn $ "parse error: " ++ show e
16 genPeerId = "-HS0001-20150215"
18 exit :: IO BC.ByteString
19 exit = exitWith ExitSuccess
22 usage = putStrLn "usage: deluge torrent-file"
24 parse :: [String] -> IO (BC.ByteString)
25 parse [] = usage >> exit
26 parse [a] = BC.readFile a
32 torrentStr <- parse args
33 case (Benc.decode torrentStr) of
34 Right d -> case (MInfo.mkMetaInfo d) of
35 Nothing -> putStrLn "parse error"
37 body <- (Benc.decode . BC.pack) <$> T.connect (MInfo.announce m) (T.prepareRequest d genPeerId)
39 Left e -> printError e