summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent/Tracker.hs23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/Network/BitTorrent/Tracker.hs b/src/Network/BitTorrent/Tracker.hs
index 56def0ed..ed3f1d78 100644
--- a/src/Network/BitTorrent/Tracker.hs
+++ b/src/Network/BitTorrent/Tracker.hs
@@ -15,7 +15,8 @@
15-- easily request scrape info for a particular torrent list. 15-- easily request scrape info for a particular torrent list.
16-- 16--
17{-# LANGUAGE OverloadedStrings #-} 17{-# LANGUAGE OverloadedStrings #-}
18{-# LANGUAGE RecordWildCards #-} 18{-# LANGUAGE RecordWildCards #-}
19{-# LANGUAGE TemplateHaskell #-}
19module Network.BitTorrent.Tracker 20module Network.BitTorrent.Tracker
20 ( withTracker, completedReq 21 ( withTracker, completedReq
21 22
@@ -43,11 +44,12 @@ import Control.Concurrent.STM
43import Control.Exception 44import Control.Exception
44import Control.Monad 45import Control.Monad
45 46
46import Data.Aeson hiding (Result) 47import Data.Aeson.TH
47import Data.BEncode 48import Data.BEncode
48import Data.ByteString (ByteString) 49import Data.ByteString (ByteString)
49import qualified Data.ByteString as B 50import qualified Data.ByteString as B
50import qualified Data.ByteString.Char8 as BC 51import qualified Data.ByteString.Char8 as BC
52import Data.Char
51import Data.List as L 53import Data.List as L
52import Data.Map (Map) 54import Data.Map (Map)
53import qualified Data.Map as M 55import qualified Data.Map as M
@@ -293,22 +295,7 @@ instance BEncodable ScrapeInfo where
293 <*> d >--? "name" 295 <*> d >--? "name"
294 fromBEncode _ = decodingError "ScrapeInfo" 296 fromBEncode _ = decodingError "ScrapeInfo"
295 297
296instance ToJSON ScrapeInfo where 298$(deriveJSON (L.map toLower . L.dropWhile isLower) ''ScrapeInfo)
297 toJSON ScrapeInfo {..} = object
298 [ "complete" .= siComplete
299 , "downloaded" .= siDownloaded
300 , "incomplete" .= siIncomplete
301 , "name" .= siName
302 ]
303
304instance FromJSON ScrapeInfo where
305 parseJSON (Object obj) = do
306 ScrapeInfo <$> obj .: "complete"
307 <*> obj .: "downloaded"
308 <*> obj .: "incomplete"
309 <*> obj .:? "name"
310
311 parseJSON _ = fail "ScrapeInfo"
312 299
313-- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL' 300-- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL'
314-- gives 'Nothing' then tracker do not support scraping. The info hash 301-- gives 'Nothing' then tracker do not support scraping. The info hash