kickass-torrents-dump-parser (empty) → 0.0.1
raw patch · 6 files changed
+135/−0 lines, 6 filesdep +basedep +bytestringdep +cassavasetup-changed
Dependencies added: base, bytestring, cassava, hspec, hspec-expectations, string-qq, text, vector
Files
- LICENSE +25/−0
- README.md +7/−0
- Setup.lhs +3/−0
- kickass-torrents-dump-parser.cabal +44/−0
- src/Text/KickassTorrentsDumpParser.hs +55/−0
- test/Spec.hs +1/−0
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2013, Michael Xavier. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,7 @@+kickass-torrents-dump-parser+============================++[](https://travis-ci.org/MichaelXavier/kickass-torrents-dump-parser)++Library to parse the torrent dump files provided by Kickass Torrents. See+http://kat.ph/api/ for the files in question.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ kickass-torrents-dump-parser.cabal view
@@ -0,0 +1,44 @@+name: kickass-torrents-dump-parser+version: 0.0.1+synopsis: Parses kat.ph torrent dumps+description: Parses kat.ph torrent dumps, see http://kat.ph/api/+license: MIT+license-file: LICENSE+author: Michael Xavier <michael@michaelxavier.net>+maintainer: Michael Xavier <michael@michaelxavier.net>+copyright: (c) 2013 Michael Xavier+category: Text+build-type: Simple+cabal-version: >=1.8+tested-with: GHC == 7.6.1+extra-source-files:+ README.md+ LICENSE++library+ exposed-modules: Text.KickassTorrentsDumpParser+ hs-source-dirs: src+ ghc-options: -Wall+ build-depends: base >= 4 && < 5,+ bytestring,+ cassava == 0.2.*,+ text == 0.11.*,+ vector+ ghc-options: -Wall++test-suite spec+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ hs-source-dirs: test,src+ build-depends: base >= 4 && < 5,+ bytestring,+ cassava == 0.2.*,+ hspec == 1.4.*,+ hspec-expectations == 0.3.*,+ text == 0.11.*,+ string-qq == 0.0.*,+ vector++source-repository head+ Type: git+ Location: git://github.com/MichaelXavier/kickass-torrents-dump-parser.git
+ src/Text/KickassTorrentsDumpParser.hs view
@@ -0,0 +1,55 @@+module Text.KickassTorrentsDumpParser (InfoHash(..),+ URL(..),+ ReleaseCategory(..),+ ReleaseTitle(..),+ Release(..),+ parseDump) where++import Control.Applicative ((<$>), (<*>), pure)+import Control.Monad (mzero)+import qualified Data.ByteString.Lazy as LBS+import Data.Csv+import Data.Char (ord)+import Data.Text (Text)+import Data.Text.Encoding (decodeUtf8)+import qualified Data.Vector as V++newtype InfoHash = InfoHash { unInfoHash :: Text } deriving (Show, Eq)+newtype URL = URL { unUrl :: Text } deriving (Show, Eq)+newtype ReleaseCategory = ReleaseCategory { unReleaseCategory :: Text } deriving (Show, Eq)+newtype ReleaseTitle = ReleaseTitle { unReleaseTitle :: Text } deriving (Show, Eq)++data Release = Release {+ infoHash :: InfoHash,+ title :: ReleaseTitle,+ category :: ReleaseCategory,+ katUrl :: URL,+ torrentUrl :: URL+} deriving (Show, Eq)++instance FromRecord Release where+ parseRecord v+ | V.length v == 5 = Release <$> v .! 0+ <*> v .! 1+ <*> v .! 2+ <*> v .! 3+ <*> v .! 4+ | otherwise = mzero++instance FromField InfoHash where+ parseField s = InfoHash <$> pure (decodeUtf8 s)++instance FromField URL where+ parseField s = URL <$> pure (decodeUtf8 s)++instance FromField ReleaseCategory where+ parseField s = ReleaseCategory <$> pure (decodeUtf8 s)++instance FromField ReleaseTitle where+ parseField s = ReleaseTitle <$> pure (decodeUtf8 s)++-- | Parses a release from a Lazy ByteString+parseDump :: LBS.ByteString -> Either String (V.Vector Release)+parseDump = decodeWith options False+ where options = DecodeOptions $ c2w8 '|'+ c2w8 = fromIntegral . ord
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --nested #-}