diff options
-rw-r--r-- | src/Data/Torrent.hs | 32 |
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 | ||
64 | import Prelude hiding (sum) | 57 | import Prelude hiding (sum) |
@@ -68,17 +61,19 @@ import Control.DeepSeq | |||
68 | import Control.Exception | 61 | import Control.Exception |
69 | import Control.Lens | 62 | import Control.Lens |
70 | 63 | ||
64 | import Data.Aeson.Types (ToJSON(..), FromJSON(..), Value(..), withText) | ||
71 | import Data.Aeson.TH | 65 | import Data.Aeson.TH |
72 | import Data.BEncode as BE | 66 | import Data.BEncode as BE |
73 | import Data.BEncode.Types as BE | 67 | import Data.BEncode.Types as BE |
74 | import Data.ByteString as BS | 68 | import Data.ByteString as BS |
75 | import qualified Data.ByteString.Char8 as BC (pack, unpack) | 69 | import qualified Data.ByteString.Char8 as BC (pack, unpack) |
76 | import qualified Data.ByteString.Lazy as BL | 70 | import qualified Data.ByteString.Lazy as BL |
77 | import Data.Char | 71 | import Data.Char as Char |
78 | import Data.Hashable as Hashable | 72 | import Data.Hashable as Hashable |
79 | import qualified Data.List as L | 73 | import qualified Data.List as L |
80 | import Data.Text (Text) | 74 | import Data.Text as T |
81 | import Data.Time.Clock.POSIX | 75 | import Data.Time |
76 | import Data.Time.Clock.POSIX | ||
82 | import Data.Typeable | 77 | import Data.Typeable |
83 | import Network.URI | 78 | import Network.URI |
84 | import System.FilePath | 79 | import 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 | ||
115 | makeLensesFor | 110 | makeLensesFor |
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 | ||
187 | instance FromJSON URI where | ||
188 | parseJSON = withText "URI" $ | ||
189 | maybe (fail "could not parse URI") pure . parseURI . T.unpack | ||
190 | |||
191 | instance ToJSON URI where | ||
192 | toJSON = String . T.pack . show | ||
193 | |||
194 | instance ToJSON NominalDiffTime where | ||
195 | toJSON = toJSON . posixSecondsToUTCTime | ||
196 | |||
197 | instance FromJSON NominalDiffTime where | ||
198 | parseJSON v = utcTimeToPOSIXSeconds <$> parseJSON v | ||
199 | |||
200 | $(deriveToJSON (L.map Char.toLower . L.dropWhile isLower) ''Torrent) | ||
201 | |||
192 | makeLensesFor | 202 | makeLensesFor |
193 | [ ("tAnnounce" , "announce" ) | 203 | [ ("tAnnounce" , "announce" ) |
194 | , ("tAnnounceList", "announceList") | 204 | , ("tAnnounceList", "announceList") |