LastFM Scrobbling Notifications

Developer
Size
4,280 Kb
Views
22,264

How do I make an lastfm scrobbling notifications?

What is a lastfm scrobbling notifications? How do you make a lastfm scrobbling notifications? This script and codes were developed by Hawcubite on 12 December 2022, Monday.

LastFM Scrobbling Notifications Previews

LastFM Scrobbling Notifications - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>LastFM Scrobbling Notifications</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Experimental LastFM Scrobbling Notifications</h1> <main class="wrapper"> <p>Keeps you updated about a users currently playing tracks.</p> <p>User: <input id="user" name="user" autofocus/><button id="start">GO!</button><button id="stop">STOP</button></p> <p>Activated: <span id="activated">No</span></p> <p>Currently playing: <span id="playing"></span></p> <hr> <footer> <p> <a href="https://www.last.fm/" target="_blank"><small>powered by AudioScrobbler</small><br/><img src="http://cdn.last.fm/flatness/badges/lastfm_red_small.gif"></a> </p> <p> <em>Something to say? Tell me: <a href="https://twitter.com/hawcubites" target="_blank">@hawcubites</a></em> </p> </footer> </main> <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

LastFM Scrobbling Notifications - Script Codes CSS Codes

@font-face { font-family: 'Vampiro One'; font-style: normal; font-weight: 400; src: local('Vampiro One'), local('VampiroOne-Regular'), url(https://fonts.gstatic.com/s/vampiroone/v7/Ho2Xld8UbQyBA8XLxF1_NYbN6UDyHWBl620a-IRfuBk.woff) format('woff');
}
* { box-sizing: border-box; }
body { margin: 0; padding: 0; background: lavender; background: linear-gradient(to bottom right, #00eaff, #c600ff) fixed; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
h1 { min-width: 600px; padding: 0 20px; margin: 60px 0; text-align: center; color: white; font-family: "Vampiro One","Lato","Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif; font-size: 4rem; font-weight: 300; text-shadow: 0 0 20px rgba(0,0,0,.5);
}
.wrapper { width: 600px; margin: 40px auto; padding: 30px; background: white; border-radius: 8px; box-shadow: 0 0 80px rgba(0,0,0,.2);
}
.wrapper > p:first-child { margin-top: 0;
}
.wrapper > p:last-child { margin-bottom: 0;
}
footer { margin-top: 40px; text-align: center;
}
hr { border: 0px solid; border-top: 1px solid #000;
}
a { color: #000;
}
input { padding: 4px; border: 1px solid #000; border-radius: 2px;
}
button { margin: 0 0 0 4px; padding: 4px; border: none; border-radius: 3px; background: #000; color: #fff;
}

LastFM Scrobbling Notifications - Script Codes JS Codes

(function() { var api = api || {}; var lastTrack; var user = ""; var t; var apiError = false; var callFrequency = 40000; api.lastfm = {}; api.lastfm.key = "dbd3952ba8ebd71b443038c829babdc3"; api.lastfm.url = "http://ws.audioscrobbler.com/2.0/"; /** * Send an API call to last.fm * @param {String} method The method name (e.g. "library.getartists") * @param {Array} options An array of tuples (arrays with two elements) with options for the request: ["key", "value"] * @param {Function} callback The callback function to call with the data returned from the request. Takes two arguments, error and data (callback(error, data)) */ api.lastfm.send = function(method, options, callback) { var url = api.lastfm.url + "?" + "method=" + method + "&api_key=" + api.lastfm.key + "&format=json"; var xhr, gotResponse; options.forEach(function(el) { url += "&" + el[0] + "=" + (el[1] + "") .replace("&", "%26") .replace("/", "%2F") .replace("+", "%2B") .replace("\\", "%5C"); }); xhr = $.getJSON(url, function(e, d) { gotResponse = true; callback(e, d); }).fail(function( jqxhr, textStatus, error ) { apiError = true; console.log("Request Failed: " + textStatus + ", " + error); }); setTimeout(function() { if (!gotResponse) { xhr.abort(); if(t) { clearInterval(t); } $("#activated").html(" Error. Response timed out."); callback("ERROR", { error: "Response timed out." }); } }, callFrequency); return xhr; } ///////// /* Notification API */ function notifyMe(title, data) { //console.log(data); // Let's check if the browser supports notifications if (!("Notification" in window)) { console.log("This browser does not support desktop notifications."); } // Let's check whether notification permissions have alredy been granted else if (Notification.permission === "granted") { // If it's okay let's create a notification var notification = new Notification(title, data); } // Otherwise, we need to ask the user for permission else if (Notification.permission !== 'denied') { Notification.requestPermission(function (permission) { // If the user accepts, let's create a notification if (permission === "granted") { var notification = new Notification(title, data); } }); } } /* Call LastFM API and push notification */ function useData(rawData) { if(rawData !== "ERROR" && typeof rawData.error === "undefined" && typeof rawData.recenttracks.track[0] !== "undefined") { // If there's an error in the request or the response we don't try to search for tracks data, also if the user never scrobbled var trackAttr = rawData.recenttracks.track[0]['@attr']; if((typeof trackAttr != "undefined") && (trackAttr.nowplaying === "true")) { var trackName = rawData.recenttracks.track[0].name; var artist = rawData.recenttracks.track[0].artist["\#text"]; var album = rawData.recenttracks.track[0].album["\#text"]; var image = rawData.recenttracks.track[0].image[1]["\#text"]; var title = trackName; var data = {icon : image, body : artist + " - " + album}; //if(output != lastTrack) { notifyMe(title, data); lastTrack = title; $("#playing").html(title); //} $("#activated").html("Yes"); } else { $("#activated").html("Yes, but there's nothing playing."); } } else if(rawData.recenttracks && typeof rawData.recenttracks.track[0] === "undefined") { $("#activated").html("No, user doesn't scrobble at all."); clearInterval(t); } else if(typeof rawData.error !== "undefined") { switch(rawData.error) { case 6: $("#activated").html("No, user not found."); clearInterval(t); return; default: if(rawData.error !== "undefined") { console.log(rawData); $("#activated").html("No, unhandled error: " + rawData.message); } else { $("#activated").html("No, unknown error."); } clearInterval(t); } } } function callLastfm(user) { if(!apiError) { api.lastfm.send("user.getRecentTracks", [["user", user], ["limit", 1]], function(responseData, error) { useData(responseData); }); } } function startObserving() { if(t) { clearInterval(t); } user = $("#user").val(); if(!apiError) { if(user !== "") { $("#activated").html(" Please wait..."); t = setInterval(function() { callLastfm(user); },callFrequency); callLastfm(user); } else { if(t != undefined && t != null) { clearInterval(t); } $("#activated").html("No, please insert user name."); $("#playing").html(""); } } else { $("#activated").html("No, API initialization error."); } return false; } $("#user").keypress(function(e) { if (e.which == 13) { startObserving(); } }); $("#start").click(function() { startObserving(); }); $("#stop").click(function() { clearInterval(t); $("#activated").html("No, manually stopped."); });
})();
LastFM Scrobbling Notifications - Script Codes
LastFM Scrobbling Notifications - Script Codes
Home Page Home
Developer Hawcubite
Username hawcubite
Uploaded December 12, 2022
Rating 3
Size 4,280 Kb
Views 22,264
Do you need developer help for LastFM Scrobbling Notifications?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Hawcubite (hawcubite) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!