summaryrefslogtreecommitdiff
path: root/src/Data/Torrent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent.hs')
-rw-r--r--src/Data/Torrent.hs29
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 @@
26module Data.Torrent 26module 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
68import Prelude hiding (sum) 66import Prelude hiding (sum)
69
70import Control.Applicative 67import Control.Applicative
71import Control.DeepSeq 68import Control.DeepSeq
72import Control.Exception 69import Control.Exception
73import Control.Lens 70import Control.Lens
74
75import Data.Aeson.Types (ToJSON(..), FromJSON(..), Value(..), withText) 71import Data.Aeson.Types (ToJSON(..), FromJSON(..), Value(..), withText)
76import Data.Aeson.TH 72import Data.Aeson.TH
77import Data.BEncode as BE 73import Data.BEncode as BE
@@ -88,6 +84,7 @@ import Data.Time.Clock.POSIX
88import Data.Typeable 84import Data.Typeable
89import Network.URI 85import Network.URI
90import Text.PrettyPrint as PP 86import Text.PrettyPrint as PP
87import Text.PrettyPrint.Class
91import System.FilePath 88import System.FilePath
92 89
93import Data.Torrent.InfoHash as IH 90import 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
158ppPrivacy :: Bool -> Doc 155ppPrivacy :: Bool -> Doc
159ppPrivacy privacy = 156ppPrivacy privacy = "Privacy: " <> if privacy then "private" else "public"
160 "Privacy: " <> if privacy then "private" else "public"
161 157
162ppAdditionalInfo :: InfoDict -> Doc 158ppAdditionalInfo :: InfoDict -> Doc
163ppAdditionalInfo layout = PP.empty 159ppAdditionalInfo layout = PP.empty
164 160
165-- | Format info dictionary in human-readable form. 161instance Pretty InfoDict where
166ppInfoDict :: InfoDict -> Doc 162 pretty InfoDict {..} =
167ppInfoDict 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
291name <:>? (Just d) = name <:> d 286name <:>? (Just d) = name <:> d
292 287
293ppTorrent :: Torrent -> Doc 288instance Pretty Torrent where
294ppTorrent 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