Skip to content

Instantly share code, notes, and snippets.

@iUltimateLP
Last active August 12, 2016 10:48
Show Gist options
  • Save iUltimateLP/f991ee06e21f7585eb70d062250d90c1 to your computer and use it in GitHub Desktop.
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).
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