From a74f51ae87abbcabcd91b5b61df0a9225cb28ff4 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Wed, 4 Feb 2015 21:53:26 +0530
Subject: [PATCH] WIP: mkMetaInfo

---
 src/Metainfo.hs | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

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
-- 
2.45.2