Created
August 20, 2009 09:53
-
-
Save ba3r/170941 to your computer and use it in GitHub Desktop.
songza song artist album search
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" | |
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> | |
<head> | |
<title>Songza Search</title> | |
</head> | |
<body> | |
<div id="ubiquity-preview" style="display: none;"> | |
<style> | |
.gresult img { | |
width: 16px; | |
height: 16px; | |
margin-right: 5px; | |
} | |
</style> | |
{for result in results} | |
<div class="gresult"> | |
<div> | |
<img src="${result.icon}" /><a href="${result.url}">${result.name}</a> | |
</div> | |
<div class="gresult-url">Source: ${result.source}</div> | |
</div> | |
{forelse} | |
<b>Your search - ${searchTerm} - did not match any documents. </b> | |
{/for} | |
</div> | |
<script class="commands"><![CDATA[ | |
CmdUtils.CreateCommand({ | |
names: ["songza"], | |
url: "http://songza.com", | |
icon: "http://songza.com/favicon.ico", | |
description: "Songza is the easiest way to search for, stream and share any song. For free.", | |
help: "Type the text of the song or song that you would like to find.", | |
author: { name: "Scott Robbin", email: "[email protected]"}, | |
license: "GPL", | |
homepage: "http://songza.com", | |
arguments: [{role: 'object', nountype: noun_arb_text, label: "band or song name"}], | |
preview: function( pblock, args ) { | |
var searchTerm = args.object.text; | |
// Only attempt to fetch search results if the user has entered a query | |
if(searchTerm.length < 1) { | |
pblock.innerHTML = "Search Songza for any song or band."; | |
return; | |
} else { | |
pblock.innerHTML = "Searching Songza for <strong>" + searchTerm + "</strong>..."; | |
} | |
// Create the search URL | |
var url = this.url + "/api/v1.1/search/{%q}"; | |
url = url.replace("{%q}", searchTerm); | |
CmdUtils.previewGet( pblock, url, {}, function(data) { | |
var numToDisplay = 7; | |
var itemCount = 0; | |
var results = []; | |
jQuery.each(data, function(i, val) { | |
// Does this qualify as a search result? | |
var song = new Object; | |
song.name = val.title; | |
song.url = val.url; | |
// Is this a YouTube or Imeem song? | |
if( (val.id).substring(0,4) == "a2r3" ) | |
song.source = "YouTube"; | |
else | |
song.source = "Imeem"; | |
if( itemCount++ >= numToDisplay) { | |
return false; | |
} | |
results[song.name] = song; | |
}); | |
pblock.innerHTML = CmdUtils.renderTemplate( jQuery("#ubiquity-preview", feed.dom).html(), | |
{results:results, searchTerm:searchTerm}); | |
}, "json"); | |
}, | |
execute: function(args) { | |
var query = (args.object.text).replace(/ /g, '+'); | |
var url = this.url + "/search/" + query; | |
Utils.openUrlInBrowser(url); | |
} | |
}); | |
]]></script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment