Skip to content

Instantly share code, notes, and snippets.

@onejgordon onejgordon/x
Created Feb 26, 2009

Embed
What would you like to do?
Lookup lyrics through lyrics.astraweb.com
var noun_type_song_lookup = {
_name: "song",
suggest: function suggest( text, html, callback ) {
var url = "http://search.lyrics.astraweb.com/";
var suggestions = [CmdUtils.makeSugg(text)];
jQuery.get(url, {word: text}, function(data) {
results = jQuery(data).find("b > a");
for ( i = 0; i < results.length && i < 9; i++ ) {
result = results.get(i);
callback(CmdUtils.makeSugg(result.text,result.text,result.href));
}
})
return [];
}
}
var lyric_url = "http://lyrics.astraweb.com";
CmdUtils.CreateCommand( {
name: "lyric",
takes: { song: noun_type_song_lookup },
homepage: "http://www.jeremyrgordon.com/2009/02/lyric-search-for-ubiquity.html",
author: { name: "Jeremy Gordon", email: "onejgordon@gmail.com"},
description: "Lookup lyrics through lyrics.astraweb.com",
help: "Search by artist and song title. Lyrics will show up in preview, run command to see full page on astraweb.",
preview: function( pblock, song) {
song_name = jQuery.trim(song.text);
if (song_name.length<1) { pblock.innerHTML = "Please enter a song and/or artist to find lyrics." } else {
CmdUtils.previewGet(pblock,lyric_url+song.data,null,function(data) {
lyric_data = jQuery(data).find("font[size='2']").eq(1).html();
artist = jQuery(data).find("b:contains('Artist:')").parent().next().html();
var template = "<u><b>${song}</b> by <b>${artist}</b></u><br> <div style=\"min-height:50px;max-height: 350px;overflow-y: auto; width:400px;\"><font size=1>${output}</font></div>";
pblock.innerHTML = CmdUtils.renderTemplate(template, {"song": song_name, "artist": artist, "output": lyric_data});
})
}
},
execute: function goto( song ) {
if (song) {
Utils.focusUrlInBrowser(lyric_url + song.data);
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.