module HBooru.Parsers.Safebooru where
import Data.List
import qualified HBooru.Parsers.GenericBooru as G
import HBooru.Parsers.GenericBooru.TH (makePost)
import HBooru.Types
import Language.Haskell.TH.Syntax (mkName)
import Text.XML.HXT.Core hiding (mkName)
$(makePost (mkName "SafebooruPost"))
data Safebooru = Safebooru
instance Postable Safebooru XML where
postUrl _ _ ts =
let tags = intercalate "+" ts
in "http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags="
++ tags ++ "&pid=0"
hardLimit _ = Limit 100
instance Site Safebooru where
instance PostParser Safebooru XML where
type ImageTy Safebooru XML = SafebooruPost
parseResponse _ = map (`betweenPosts` SafebooruPost)
. runLA (xreadDoc /> G.parsePost) . getResponse
instance Counted Safebooru XML where
parseCount _ = read . head . runLA (xreadDoc >>> hasName "posts"
>>> getAttrValue "count") . getResponse