module Web.Last.Tag where import Control.Applicative import Control.Arrow import Web.Last.Types import Web.Last.Request import qualified Web.Last.Parsing as P import Text.JSON.Combinators -- Broken on api end. Same problem as Track.getSimilar -- json is mangled getSimilar :: String -> Last [Tag] getSimilar tag = anonRequest "tag.getsimilar" [("tag",tag)] [] pa where pa = objOf $ inObj "similartags" $ llArr "tag" P.tag -- String is tagcount getTopAlbums :: String -> Last [(Album,String,[Image])] getTopAlbums tag = anonRequest "tag.gettopalbums" [("tag",tag)] [] pa where pa = objOf $ inObj "topalbums" $ llArr "album" $ return (,,) <*> P.album <*> objOf (ll "tagcount" strJS) <*> objOf (llArr "image" P.image) -- String is tagcount getTopArtists :: String -> Last [(Artist,String,[Image])] getTopArtists tag = anonRequest "tag.gettopartists" [("tag",tag)] [] pa where pa = objOf $ inObj "topartists" $ llArr "artist" $ return (,,) <*> P.artist <*> objOf (ll "tagcount" strJS) <*> objOf (llArr "image" P.image) -- String is tagcount getTopTags :: String -> Last [Tag] getTopTags tag = anonRequest "tag.gettoptags" [("tag",tag)] [] pa where pa = objOf $ inObj "toptags" $ llArr "tag" $ P.tag -- String is tagcount getTopTracks :: String -> Last [(Track,String,[Image])] getTopTracks tag = anonRequest "tag.gettoptracks" [("tag",tag)] [] pa where pa = objOf $ inObj "toptracks" $ llArr "track" $ return (,,) <*> P.track <*> objOf (ll "tagcount" strJS) <*> objOf (llArr "image" P.image) getWeeklyArtistChart :: String -> Maybe String -> Maybe String -> Maybe Int -> Last [Weighted Artist] getWeeklyArtistChart tag from to limit = anonRequest "tag.getweeklyartistchart" [("tag",tag)] [("from",from),("to",to),("limit",show <$> limit)] pa where pa = objOf $ inObj "weeklyartistchart" $ llArr "artist" (P.weighted P.artist) getWeeklyChartList :: String -> Last [(String,String)] getWeeklyChartList tag = anonRequest "tag.getweeklychartlist" [("tag",tag)] [] pa where pa = objOf $ inObj "weeklychartlist" $ llArr "chart" $ objOf $ (ll "from" strJS) &&& (ll "to" strJS) -- String is tagcount search :: String -> Last (Paged (Tag,String)) search tag = pagedRequest "tag.search" [("tag",tag)] [] pa pno where pa = objOf $ inObj "results" $ inObj "tagmatches" $ llArr "tag" $ P.tag &&& (objOf $ ll "count" strJS) pno = P.openSearchPages