{ "translatorID": "5c6895a1-b6a9-4939-9c65-43f8ae0ef096", "label": "METS", "creator": "Abe Jellinek", "target": "xml", "minVersion": "3.0", "maxVersion": "", "priority": 50, "configOptions": { "dataMode": "xml/dom" }, "inRepository": true, "translatorType": 1, "lastUpdated": "2021-07-13 20:44:34" } /* ***** BEGIN LICENSE BLOCK ***** Copyright © 2021 Abe Jellinek This file is part of Zotero. Zotero is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Zotero is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Zotero. If not, see . ***** END LICENSE BLOCK ***** */ function detectImport() { var line; var i = 0; while ((line = Zotero.read()) !== false) { if (line !== "") { if (line.includes(" 7) { return false; } } } return false; } function doImport() { let xml = Zotero.getXML(); for (let mets of xml.querySelectorAll('mets')) { let attachments = createAttachments(mets); for (let dmd of mets.querySelectorAll('dmdSec')) { let mdWrap = dmd.querySelector('mdWrap'); if (!mdWrap) { Z.debug('No metadata found in METS item. External metadata is not supported.'); } let mdType = mdWrap.getAttribute('MDTYPE'); Z.debug(`Found metadata of type '${mdType}'`); let data = extractData(mdWrap); processData(mdType, data, attachments); } } } function createAttachments(mets) { let attachments = []; for (let file of mets.querySelectorAll('fileSec file')) { if (attachments.length >= 5) { Z.debug('Too many attachments. Something is probably wrong.'); attachments = []; break; } let mimeType = file.getAttribute('MIMETYPE'); let locator = file.querySelector('FLocat[LOCTYPE="URL"]'); let url = locator && locator.getAttribute('xlink:href'); if (mimeType && url) { let title = 'Attachment'; if (mimeType == 'application/pdf') { title = 'PDF'; // full text? often it isn't text! } else if (mimeType.startsWith('audio/')) { title = 'Audio'; } else if (mimeType.startsWith('video/')) { title = 'Video'; } else if (mimeType.startsWith('image/')) { title = 'Image'; } attachments.push({ title, mimeType, url }); } } return attachments; } function extractData(mdWrap) { for (let child of mdWrap.children) { if (child.tagName.endsWith('xmlData')) { Z.debug('Metadata is XML'); return child.innerHTML; } else if (child.tagName.endsWith('binData')) { Z.debug('Metadata is base64 encoded'); return atob(child.innerHTML); } } Z.debug('Metadata is in XML (unwrapped)'); return mdWrap.innerHTML; } function processData(mdType, data, attachments) { switch (mdType) { case 'MARC': // charmingly, we don't get to know what KIND of MARC we're // getting. we could go off of whether it's encoded as // binary, but that isn't really valid according to the // spec. so we'll just try MARCXML, then binary MARC, then // MAB2 for good measure (it's MARC-ish!). callImport( data, [ 'edd87d07-9194-42f8-b2ad-997c4c7deefd', // MARCXML 'a6ee60df-1ddc-4aae-bb25-45e0537be973', // MARC '91acf493-0de7-4473-8b62-89fd141e6c74', // MAB2 ], attachments ); break; case 'MODS': callImport( data, '0e2235e7-babf-413c-9acf-f27cce5f059c', // MODS attachments, item => item.callNumber = '' ); break; case 'OTHER': // this usually indicates some kind of internal metadata that isn't // essential to parse. Z.debug('Skipping \'OTHER\' metadata'); break; case 'EAD': // todo: an EAD translator. does anyone use EAD? // https://www.loc.gov/ead/ default: throw new Error(`Unsupported metadata type: ${mdType}`); } } function callImport(data, translator, attachments, callback) { let trans = Zotero.loadTranslator('import'); trans.setTranslator(translator); trans.setHandler('itemDone', function (_, item) { let numFieldsSet = 0; for (let field of Object.keys(item)) { if (field == 'itemType') continue; if (item[field] && typeof item[field] == 'string') { numFieldsSet++; } } if (numFieldsSet <= 1) { Z.debug(`Skipping item with < 2 fields set: '${item.title}'`); return; } if (attachments) { item.attachments.push(...attachments); } if (item.language == 'zxx') { delete item.language; } if (callback) callback(item); item.complete(); }); trans.setString(data); trans.translate(); } /** BEGIN TEST CASES **/ var testCases = [ { "type": "import", "input": "\n \n \n World Digital Library\n \n \n Library of Congress\n \n \n \n \n \n \n text\n \n Antietam, Maryland. Allan Pinkerton, President Lincoln, and Major General John A. McClernand: Another View\n \n At the outset of the U.S. Civil War, Mathew Brady dispatched a team of photographers to document the conflict. Among them was a Scottish-born immigrant named Alexander Gardner, the photographer who took this photo of Lincoln at Antietam as well as other famous wartime shots. The man to Lincoln's right is Allan Pinkerton, founder of the Pinkerton National Detective Agency, whom Lincoln had as head of a personal security detail during the war. Gardner titled another shot of Pinkerton and his brother William at Antietam “The Secret Service.” Gardner photographed Lincoln on seven separate occasions, the last one on February 5, 1865, only a few weeks before Lincoln’s assassination. In 1866 he published Gardner’s Sketchbook of the War, combining plates and text, commemorating such battles as Fredericksburg, Gettysburg, and Petersburg, but the book was a commercial failure. Photographic historians also have suggested that Gardner staged many of his photos, moving dead bodies and using a regular prop gun to create romanticized pictorial narratives.\n \n 1 negative : glass, wet collodion\n \n \n zxx\n \n \n Gardner, Alexander, 1821-1882\n \n Photographer\n \n \n \n 1862-10-03\n \n \n 1862-10-03\n \n \n \n North America\n United States of America\n Maryland\n Antietam\n \n \n \n Antietam, Battle of, Maryland, 1862\n \n \n Generals\n \n \n Lincoln, Abraham, 1809-1865\n \n \n McClernand, John A. (John Alexander), 1812-1900\n \n \n Military camps\n \n \n Pinkerton, Allan, 1819-1884\n \n \n Presidents\n \n \n Tents\n \n \n United States--History--Civil War, 1861-1865\n \n \n United States. Army\n \n 973\n \n \n http://hdl.loc.gov/loc.pnp/cwpb.04326\n \n \n \n \n http://hdl.loc.gov/loc.wdl/wdl.1\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "items": [ { "itemType": "document", "title": "Antietam, Maryland. Allan Pinkerton, President Lincoln, and Major General John A. McClernand: Another View", "creators": [ { "firstName": "Alexander", "lastName": "Gardner", "creatorType": "author" } ], "date": "1862-10-03", "abstractNote": "At the outset of the U.S. Civil War, Mathew Brady dispatched a team of photographers to document the conflict. Among them was a Scottish-born immigrant named Alexander Gardner, the photographer who took this photo of Lincoln at Antietam as well as other famous wartime shots. The man to Lincoln's right is Allan Pinkerton, founder of the Pinkerton National Detective Agency, whom Lincoln had as head of a personal security detail during the war. Gardner titled another shot of Pinkerton and his brother William at Antietam “The Secret Service.” Gardner photographed Lincoln on seven separate occasions, the last one on February 5, 1865, only a few weeks before Lincoln’s assassination. In 1866 he published Gardner’s Sketchbook of the War, combining plates and text, commemorating such battles as Fredericksburg, Gettysburg, and Petersburg, but the book was a commercial failure. Photographic historians also have suggested that Gardner staged many of his photos, moving dead bodies and using a regular prop gun to create romanticized pictorial narratives.", "attachments": [ { "title": "Image", "mimeType": "image/tiff" }, { "title": "PDF", "mimeType": "application/pdf" } ], "tags": [ { "tag": "Antietam, Battle of, Maryland, 1862" }, { "tag": "Generals" }, { "tag": "Lincoln, Abraham, 1809-1865" }, { "tag": "McClernand, John A. (John Alexander), 1812-1900" }, { "tag": "Military camps" }, { "tag": "Pinkerton, Allan, 1819-1884" }, { "tag": "Presidents" }, { "tag": "Tents" }, { "tag": "United States--History--Civil War, 1861-1865" }, { "tag": "United States. Army" } ], "notes": [], "seeAlso": [] } ] }, { "type": "import", "input": "\n\n \n \n \n \n \n 00000cas 82200000 4500\n BDG20080002497\n BDG\n 20210421075144.0\n 100609d19121917espwr|n |0|||b|spa d\n \n BDG\n glg\n BDG\n rda\n BDG\n \n \n El cruzado\n : semanario tradicionalista\n \n \n Mondoñedo\n [editor non identificado]\n 1912-1917\n \n \n Mondoñedo\n Tip. Mancebo\n 1912-1917\n \n \n v.\n 47 cm\n \n \n Semanal \n \n \n Director: José Polo Folgueira\n \n \n Propietario: Enrique Costas Márquez\n \n \n Redactor: Carolino Costas Márquez\n \n \n Colaboradores: Antonio Noriega Varela e Manuel Amor Meilán.\n \n \n n. 13 (jul. 1912)\n \n \n BDGA20090004351\n Prensa\n Galicia\n \n \n BDGA20180473692\n Costas Márquez, Enrique\n \n \n BDGA20181256447\n Costas Márquez, Carolino\n \n \n BDGA20120008724\n Noriega Varela, Antonio\n 1869-1947\n \n \n BDGA20130018034\n Amor Meilán, Manuel\n 1867-1933\n \n \n BDGA20180698774\n Tipografía Mancebo\n \n \n BDGA20150000309\n España\n Galicia\n Lugo\n Mondoñedo\n \n \n (Día)\n (Mes)\n (Año)\n w\n \n \n image/jpeg\n 1262473\n Portada\n \n \n 13:jul.1912 - 14:sept.1912, 25:oct.1912 - 25:oct.1912, 2:nov.1912 - 7:dic.1912\n \n \n\n \n \n \n \n FID0\n \n \n \n \n \n \n \n \n \n \n
\n
\n \n
\n
\n
\n
\n", "items": [ { "itemType": "book", "title": "El cruzado: semanario tradicionalista", "creators": [ { "firstName": "Enrique", "lastName": "Costas Márquez", "creatorType": "editor" }, { "firstName": "Carolino", "lastName": "Costas Márquez", "creatorType": "editor" }, { "firstName": "Antonio", "lastName": "Noriega Varela", "creatorType": "editor" }, { "firstName": "Manuel", "lastName": "Amor Meilán", "creatorType": "editor" }, { "lastName": "Tipografía Mancebo", "creatorType": "editor", "fieldMode": true } ], "date": "1912", "place": "Mondoñedo", "publisher": "editor non identificado", "attachments": [ { "title": "Image", "mimeType": "image/jpeg" } ], "tags": [ { "tag": "Galicia" }, { "tag": "Prensa" } ], "notes": [ { "note": "Director: José Polo Folgueira Propietario: Enrique Costas Márquez Redactor: Carolino Costas Márquez Colaboradores: Antonio Noriega Varela e Manuel Amor Meilán" } ], "seeAlso": [] } ] }, { "type": "import", "input": "\n\nAntiquitates_und_ArchaeologiaAntiquitates_und_Archaeologia_ARCHAEO18PPN143342827PPN143342819Vite De' Pittori, Scultori Ed Architetti NapoletaniNon mai date alla luce da Autore alcuno ...itNeapel1742RicciardidomiviteautDominiciBernardoDominici, BernardoDigitalisierungszentrum der Niedersächsischen Staats- und Universitätsbibliothek Göttingenhttp://gdz.sub.uni-goettingen.de/logo_gdz_dfgv.pnghttp://gdz.sub.uni-goettingen.dehttp://opac.sub.uni-goettingen.de/DB=1/PPN?PPN=143342827http://resolver.sub.uni-goettingen.de/purl?PPN143342827\n", "items": [ { "itemType": "document", "title": "Vite De' Pittori, Scultori Ed Architetti Napoletani: Non mai date alla luce da Autore alcuno ...", "creators": [ { "firstName": "Bernardo", "lastName": "Dominici", "creatorType": "author" } ], "date": "1742", "language": "it", "publisher": "Ricciardi", "attachments": [], "tags": [ { "tag": "domivite" } ], "notes": [], "seeAlso": [] } ] }, { "type": "import", "input": "\n\nAntiquitates_und_ArchaeologiaAntiquitates_und_Archaeologia_ARCHAEO18PPN137363532PPN137363540PPN137363540Accurata, E Succinta Descrizione Topografica Delle Antichitá Di Roma1laRoma1763Bernabò, e LazzariniautVenutiRidolfinoVenuti, Ridolfino[1] Bl., XXXVI, 143, [1] S., 59 Bl., [1] gef. Bl.Clemens Papa XIII. Ad futuram rei memoriam.Avvertimento Al Lettore.Indice De' Capi Della Parte Prima.Approvazione.Introduzione Alla Topografia Di Roma.Carta Topografica Delle Antichità Di Roma [...]Capo Primo Del Monte Palatino.[Taf.] 1 [- Taf.] 14Capo Primo Del Monte Palatino.Capo Secondo Del Foro Romano.[Taf.] 15 [- Taf.] 16Capo Terzo Del Campidoglio.[Taf.] 17 [- Taf.] 22Capo Quarto Fori di Cesare, d'Augusto, di Nerva, e di Trajano.[Taf.] 23 [-Taf.] 25Capo Quinto Del Colle Quirinale.[Taf.] 26 [- Taf.] 33Capo Sesto Monte Viminale.Capo Settimo. Colle Esquilino.[Taf.] 34 [- Taf.] 55Capo Ottavo Del Monte Celio.[Taf.] 56 [- Taf.] 594 ARCH I, 3892:1Digitalisierungszentrum der Niedersächsischen Staats- und Universitätsbibliothek Göttingenhttp://gdz.sub.uni-goettingen.de/logo_gdz_dfgv.pnghttp://gdz.sub.uni-goettingen.dehttp://opac.sub.uni-goettingen.de/DB=1/PPN?PPN=137363532http://resolver.sub.uni-goettingen.de/purl?PPN137363540\n", "items": [ { "itemType": "bookSection", "title": "Accurata, E Succinta Descrizione Topografica Delle Antichitá Di Roma", "creators": [ { "firstName": "Ridolfino", "lastName": "Venuti", "creatorType": "author" } ], "date": "1763", "language": "la", "place": "Roma", "publisher": "Bernabò, e Lazzarini", "attachments": [], "tags": [], "notes": [], "seeAlso": [] } ] } ] /** END TEST CASES **/