Fixes 21
authorAbhiranjan Kumar <abhiranjan.kumar00@gmail.com>
Sat, 11 Apr 2015 13:12:54 +0000 (18:42 +0530)
committerAbhiranjan Kumar <abhiranjan.kumar00@gmail.com>
Sat, 11 Apr 2015 13:12:54 +0000 (18:42 +0530)
src/FuncTorrent/Metainfo.hs
test/Test.hs

index 61699a3319e33f6c7a375eec9bf55c9c769f698f..dfedb59dbdd3d57cf3643348d9e70e287f2192d0 100644 (file)
@@ -25,7 +25,7 @@ data Info = Info { pieceLength :: !Integer
 
 data Metainfo = Metainfo { info :: !Info
                          , announceList :: ![String]
-                         , creationDate :: !(Maybe String)
+                         , creationDate :: !(Maybe Integer)
                          , comment :: !(Maybe String)
                          , createdBy :: !(Maybe String)
                          , encoding :: !(Maybe String)
@@ -50,19 +50,22 @@ maybeBstrToString :: Maybe BVal -> Maybe String
 maybeBstrToString (Just (Bstr bs)) = Just $ unpack bs
 maybeBstrToString _ = Nothing
 
+maybeBstrToInteger :: Maybe BVal -> Maybe Integer
+maybeBstrToInteger (Just (Bint bs)) = Just  bs
+maybeBstrToInteger _ = Nothing
+
 mkMetaInfo :: BVal -> Maybe Metainfo
 mkMetaInfo (Bdict m) = let (Just info') = mkInfo $ m ! "info"
                            announce' = lookup "announce" m
                            announceList' = lookup "announce-list" m
-                           -- creationDate = lookup (Bstr (pack "creation date")) m
-                           creationDate' = Nothing
+                           creationDate' = lookup "creation date" m
                            comment' = lookup "comment" m
                            createdBy' = lookup "created by" m
                            encoding' = lookup "encoding" m
                        in Just Metainfo { info = info'
                                         , announceList = maybeToList (announce' >>= bstrToString)
                                                          ++ getAnnounceList announceList'
-                                        , creationDate = creationDate'
+                                        , creationDate = maybeBstrToInteger creationDate'
                                         , comment = maybeBstrToString comment'
                                         , createdBy = maybeBstrToString createdBy'
                                         , encoding = maybeBstrToString encoding'
index 8a4649edf86e49706ccca529a74f5e4eee1b197e..3ead970aa024b32d8e2ba3473b2ca474041c1ebf 100644 (file)
@@ -39,7 +39,7 @@ hello = Metainfo {
             md5sum = Nothing
           },
           announceList = ["http://9.rarbg.com:2710/announce"],
-          creationDate = Nothing,
+          creationDate = Just 1428717851,
           comment = Just "hello world",
           createdBy = Just "Jaseem Abid",
           encoding = Just "UTF-8"