-
-
Save dhou/53950 to your computer and use it in GitHub Desktop.
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
/* | |
* Looks for imdb id using keywords, then use the imdb id to search mininova. | |
* e.g. imdbt Matrix of t -> select from up to 5 movie suggestions to search for seeds on imdb | |
*/ | |
const ITEMS_TMPL = "<div style=\"clear: both;\"><b><u><a href=\"${link}\">${title} (${year} ${imdb})</a></u></b><br/>" + | |
"<img src=\"${img}\" style=\"float: left; height: 80px; background-color: white;\" />" + | |
"</div><br/>"; | |
var $j = jQuery; | |
var log = CmdUtils.log; | |
var store = Application.storage; | |
const IMDB_IDS = 'ubiquity_imdb_ids'; | |
function getImdbItems () { | |
return store.get(IMDB_IDS, []); | |
} | |
function getImdbItem (id) { | |
var items = getImdbItems(); | |
for (var i=0; i < items.length; i++) { | |
var item = items[i]; | |
if (item.imdbId == id) { | |
return item; | |
}; | |
}; | |
} | |
var noun_imdb_id = { | |
_name: "IMDB ID", | |
item_list: null, | |
suggest: function(text, html){ | |
if (text.length < 1) return []; | |
this.item_list = getImdbItems(); | |
var suggs = []; | |
for (var i=0; i < this.item_list.length; i++) { | |
if(text){ | |
if(this.item_list[i].imdbId.match(text, "i")) | |
suggs.push(CmdUtils.makeSugg(this.item_list[i].imdbId)); | |
}else{ | |
suggs.push(CmdUtils.makeSugg(this.item_list[i].imdbId)); | |
} | |
}; | |
return suggs.splice(0,5); | |
} | |
} | |
CmdUtils.CreateCommand({ | |
names: ["imdbt","mininova-imdb"], | |
icon: "http://static.mininova.org/images/favicon.ico", | |
homepage: "http://damienh.org/category/geek-stuff/ubiquity-geek-stuff/", | |
author: { | |
name: "Damien Hou", | |
email: "[email protected]" | |
}, | |
license: "GPL", | |
description: "Use keywords to accurately search for imdb movies on mininova", | |
help: "imdbt movie keywords (with imdbid like tt12345678)", | |
arguments: [{role:'object', nountype:noun_arb_text, label:'movie title'}, | |
{role:'modifier', nountype:noun_imdb_id, label:'with'}], | |
_getImdbId: function(q){ | |
}, | |
preview: function(pblock, args) { | |
var q = args.object.text; | |
if (args.modifier.text) { | |
var item = getImdbItem(args.modifier.text); | |
if(item){ | |
pblock.innerHTML = CmdUtils.renderTemplate(ITEMS_TMPL, { | |
link: item.link, | |
title: item.title, | |
img: item.img, | |
imdb: item.imdbId, | |
year: item.year | |
}); | |
return; | |
} | |
var url = 'http://api.douban.com/movie/subject/imdb/'+args.modifier.text; | |
var params = {}; | |
}else{ | |
var url = 'http://api.douban.com/movie/subjects?apikey=06ed1564b5b0aef014c7402e21120cd0&start-index=1&max-results=5'; | |
var params = { | |
'q': q | |
}; | |
} | |
CmdUtils.previewGet(pblock, | |
url, | |
params, | |
function(data) { | |
pblock.innerHTML = ""; | |
var title = $j('entry title', data).text(); | |
if (title) { | |
var entries = $j('entry', data); | |
var items = []; | |
for (var i = 0; i < entries.length; i++) { | |
var entry = entries[i]; | |
var item = {}; | |
var imdb = $j('db\\\:attribute[name="imdb"]', entry).text(); | |
item.imdbId = imdb.substring(26, imdb.length-1); | |
item.link = $j('link[rel="alternate"]', entry).attr('href'); | |
item.title = $j('title', entry).text(); | |
item.img = $j('link[rel="image"]', entry).attr('href'); | |
item.year = $j('db\\\:attribute[name="pubdate"]', entry).text(); | |
items.push(item); | |
pblock.innerHTML += CmdUtils.renderTemplate(ITEMS_TMPL, { | |
link: item.link, | |
title: item.title, | |
img: item.img, | |
imdb: item.imdbId, | |
year: item.year | |
}); | |
}; | |
store.set(IMDB_IDS, items); | |
} | |
}, | |
"xml" | |
); | |
}, | |
execute: function(args) { | |
h='http://www.mininova.org'; | |
if (args.modifier.text) { | |
var imdbid = args.modifier.text.slice(2); | |
var url = 'http://www.mininova.org/imdb/'+imdbid+'/seeds'; | |
}else{ | |
var url = 'http://www.mininova.org/search/'+encodeURIComponent(args.object.text)+'/4/seeds'; | |
var imdbid = ''; | |
} | |
Utils.openUrlInBrowser(url,null); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment