Last active
August 12, 2016 10:48
-
-
Save iUltimateLP/f991ee06e21f7585eb70d062250d90c1 to your computer and use it in GitHub Desktop.
A simple script to get Album Artwork from iTunes and put it inside the TeamSpeak avatar (using Sinusbot).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registerPlugin | |
( | |
{ | |
name: 'iTunes Cover Art', | |
version: '1.0', | |
description: 'Download Cover Art from the iTunes API!', | |
author: 'Johnny Verbeek (iUltimateLP) <[email protected]>', | |
vars: { | |
desired_album_size: | |
{ | |
title: "The desired size for the downloaded album cover.", | |
type: "number" | |
} | |
} | |
}, | |
function(sinusbot, config) | |
{ | |
sinusbot.on('trackEnd', function(ev){ | |
sinusbot.setDefaultAvatar(); | |
}); | |
sinusbot.on('track', function(ev) | |
{ | |
if (ev.title != '' && ev.artist != '' && (ev.type == '' || ev.type == 'file')) | |
{ | |
if (!ev.thumbnail) | |
{ | |
sinusbot.log('Requesting cover art from iTunes for ' + ev.artist + ' - ' + ev.title); | |
var httpres = sinusbot.http( | |
{ | |
method: 'GET', | |
url: 'http://itunes.apple.com/search?entity=musicTrack&term="' + encodeURIComponent(ev.artist) + '+' + encodeURIComponent(ev.title) + '"' | |
}, | |
function(err, res) | |
{ | |
if (httpres) | |
{ | |
var jsonres = JSON.parse(res.data); | |
sinusbot.log("Got " + jsonres.resultCount + " results from iTunes!"); | |
if (jsonres.resultCount != 0) | |
{ | |
var size = config.desired_album_size.toString(); | |
var result = sinusbot.downloadTrackThumbnail(ev.uuid, jsonres.results[0].artworkUrl100.replace(new RegExp("100x100"), size + "x" + size)); | |
if (result) | |
{ | |
sinusbot.setAvatarFromTrack(); | |
sinusbot.log('Successfully updated thumbnail!'); | |
} | |
else | |
{ | |
sinusbot.setDefaultAvatar(); | |
sinusbot.log('Failed updating thumbnail!'); | |
} | |
} | |
} | |
else | |
{ | |
sinusbot.setDefaultAvatar(); | |
sinusbot.log("An thumbnail is already there, setting it to the current avatar."); | |
} | |
} | |
); | |
} | |
else | |
{ | |
sinusbot.setAvatarFromTrack(); | |
} | |
} | |
}); | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment