summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Data/Torrent.hs32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 15ada35f..90ec0cc4 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -52,13 +52,6 @@ module Data.Torrent
52 , isTorrentPath 52 , isTorrentPath
53 , fromFile 53 , fromFile
54 , toFile 54 , toFile
55
56{-
57 , nullTorrent
58 , mktorrent
59
60
61-}
62 ) where 55 ) where
63 56
64import Prelude hiding (sum) 57import Prelude hiding (sum)
@@ -68,17 +61,19 @@ import Control.DeepSeq
68import Control.Exception 61import Control.Exception
69import Control.Lens 62import Control.Lens
70 63
64import Data.Aeson.Types (ToJSON(..), FromJSON(..), Value(..), withText)
71import Data.Aeson.TH 65import Data.Aeson.TH
72import Data.BEncode as BE 66import Data.BEncode as BE
73import Data.BEncode.Types as BE 67import Data.BEncode.Types as BE
74import Data.ByteString as BS 68import Data.ByteString as BS
75import qualified Data.ByteString.Char8 as BC (pack, unpack) 69import qualified Data.ByteString.Char8 as BC (pack, unpack)
76import qualified Data.ByteString.Lazy as BL 70import qualified Data.ByteString.Lazy as BL
77import Data.Char 71import Data.Char as Char
78import Data.Hashable as Hashable 72import Data.Hashable as Hashable
79import qualified Data.List as L 73import qualified Data.List as L
80import Data.Text (Text) 74import Data.Text as T
81import Data.Time.Clock.POSIX 75import Data.Time
76import Data.Time.Clock.POSIX
82import Data.Typeable 77import Data.Typeable
83import Network.URI 78import Network.URI
84import System.FilePath 79import System.FilePath
@@ -110,7 +105,7 @@ data InfoDict = InfoDict
110 -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html> 105 -- BEP 27: <http://www.bittorrent.org/beps/bep_0027.html>
111 } deriving (Show, Read, Eq, Typeable) 106 } deriving (Show, Read, Eq, Typeable)
112 107
113$(deriveJSON (L.map toLower . L.dropWhile isLower) ''InfoDict) 108$(deriveJSON (L.map Char.toLower . L.dropWhile isLower) ''InfoDict)
114 109
115makeLensesFor 110makeLensesFor
116 [ ("idInfoHash" , "infohash" ) 111 [ ("idInfoHash" , "infohash" )
@@ -189,6 +184,21 @@ data Torrent = Torrent
189 -- encrypted SHA-1 hash of the info dictionary). 184 -- encrypted SHA-1 hash of the info dictionary).
190 } deriving (Show, Eq, Typeable) 185 } deriving (Show, Eq, Typeable)
191 186
187instance FromJSON URI where
188 parseJSON = withText "URI" $
189 maybe (fail "could not parse URI") pure . parseURI . T.unpack
190
191instance ToJSON URI where
192 toJSON = String . T.pack . show
193
194instance ToJSON NominalDiffTime where
195 toJSON = toJSON . posixSecondsToUTCTime
196
197instance FromJSON NominalDiffTime where
198 parseJSON v = utcTimeToPOSIXSeconds <$> parseJSON v
199
200$(deriveToJSON (L.map Char.toLower . L.dropWhile isLower) ''Torrent)
201
192makeLensesFor 202makeLensesFor
193 [ ("tAnnounce" , "announce" ) 203 [ ("tAnnounce" , "announce" )
194 , ("tAnnounceList", "announceList") 204 , ("tAnnounceList", "announceList")