-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathVictoria & Albert Museum.js
277 lines (251 loc) · 7.58 KB
/
Victoria & Albert Museum.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
{
"translatorID": "56fc13bf-411f-4409-9a61-3d334d76763b",
"label": "Victoria & Albert Museum",
"creator": "Richard Palmer - V&A Digital Media & Publishing",
"target": "^https?://collections\\.vam\\.ac\\.uk",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2022-04-29 19:15:08"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2022 V&A Museum
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 <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, url) {
if (url.includes("/item/")) {
return "artwork";
}
else if (url.includes("/search/") && getRecords(doc).length) {
return "multiple";
}
return false;
}
function scrape(doc, url) {
var id = url.match(/item\/(O[0-9]+)/i)[1];
var apiUrl = "https://api.vam.ac.uk/v2/museumobject/" + id;
Zotero.Utilities.doGet(apiUrl, function (respText) {
var museumobject = JSON.parse(respText);
var data = museumobject.record;
var item = new Zotero.Item("artwork");
if (data.titles.length > 0) {
item.title = data.titles[0].title;
item.shortTitle = data.objectType;
}
else if (data.objectType) {
item.title = data.objectType;
item.shortTitle = data.objectType;
}
item.abstractNote = data.briefDescription;
item.medium = data.materialsAndTechniques;
item.artworkSize = data.dimensionsNote;
if (data.productionDates.length > 1) {
item.date = data.productionDates[0].date.text;
}
else if (data.productionDates.length > 0) {
item.date = data.productionDates[0].date.text;
}
let collection = text(doc, 'a[href*="/search/?id_collection="]')
|| data.collectionCode.text;
item.archive = `Victoria & Albert Museum ${collection}`;
item.libraryCatalog = 'Victoria & Albert Museum';
item.callNumber = data.accessionNumber;
item.rights = data.creditLine;
item.url = url;
var artistMakerPerson = data.artistMakerPerson;
for (var i = 0; i < artistMakerPerson.length; i++) {
// This is not ideal and assume surname, firstnames convention is correct
var fullName = artistMakerPerson[i].name.text;
var lastComma = fullName.lastIndexOf(",");
var firstName = "";
var lastName = "";
if (lastComma > 0) {
lastName = fullName.substring(0, lastComma);
firstName = fullName.substring(lastComma + 1);
}
else {
firstName = fullName;
}
firstName = firstName
.replace('(Senior)', 'Sr.')
.replace('(Junior)', 'Jr.');
item.creators.push({
lastName: lastName,
firstName: firstName,
creatorType: "author"
});
}
var artistMakerPeople = data.artistMakerPeople;
for (var j = 0; j < artistMakerPeople.length; j++) {
item.creators.push({
lastName: artistMakerPeople[j].name.text,
fieldMode: 1,
creatorType: "author"
});
}
var artistMakerOrganisations = data.artistMakerOrganisations;
for (var k = 0; k < artistMakerOrganisations.length; k++) {
item.creators.push({
lastName: artistMakerOrganisations[k].name.text,
fieldMode: 1,
creatorType: "author"
});
}
item.attachments.push({
document: doc,
title: "Snapshot"
});
item.complete();
});
}
function getRecords(doc) {
return ZU.xpath(doc, '//figure[contains(@class, "b-object-card--etc")]//a');
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
var artworks = {};
var items = getRecords(doc);
for (var item in items) {
var title = ZU.xpathText(items[item], './/div[@class="b-object-card__caption"]');
var href = items[item].href;
artworks[href] = title;
}
Zotero.selectItems(artworks, function (artworks) {
if (artworks) ZU.processDocuments(Object.keys(artworks), scrape);
});
}
else {
scrape(doc, url);
}
return false;
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://collections.vam.ac.uk/item/O4293/ripple-pattern-vase-imperial-glass-co/",
"items": [
{
"itemType": "artwork",
"title": "'Ripple' pattern",
"creators": [
{
"lastName": "Imperial Glass Co.",
"fieldMode": 1,
"creatorType": "author"
}
],
"date": "ca. 1914",
"abstractNote": "Vase of glass, made by Imperial Glass Company, Ohio, c. 1914-25",
"archive": "Victoria & Albert Museum Ceramics Collection",
"artworkMedium": "Press moulded glass, heated",
"callNumber": "C.32-1992",
"libraryCatalog": "Victoria & Albert Museum",
"rights": "Given by Raymond and Michel Lerpiniere",
"shortTitle": "Vase",
"url": "https://collections.vam.ac.uk/item/O4293/ripple-pattern-vase-imperial-glass-co/",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://collections.vam.ac.uk/item/O19135/graphic-permutations-four-cubes-barton-glenys/",
"items": [
{
"itemType": "artwork",
"title": "Graphic Permutations",
"creators": [
{
"lastName": "Barton",
"firstName": " Glenys",
"creatorType": "author"
}
],
"date": "1971",
"abstractNote": "E, SP, BARTON GLENYS, 20",
"archive": "Victoria & Albert Museum Ceramics Collection",
"artworkMedium": "Bone china, slip-cast, with silk-screened decoration",
"callNumber": "CIRC.277 to C-1973",
"libraryCatalog": "Victoria & Albert Museum",
"shortTitle": "Four cubes",
"url": "https://collections.vam.ac.uk/item/O19135/graphic-permutations-four-cubes-barton-glenys/",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://collections.vam.ac.uk/item/O11451/the-garrick-bed-bed-chippendale-thomas-senior/",
"items": [
{
"itemType": "artwork",
"title": "The Garrick Bed",
"creators": [
{
"lastName": "Chippendale",
"firstName": " Thomas Sr.",
"creatorType": "author"
}
],
"date": "ca. 1775",
"abstractNote": "A bed of softwood, with fluted foot columns, painted white and green. The tester is edged with carved lappets painted in green and white. The current hangings of screen printed cotton date from 2001.",
"archive": "Victoria & Albert Museum Furniture and Woodwork Collection",
"artworkMedium": "Japanned (painted) beech and pine, with 20th century reproduction hangings.",
"artworkSize": "The bed has been reduced in width.",
"callNumber": "W.70-1916",
"libraryCatalog": "Victoria & Albert Museum",
"rights": "Given by H. E. Trevor, a direct descendant of David Garrick's brother, George",
"shortTitle": "Bed",
"url": "https://collections.vam.ac.uk/item/O11451/the-garrick-bed-bed-chippendale-thomas-senior/",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://collections.vam.ac.uk/search/?q=beach&year_made_from=&year_made_to=",
"defer": true,
"items": "multiple"
}
]
/** END TEST CASES **/