Browse Source

fix beta lastfm api

windhamdavid 4 years ago
parent
commit
88a1e6fba2
2 changed files with 68 additions and 4 deletions
  1. 52 2
      js/fm.js
  2. 16 2
      page-music.php

+ 52 - 2
js/fm.js

@@ -425,7 +425,7 @@ $('.music-typed').waypoint(function() {
 	$('.wartists').lfmaw();
 	
 	$.fn.lfmtm = function(options){
-		var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=3month&format=json&limit=45";
+		var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=1month&format=json&limit=45";
 		var tracks = [];
 		function isLoadedt (tracksElement) {
 			for (var i = 0; i < tracks.length; i++){
@@ -449,7 +449,7 @@ $('.music-typed').waypoint(function() {
 	};
 	
 	$.fn.lfmam = function(options){
-		var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=3month&format=json&limit=45";
+		var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=1month&format=json&limit=45";
 		var artists = [];
 		function isLoadeda (artistElement) {
 			for (var i = 0; i < artists.length; i++){
@@ -523,6 +523,56 @@ $('.music-typed').waypoint(function() {
 	
 	$('.artists').lfma();
 	$('.tracks').lfmt();
+	
+	$.fn.lfya = function(options){
+		var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=1year&format=json&limit=50";
+		var artists = [];
+		function isLoadeda (artistElement) {
+			for (var i = 0; i < artists.length; i++){
+				var markup = $("<li class='list-group-item'>" + artists[i].aname + "<span class='badge'>" + artists[i].played + "</span></li>");
+				artistElement.append(markup);
+			}
+		}
+		return this.each(function(){
+			var $this = $(this);
+			$.getJSON( urla, function(data){
+				$(data.topartists.artist).each(function(){
+					artists.push ({
+						aname:	this.name,
+						played: this.playcount
+					});
+				});
+				isLoadeda($this);
+			});
+		});
+	};
+	
+	$.fn.lfyt = function(options){
+		var urla = "https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=1year&format=json&limit=50";
+		var tracks = [];
+		function isLoadedt (tracksElement) {
+			for (var i = 0; i < tracks.length; i++){
+				var markup = $("<li class='list-group-item'>" + tracks[i].artist + " - <span class='artist'>" + tracks[i].title + "</span><span class='badge'>" + tracks[i].played + "</span></li>");
+				tracksElement.append(markup);
+			}
+		}
+		return this.each(function(){
+			var $this = $(this);
+			$.getJSON( urla, function(data){
+				$(data.toptracks.track).each(function(){
+					tracks.push ({
+						title: this.name,
+						artist: this.artist.name,
+						played: this.playcount,
+					});
+				});
+				isLoadedt($this);
+			});
+		});
+	};
+	
+	$('.artists').lfya();
+	$('.tracks').lfyt();
 
 	$.fn.lfm = function(options){
 		var url = "https://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=windhamdavid&api_key=e12ea1d0253898ee9a93edfe42ffdeab&period=12month&format=json&limit=200";

+ 16 - 2
page-music.php

@@ -193,13 +193,13 @@ get_header(); ?>
 					</div>
 					<div class="row">
 						<div class="col-sm-4">
-							<h5 class="cm-type"><em>Artists: 3 Month</em></h5>
+							<h5 class="cm-type"><em>Artists: 1 Month</em></h5>
 							<ul class="list-group">
 								<div class="martists"></div>
 							</ul>
 						</div>
 						<div class="col-sm-8">
-							<h5 class="cm-type"><em>Tracks: 3 Month</em></h5>
+							<h5 class="cm-type"><em>Tracks: 1 Month</em></h5>
 							<ul class="list-group">
 								<div class="mtracks"></div>
 							</ul>
@@ -219,6 +219,20 @@ get_header(); ?>
 							</ul>
 						</div>
 					</div>
+					<div class="row">
+						<div class="col-sm-4">
+							<h5 class="cm-type"><em>Artists: 1 Year</em></h5>
+							<ul class="list-group">
+								<div class="artists"></div>
+							</ul>
+						</div>
+						<div class="col-sm-8">
+							<h5 class="cm-type"><em>Tracks: 1 Year</em></h5>
+							<ul class="list-group">
+								<div class="tracks"></div>
+							</ul>
+						</div>
+					</div>
 					
 					<h5 class="cm-type"><em>Top 200 Albums From the Last Year</em></h5>
 					<div class="albums"></div>