Last active
December 30, 2021 19:21
-
-
Save ignamv/6406714 to your computer and use it in GitHub Desktop.
Zotero translator for libgen.org
This file contains 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
{ | |
"translatorID": "d1b38d36-6bcc-4828-969f-b08a2a2e0723", | |
"label": "Libgen", | |
"creator": "Ignacio Martinez V.", | |
"target": "libgen\\.org|gen\\.lib\\.rus\\.ec", | |
"minVersion": "1.0", | |
"maxVersion": "", | |
"priority": 100, | |
"inRepository": true, | |
"translatorType": 4, | |
"browserSupport": "g", | |
"lastUpdated": "2013-09-02 08:11:27" | |
} | |
function detectWeb(doc, url) { | |
if(url.indexOf('search.php') != -1) { | |
return 'multiple'; | |
} | |
} | |
var orig_url; | |
function doWeb(doc, url) { | |
var articles = new Array(); | |
orig_url = url; | |
var items = ZU.getItemArray(doc, doc, '/book/index.php') | |
Zotero.selectItems(items, function(items) { | |
if (!items) { | |
Zotero.done(); | |
return true; | |
} | |
for (var i in items) { | |
articles.push(i); | |
} | |
Zotero.Utilities.doGet(articles, bookCallback, | |
function () { Zotero.done();}); | |
}); | |
} | |
function bookAttr(book, attr) { | |
var tags = book.getElementsByTagName(attr); | |
if(tags.length == 0) { | |
return ""; | |
} | |
return tags[0].textContent; | |
} | |
var association = { | |
'language': 'language', | |
'title': 'title', | |
'ISBN': 'isbn', | |
'series': 'series', | |
'edition': 'edition', | |
'place': 'city', | |
'date': 'year', | |
'numPages': 'pages', | |
'volume': 'volume', | |
'abstractNote': 'descr'}; | |
function bookCallback(text, foo, url) { | |
var doc; | |
try { | |
var parser = new DOMParser(); | |
doc = parser.parseFromString(text, 'text/xml'); | |
} catch(e) { | |
Zotero.debug('Parsing exception ' + e); | |
return; | |
} | |
if(doc.documentElement.nodeName == 'parsererror' ) { | |
Zotero.debug('Error parsing ' + text ); | |
return; | |
} | |
var bookTag = doc.getElementsByTagName('book')[0]; | |
var newBook = new Zotero.Item('book'); | |
for(var attr in association) { | |
newBook[attr] = ZU.xpathText(bookTag, association[attr]); | |
} | |
newBook.attachments = [{ | |
title: 'Library Genesis download links', | |
url: orig_url.replace(/\\?.*/,'?req='+ | |
ZU.xpathText(bookTag, '/md5hash')+'&column[]=md5'), | |
snapshot: false | |
}]; | |
newBook.creators = [] | |
// The Authors field goes like | |
// editor1, editor2 (editors), author1, author2 (authors) | |
var authors = ZU.xpathText(bookTag, 'authors').split(/,/); | |
var type = 'author'; | |
for(var ii=authors.length-1; ii != -1; ii--) { | |
if(authors[ii].match(/\(.*auth.*\)/i)) | |
type = 'author'; | |
else if(authors[ii].match(/\(.*ed.*\)/i)) | |
type = 'editor'; | |
newBook.creators.splice(0,0,Zotero.Utilities.cleanAuthor( | |
authors[ii].replace(/\(.*\)/,''), type)); | |
} | |
newBook.complete(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a more up-to-date translator: zotero/translators#1056