LastFM Scrobbling Notifications
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 - 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."); });
})();
Developer | Hawcubite |
Username | hawcubite |
Uploaded | December 12, 2022 |
Rating | 3 |
Size | 4,280 Kb |
Views | 22,264 |
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!
Name | Size |
Radial Image Preview | 3,233 Kb |
DFF Website | 10,123 Kb |
Full CSS Resizing Tiles | 3,043 Kb |
Gooey cube | 3,292 Kb |
Transitional Hover-Boxes | 1,872 Kb |
Organic responsive rounded container | 1,710 Kb |
A Pen by hawcubite | 2,261 Kb |
Table scroll shadows | 3,691 Kb |
Vue.js Tutorial | 3,460 Kb |
Testing 3D text in CSS | 5,079 Kb |
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!
Name | Username | Size |
Web Spiral - p5.js | TWAIN | 2,183 Kb |
CSS3 Form Page Design | Rssatnam | 3,613 Kb |
Border image | JohnRiordan | 2,120 Kb |
Project MMetro beta | Atomicsong | 5,157 Kb |
Responsive Pricing Table | Jeremycaris | 2,690 Kb |
A Pen by Ben Babics | Benbabics | 2,957 Kb |
Freecodecamp - Tribute Page | Samoht513 | 3,583 Kb |
Mobile first social buttons with no iframe | Alistairtweedie | 3,158 Kb |
SCSS Simple Animated Drop-In | Danwarfel | 2,175 Kb |
Countdown with Rings | Ewganoel | 2,490 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!