2008-09-11 04:40:07 +00:00
|
|
|
{
|
2011-03-19 23:54:56 +00:00
|
|
|
"translatorID": "d3b1d34c-f8a1-43bb-9dd6-27aa6403b217",
|
|
|
|
"label": "YouTube",
|
|
|
|
"creator": "Sean Takats and Michael Berkowitz and Matt Burton",
|
|
|
|
"target": "https?://[^/]*youtube\\.com\\/",
|
|
|
|
"minVersion": "1.0.0rc4",
|
|
|
|
"maxVersion": "",
|
|
|
|
"priority": 100,
|
|
|
|
"inRepository": "1",
|
|
|
|
"translatorType": 4,
|
|
|
|
"lastUpdated": "2011-03-20 03:10:43"
|
2008-09-11 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function detectWeb(doc, url){
|
|
|
|
var namespace = doc.documentElement.namespaceURI;
|
|
|
|
var nsResolver = namespace ? function(prefix) {
|
|
|
|
if (prefix == 'x') return namespace; else return null;
|
|
|
|
} : null;
|
2009-02-21 23:37:33 +00:00
|
|
|
|
|
|
|
|
2011-03-19 23:54:56 +00:00
|
|
|
/*var xpath = '//input[@type="hidden" and @name="video_id"]';
|
2008-09-11 04:40:07 +00:00
|
|
|
if(doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()) {
|
|
|
|
return "videoRecording";
|
2011-03-19 23:54:56 +00:00
|
|
|
}*/
|
|
|
|
if (url.match(/\/watch\?(?:.*)v=([0-9a-zA-Z]+)/)) {
|
|
|
|
return "videoRecording";
|
2008-09-11 04:40:07 +00:00
|
|
|
}
|
2009-02-21 23:37:33 +00:00
|
|
|
//Search results
|
2011-03-19 23:54:56 +00:00
|
|
|
if (doc.evaluate('//div[@class="result-item-main-content"]//a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()){
|
2008-09-11 04:40:07 +00:00
|
|
|
return "multiple";
|
|
|
|
}
|
2009-02-21 23:37:33 +00:00
|
|
|
//playlists
|
|
|
|
if (doc.evaluate('//div[starts-with(@class, "title")]/a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()){
|
2008-09-11 04:40:07 +00:00
|
|
|
return "multiple";
|
|
|
|
}
|
2009-02-21 23:37:33 +00:00
|
|
|
// still used?
|
2008-09-11 04:40:07 +00:00
|
|
|
if (doc.evaluate('//div[@class="vltitle"]/div[@class="vlshortTitle"]/a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()){
|
|
|
|
return "multiple";
|
|
|
|
}
|
2009-02-21 23:37:33 +00:00
|
|
|
|
2008-09-11 04:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function doWeb(doc, url){
|
|
|
|
var namespace = doc.documentElement.namespaceURI;
|
|
|
|
var nsResolver = namespace ? function(prefix) {
|
|
|
|
if (prefix == 'x') return namespace; else return null;
|
|
|
|
} : null;
|
|
|
|
var host = doc.location.host;
|
|
|
|
var video_ids = new Array();
|
2011-03-19 23:54:56 +00:00
|
|
|
var elmt, video_id;
|
|
|
|
var videoRe = /\/watch\?(?:.*)v=([0-9a-zA-Z_-]+)/;
|
|
|
|
if(video_id = videoRe.exec(url)) {
|
2008-09-11 04:40:07 +00:00
|
|
|
//single video
|
2011-03-19 23:54:56 +00:00
|
|
|
video_ids.push(video_id[1]);
|
2008-09-11 04:40:07 +00:00
|
|
|
} else {
|
|
|
|
// multiple videos
|
|
|
|
var items = new Object();
|
2009-02-21 23:37:33 +00:00
|
|
|
// search results and community/user pages
|
2011-03-19 23:54:56 +00:00
|
|
|
if (elmt = doc.evaluate('//div[@class="result-item-main-content"]//a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()){
|
|
|
|
elmts = doc.evaluate('//div[@class="result-item-main-content"]//a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null);
|
2009-02-21 23:37:33 +00:00
|
|
|
}
|
|
|
|
// playlists
|
|
|
|
else if (doc.evaluate('//div[starts-with(@class, "title")]/a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()){
|
|
|
|
elmts = doc.evaluate('//div[starts-with(@class, "title")]/a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null);
|
|
|
|
}
|
|
|
|
// still used?
|
|
|
|
else if (doc.evaluate('//div[@class="vltitle"]/div[@class="vlshortTitle"]/a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext()){
|
2008-09-11 04:40:07 +00:00
|
|
|
elmts = doc.evaluate('//div[@class="vltitle"]/div[@class="vlshortTitle"]/a[contains(@href, "/watch?v=")]', doc, nsResolver, XPathResult.ANY_TYPE, null);
|
|
|
|
}
|
|
|
|
while (elmt = elmts.iterateNext()){
|
|
|
|
var title = elmt.textContent;
|
|
|
|
title = Zotero.Utilities.trimInternal(title);
|
|
|
|
var link = elmt.href;
|
2011-03-19 23:54:56 +00:00
|
|
|
Zotero.debug(link);
|
2008-09-11 04:40:07 +00:00
|
|
|
var m = videoRe(link);
|
|
|
|
var video_id = m[1];
|
|
|
|
items[video_id] = title;
|
|
|
|
}
|
|
|
|
items = Zotero.selectItems(items);
|
|
|
|
if(!items) return true;
|
|
|
|
for(var i in items) {
|
|
|
|
video_ids.push(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getData(video_ids, host);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getData(ids, host){
|
|
|
|
var uris = new Array();
|
|
|
|
var url = "http://gdata.youtube.com/feeds/videos/";
|
|
|
|
for each(var id in ids){
|
|
|
|
uris.push(url+id);
|
|
|
|
}
|
|
|
|
Zotero.Utilities.HTTP.doGet(uris, function(text) {
|
2009-08-04 04:36:42 +00:00
|
|
|
// Strip XML header
|
2008-09-11 04:40:07 +00:00
|
|
|
text = text.replace(/<\?xml[^>]*\?>/, "");
|
2009-08-04 04:36:42 +00:00
|
|
|
|
|
|
|
default xml namespace = "http://www.w3.org/2005/Atom"; with({});
|
|
|
|
var mediaNS = new Namespace("http://search.yahoo.com/mrss/");
|
|
|
|
var ytNS = new Namespace("http://gdata.youtube.com/schemas/2007");
|
|
|
|
|
2008-09-11 04:40:07 +00:00
|
|
|
// pad xml
|
|
|
|
text = "<zotero>"+text+"</zotero>";
|
|
|
|
var xml = new XML(text);
|
|
|
|
var newItem = new Zotero.Item("videoRecording");
|
|
|
|
var title = "";
|
2009-08-04 04:36:42 +00:00
|
|
|
var title = xml..mediaNS::title[0].text().toString();
|
|
|
|
if (xml..mediaNS::title.length()){
|
|
|
|
var title = Zotero.Utilities.trimInternal(xml..mediaNS::title[0].text().toString());
|
2008-09-11 04:40:07 +00:00
|
|
|
if (title == ""){
|
|
|
|
title = " ";
|
|
|
|
}
|
|
|
|
newItem.title = title;
|
|
|
|
}
|
2009-08-04 04:36:42 +00:00
|
|
|
if (xml..mediaNS::keywords.length()){
|
|
|
|
var keywords = xml..mediaNS::keywords[0].text().toString();
|
2008-09-11 04:40:07 +00:00
|
|
|
keywords = keywords.split(",");
|
|
|
|
for each(var tag in keywords){
|
|
|
|
newItem.tags.push(Zotero.Utilities.trimInternal(tag));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xml..published.length()){
|
|
|
|
var date = xml..published[0].text().toString();
|
|
|
|
newItem.date = date.substr(0, 10);
|
|
|
|
}
|
|
|
|
if (xml..author.name.length()){
|
|
|
|
var author = xml..author.name[0].text().toString();
|
2009-08-04 04:36:42 +00:00
|
|
|
var creator = Zotero.Utilities.cleanAuthor(author, "contributor", true);
|
|
|
|
if (!creator.firstName) {
|
|
|
|
creator.fieldMode = 1;
|
|
|
|
}
|
|
|
|
newItem.creators.push(creator);
|
2008-09-11 04:40:07 +00:00
|
|
|
}
|
2009-08-04 04:36:42 +00:00
|
|
|
if (xml..mediaNS::player.length()){
|
|
|
|
var url = xml..mediaNS::player[0].@url.toString();
|
2008-09-11 04:40:07 +00:00
|
|
|
newItem.url = url;
|
|
|
|
}
|
2009-08-04 04:36:42 +00:00
|
|
|
if (xml..ytNS::duration.length()){
|
|
|
|
var runningTime = xml..ytNS::duration[0].@seconds.toString();
|
2008-09-11 04:40:07 +00:00
|
|
|
newItem.runningTime = runningTime + " seconds";
|
|
|
|
}
|
2009-08-04 04:36:42 +00:00
|
|
|
if (xml..mediaNS::description.length()){
|
|
|
|
newItem.abstractNote = xml..mediaNS::description[0].text().toString();
|
2008-09-11 04:40:07 +00:00
|
|
|
}
|
2009-02-21 23:37:33 +00:00
|
|
|
/*
|
2008-10-29 15:33:55 +00:00
|
|
|
//temporary fix for downloads using techcrunch
|
|
|
|
var techcrunchurl = "http://www.techcrunch.com/ytdownload3.php?url="+encodeURIComponent(newItem.url)+"&submit=Get+Video";
|
2009-02-21 23:37:33 +00:00
|
|
|
Zotero.debug(techcrunchurl);
|
2008-10-29 15:33:55 +00:00
|
|
|
Zotero.Utilities.HTTP.doGet(techcrunchurl, function(text) {
|
|
|
|
var flv = text.match(/HREF='([^']+)'/);
|
|
|
|
if (flv[1]){
|
|
|
|
flv = flv[1];
|
|
|
|
// title parameter needs to be encoded
|
|
|
|
var title = flv.match(/&title=([^&]+)/);
|
|
|
|
if (title[1]){
|
|
|
|
title = encodeURIComponent(title[1]);
|
|
|
|
flv = flv.replace(/&title=([^&]+)/, title);
|
|
|
|
}
|
|
|
|
newItem.attachments.push({url:flv, title:"YouTube Video Recording", mimeType:"video/x-flv"});
|
|
|
|
}
|
2008-09-11 04:40:07 +00:00
|
|
|
newItem.complete();
|
2009-01-08 08:28:59 +00:00
|
|
|
}, function() {Zotero.done();});
|
2009-02-21 23:37:33 +00:00
|
|
|
*/
|
|
|
|
newItem.complete();
|
|
|
|
Zotero.done();
|
2008-09-11 04:40:07 +00:00
|
|
|
});
|
|
|
|
Zotero.wait();
|
2011-03-19 23:54:56 +00:00
|
|
|
}
|