From: Ramakrishnan Muthukrishnan Date: Wed, 4 Feb 2015 16:23:26 +0000 (+0530) Subject: WIP: mkMetaInfo X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/priv//%22%3C?a=commitdiff_plain;h=a74f51ae87abbcabcd91b5b61df0a9225cb28ff4;p=functorrent.git WIP: mkMetaInfo --- diff --git a/src/Metainfo.hs b/src/Metainfo.hs index 58a2369..c609123 100644 --- a/src/Metainfo.hs +++ b/src/Metainfo.hs @@ -2,6 +2,7 @@ module Metainfo where import qualified Bencode as Benc import qualified Data.ByteString.Char8 as BC +import qualified Data.Map as M import Data.Time.Clock -- only single file mode supported for the time being. @@ -22,4 +23,19 @@ data Metainfo = MetaInfo { info :: Info , encoding :: Maybe String } deriving (Eq) -mkMetaInfo :: Benv.BVal -> MetaInfo +mkMetaInfo :: Benv.BVal -> Maybe MetaInfo +mkMetaInfo (Bdict m) = let info = mkInfo (m ! (Bstr (BC.pack "info"))) + announce = m M.! (Bstr (BC.pack "announce")) + announceList = M.lookup (Bstr (BC.pack "announce list")) m + creationDate = M.lookup (Bstr (BC.pack "creation date")) m + comment = M.lookup (Bstr (BC.pack "comment")) m + createdBy = M.lookup (Bstr (BC.pack "created by")) m + encoding = M.lookup (Bstr (BC.pack "encoding")) m + in Just MetaInfo { info = info + , announce = announce + , announceList = announceList + , creationDate = creationDate + , comment = comment + , createdBy = createdBy + , encoding = encoding } +mkMetaInfo _ = Nothing