module Web.Last.Artist 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 -- addTags needs auth getEvents :: String -> Last [Event] getEvents artistName = anonRequest "artist.getevents" [("artist",artistName)] [] pa where pa = objOf $ inObj "events" $ llArr "event" P.event -- Sometimes instead of a list of similar artists we get "\n\t" which causes problems getInfo :: Maybe String -> Maybe String -> Maybe String -> Last (Artist,ArtistInfo) getInfo artistName artistMBID lang = anonRequest "artist.getinfo" [] [("artist",artistName),("mbid",artistMBID),("lang",lang)] pa where pa = objOf $ ll "artist" $ P.artist &&& P.artistInfo getShouts :: String -> Last [Shout] getShouts artistName = anonRequest "artist.getshouts" [("artist",artistName)] [] pa where pa = objOf $ inObj "shouts" $ llArr "shout" P.shout -- Broken on last.fm end - does not translate properly to json getSimilar :: String -> Maybe Int -> Last [(Artist,[Image])] getSimilar artistName limit = anonRequest "artist.getsimilar" [("artist",artistName)] [("limit",show <$> limit)] pa where pa = objOf $ inObj "similarartists" $ llArr "artist" $ P.artist &&& (objOf $ llArr "image" P.image) -- getTags needs auth getTopAlbums :: String -> Last [Ranked Album] getTopAlbums artistName = anonRequest "artist.gettopalbums" [("artist",artistName)] [] pa where pa = objOf $ inObj "topalbums" $ llArr "album" (P.ranked P.album) getTopFans :: String -> Last [(Weighted User,[Image])] getTopFans artistName = anonRequest "artist.gettopfans" [("artist",artistName)] [] pa where pa = objOf $ inObj "topfans" $ llArr "user" $ (P.weighted P.user) &&& (objOf $ llArr "image" P.image) getTopTags :: String -> Last [Tag] getTopTags artistName = anonRequest "artist.gettoptags" [("artist",artistName)] [] pa where pa = objOf $ inObj "toptags" $ llArr "tag" P.tag getTopTracks :: String -> Last [(Ranked Track,[Image])] getTopTracks artistName = anonRequest "artist.gettoptracks" [("artist",artistName)] [] pa where pa = objOf $ inObj "toptracks" $ llArr "track" $ (P.ranked P.track) &&& (objOf $ llArr "image" P.image) -- removeTags needs auth search :: String -> Last (Paged (Artist,[Image])) search artistName = pagedRequest "artist.search" [("artist",artistName)] [] pa pno where pa = objOf $ inObj "results" $ inObj "artistmatches" $ llArr "artist" $ P.artist &&& (objOf $ llArr "image" P.image) pno = P.openSearchPages