text: "use strict";function chartController(t,e){function r(){e.getTopArtists().then(function(e){t.topArtists=e.topartists.artist,console.log(t.topArtists)})}r()}var app=angular.module("Scrbbl",["ngCookies","ngResource","ngMessages","ngRoute","mgcrea.ngStrap"]);app.config(["$locationProvider","$routeProvider",function(t,e){t.html5Mode(!0),e.when("/",{templateUrl:"public/views/home.html",controller:"MainCtrl"}).when("/manual",{templateUrl:"public/views/manual.html",controller:"ManualCtrl"}).when("/scrobblealbum",{templateUrl:"public/views/scrobblealbum.html",controller:"ScrobbleAlbumCtrl"}).when("/scrobbleradio",{templateUrl:"public/views/scrobbleradio.html",controller:"RadioCtrl"}).when("/scrobbleuser",{templateUrl:"public/views/scrobbleuser.html",controller:"ScrobbleUserCtrl"}).when("/charts",{templateUrl:"public/views/charts.html",controller:"ChartCtrl"}).when("/fun",{templateUrl:"public/views/fun.html",controller:"FunCtrl"}).when("/404",{templateUrl:"public/views/404.html"}).otherwise({redirectTo:"/404"})}]),function(){app.factory("Authenticate",["$http","$window","$location",function(t,e,r){function n(){var t=r.absUrl().split("?")[0];return e.location.href="http://www.last.fm/api/auth/?api_key=f4f831e3766b42660d26c9b29b25599e&cb="+t}function o(e){return t.get("/api/auth/"+e)}return{login:n,createSession:o}}])}(),function(){function t(t,e,r,n,o){function a(){var t=o.absUrl().split("?")[0];return n.location.href="http://www.last.fm/api/auth/?api_key=f4f831e3766b42660d26c9b29b25599e&cb="+t}function c(e){return t.get("/api/auth/"+e)}function s(e){return t.get("/api/user/getuserplays/"+e).then(i).catch(u)}function l(){var n=r.getCookieData();e.defer();return t({method:"GET",url:"/api/user/getusertopartists",headers:{user:n.userName}}).then(function(t){return t.data})}function i(t){return t.data.recenttracks.track}function u(t){console.log(t)}return{getUserData:s,getTopArtists:l,login:a,createSession:c}}app.factory("LastfmUser",["$http","$q","UserPersistence","$window","$location",t])}(),function(){app.factory("Radio",["$http","$window","$q",function(t,e,r){function n(e){return t.get("/api/user/getuserplays/"+e).then(function(t){return t.data.recenttracks.track}).catch(function(t){r.reject("Error retrieving station plays - (HTTP Status: "+t.status+")")})}return{getStationPlays:n}}])}(),function(){app.factory("Scrobble",["$http","$window","$q","UserPersistence",function(t,e,r,n){function o(e){return t.post("/api/scrobble",e)}function a(e){return t.post("/api/searchalbum",e).then(function(t){var e=_.map(t.data.results,function(t){return{title:t.collectionName,artist:t.artistName,collectionId:t.collectionId,imageUrl:t.artworkUrl60}});return e}).catch(function(t){return r.reject("Error searching for albums - (HTTP Status: "+t.status+")")})}function c(e){return t({method:"POST",url:encodeURI("/api/scrobblealbum"),headers:{username:i.userName,key:i.key},data:e})}function s(t){}function l(){return t({method:"GET",url:encodeURI("api/getartistscrobbles"),headers:{username:i.userName,key:i.key}}).then(function(t){return t.data})}var i=n.getCookieData(),u={};return{scrobbleTrack:o,searchAlbum:a,scrobbleAlbum:c,getArtistScrobbles:s,getUserTopArtists:l,topArtists:u}}])}(),function(){app.factory("Track",["$http","$window","$q",function(t,e,r){function n(e){return t.get("/api/albums/getalbuminfo/"+e).then(function(t){return t.data}).catch(function(t){return r.reject("Error getting album tracks")})}return{getAlbumTracks:n}}])}(),function(){app.factory("UserPersistence",["$cookies",function(t){function e(e){a=e.userName,c=e.key,t.put("userName",a),t.put("key",c)}function r(){var e={};return e.userName=t.get("userName"),e.key=t.get("key"),e.userName?e:null}function n(){a="",c="",t.remove("userName"),t.remove("key")}function o(){var e=null;return t.get("key")&&(e=t.get("key")),e}var a="",c="";return{setCookieData:e,getCookieData:r,clearCookieData:n,getCookieKey:o}}])}(),function(){app.controller("ScrobbleAlbumCtrl",["$scope","$alert","Authenticate","$location","Scrobble","UserPersistence","Track",function(t,e,r,n,o,a,c){t.album={},t.selectedAlbum=null,t.search=function(){o.searchAlbum(t.album).then(function(e){t.results=e}).catch(function(t){console.log(t)}).finally(function(){console.log("Complete")})},t.refreshForm=function(){t.success=!1,t.track={}},t.selectResult=function(e){t.selectedAlbum=e,c.getAlbumTracks(e.collectionId).then(function(e){t.album.tracks=e})},t.scrobbleAlbum=function(){t.album.user=a.getCookieData(),o.scrobbleAlbum(t.album).then(function(e){t.success=e,t.loading=!1,t.results={},t.selectedAlbum={},t.album={}})}}])}(),app.controller("ChartCtrl",["$scope","LastfmUser",chartController]),function(){app.controller("LoginCtrl",["$scope","$alert","LastfmUser","$location","UserPersistence",function(t,e,r,n,o){o.getCookieData()&&(t.user=o.getCookieData());var a=n.search().token;a&&"undefined"!=a&&!o.getCookieData()&&r.createSession(a).then(function(e){t.user={},t.user.userName=e.data.username,t.user.key=e.data.key,o.setCookieData(t.user)}),console.log(t.user),t.authenticate=function(){console.log("clicked"),r.login()},t.logout=function(){o.clearCookieData(),location.reload()}}])}(),function(){app.controller("MainCtrl",["$scope","$alert","Authenticate","$location","$cookies","UserPersistence",function(t,e,r,n,o,a){t.showFirstVisitMessage=!o.visited,o.visited="yes"}])}(),function(){app.controller("ManualCtrl",["$scope","$alert","Authenticate","$location","Scrobble","UserPersistence",function(t,e,r,n,o,a){a.getCookieData()&&o.getUserTopArtists().then(function(t){o.topArtists=t}),t.track={},t.success=!1,t.scrobble=function(){t.loading=!0,t.track.user=a.getCookieData(),o.scrobbleTrack(t.track).then(function(e){t.success=e,t.loading=!1})},t.refreshForm=function(){t.success=!1,t.track={}},t.$watch("track.songArtist",_.debounce(function(e,r){t.$apply(function(){void 0!==e&&(t.artistScrobbles=_.result(_.find(o.topArtists,function(t){return t.name.toLowerCase()===e.toLowerCase()}),"playcount"),console.log(t.artistScrobbles))})},1e3),!0),t.clearForm=function(){t.track={}}}])}(),function(){app.controller("RadioCtrl",["$scope","$alert","Authenticate","$location","Scrobble","Radio",function(t,e,r,n,o,a){t.search={},t.stations=[{station:"Radio 1",lastfmName:"bbcradio1"},{station:"Radio 2",lastfmName:"bbcradio2"},{station:"Radio 3",lastfmName:"bbcradio3"},{station:"Radio 1xtra",lastfmName:"bbc1xtra"}],t.getStationPlays=function(){a.getStationPlays(t.search.selectedStation).then(function(e){t.results=_.map(e,function(t){return{title:t.name,artist:t.artist["#text"],date:t.date?t.date["#text"]:" "}})}).catch(function(t){console.log("Error message: "+t)})},t.scrobbleSelected=function(){var e={};e.tracks=_.chain(t.results).filter(function(t){return t.toScrobble}).map(function(t){return{artistName:t.artist,trackCensoredName:t.title,date:t.date}}).value(),o.scrobbleAlbum(e).then(function(e){t.success=e,t.loading=!1,t.results=null,t.selectedAlbum={},t.album={}})},t.refreshForm=function(){t.success=!1,t.search={}}}])}(),function(){app.controller("ScrobbleUserCtrl",["$scope","LastfmUser","Scrobble",function(t,e,r){t.lastfmuser={},t.searchUser=function(){e.getUserData(t.lastfmuser.name).then(function(e){t.results=_.map(e,function(t){return{title:t.name,artist:t.artist["#text"],date:t.date?t.date["#text"]:"",album:t.album?t.album["#text"]:""}})}).catch(function(t){})},t.scrobbleSelected=function(){var e={};e.tracks=_.chain(t.results).filter(function(t){return t.toScrobble}).map(function(t){return{artistName:t.artist,trackCensoredName:t.title,date:t.date,collectionName:t.album}}).value(),r.scrobbleAlbum(e).then(function(e){t.success=e,t.loading=!1,t.results=null,t.selectedAlbum={},t.album={}})},t.$watch("lastfmuser.name",_.debounce(function(e,r){t.$apply(function(){console.log(t.lastfmuser.name)})},1e3),!0)}])}();