diff options
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r-- | src/Data/Torrent.hs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index dddd1832..fc0cb10b 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -26,7 +26,6 @@ | |||
26 | module Data.Torrent | 26 | module Data.Torrent |
27 | ( -- * Info dictionary | 27 | ( -- * Info dictionary |
28 | InfoDict (..) | 28 | InfoDict (..) |
29 | , ppInfoDict | ||
30 | 29 | ||
31 | -- ** Lenses | 30 | -- ** Lenses |
32 | , infohash | 31 | , infohash |
@@ -36,7 +35,6 @@ module Data.Torrent | |||
36 | 35 | ||
37 | -- * Torrent file | 36 | -- * Torrent file |
38 | , Torrent(..) | 37 | , Torrent(..) |
39 | , ppTorrent | ||
40 | 38 | ||
41 | -- ** Lenses | 39 | -- ** Lenses |
42 | , announce | 40 | , announce |
@@ -66,12 +64,10 @@ module Data.Torrent | |||
66 | ) where | 64 | ) where |
67 | 65 | ||
68 | import Prelude hiding (sum) | 66 | import Prelude hiding (sum) |
69 | |||
70 | import Control.Applicative | 67 | import Control.Applicative |
71 | import Control.DeepSeq | 68 | import Control.DeepSeq |
72 | import Control.Exception | 69 | import Control.Exception |
73 | import Control.Lens | 70 | import Control.Lens |
74 | |||
75 | import Data.Aeson.Types (ToJSON(..), FromJSON(..), Value(..), withText) | 71 | import Data.Aeson.Types (ToJSON(..), FromJSON(..), Value(..), withText) |
76 | import Data.Aeson.TH | 72 | import Data.Aeson.TH |
77 | import Data.BEncode as BE | 73 | import Data.BEncode as BE |
@@ -88,6 +84,7 @@ import Data.Time.Clock.POSIX | |||
88 | import Data.Typeable | 84 | import Data.Typeable |
89 | import Network.URI | 85 | import Network.URI |
90 | import Text.PrettyPrint as PP | 86 | import Text.PrettyPrint as PP |
87 | import Text.PrettyPrint.Class | ||
91 | import System.FilePath | 88 | import System.FilePath |
92 | 89 | ||
93 | import Data.Torrent.InfoHash as IH | 90 | import Data.Torrent.InfoHash as IH |
@@ -156,18 +153,16 @@ instance BEncode InfoDict where | |||
156 | ih = IH.hashlazy (encode dict) | 153 | ih = IH.hashlazy (encode dict) |
157 | 154 | ||
158 | ppPrivacy :: Bool -> Doc | 155 | ppPrivacy :: Bool -> Doc |
159 | ppPrivacy privacy = | 156 | ppPrivacy privacy = "Privacy: " <> if privacy then "private" else "public" |
160 | "Privacy: " <> if privacy then "private" else "public" | ||
161 | 157 | ||
162 | ppAdditionalInfo :: InfoDict -> Doc | 158 | ppAdditionalInfo :: InfoDict -> Doc |
163 | ppAdditionalInfo layout = PP.empty | 159 | ppAdditionalInfo layout = PP.empty |
164 | 160 | ||
165 | -- | Format info dictionary in human-readable form. | 161 | instance Pretty InfoDict where |
166 | ppInfoDict :: InfoDict -> Doc | 162 | pretty InfoDict {..} = |
167 | ppInfoDict InfoDict {..} = | 163 | pretty idLayoutInfo $$ |
168 | ppLayoutInfo idLayoutInfo $$ | 164 | pretty idPieceInfo $$ |
169 | ppPieceInfo idPieceInfo $$ | 165 | ppPrivacy idPrivate |
170 | ppPrivacy idPrivate | ||
171 | 166 | ||
172 | {----------------------------------------------------------------------- | 167 | {----------------------------------------------------------------------- |
173 | -- Torrent info | 168 | -- Torrent info |
@@ -290,13 +285,13 @@ name <:> v = name <> ":" <+> v | |||
290 | _ <:>? Nothing = PP.empty | 285 | _ <:>? Nothing = PP.empty |
291 | name <:>? (Just d) = name <:> d | 286 | name <:>? (Just d) = name <:> d |
292 | 287 | ||
293 | ppTorrent :: Torrent -> Doc | 288 | instance Pretty Torrent where |
294 | ppTorrent Torrent {..} = | 289 | pretty Torrent {..} = |
295 | "InfoHash: " <> ppInfoHash (idInfoHash tInfoDict) | 290 | "InfoHash: " <> pretty (idInfoHash tInfoDict) |
296 | $$ hang "General" 4 generalInfo | 291 | $$ hang "General" 4 generalInfo |
297 | $$ hang "Tracker" 4 trackers | 292 | $$ hang "Tracker" 4 trackers |
298 | $$ ppInfoDict tInfoDict | 293 | $$ pretty tInfoDict |
299 | where | 294 | where |
300 | trackers = case tAnnounceList of | 295 | trackers = case tAnnounceList of |
301 | Nothing -> text (show tAnnounce) | 296 | Nothing -> text (show tAnnounce) |
302 | Just xxs -> vcat $ L.map ppTier $ L.zip [1..] xxs | 297 | Just xxs -> vcat $ L.map ppTier $ L.zip [1..] xxs |