-
Notifications
You must be signed in to change notification settings - Fork 786
/
Copy pathKanopy.js
358 lines (342 loc) · 9.89 KB
/
Kanopy.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
{
"translatorID": "595f70a0-9f64-459c-a4b1-658c8193bf7f",
"label": "Kanopy",
"creator": "Abe Jellinek",
"target": "^https?://[^/]+\\.kanopy\\.com/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2021-08-16 23:36:22"
}
/*
***** 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 <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
function detectWeb(doc, url) {
if (url.includes('/video/')) {
return "film";
}
return false;
}
function doWeb(doc, url) {
scrape(doc, url);
}
function scrape(doc, url) {
let item = new Zotero.Item('film');
item.title = ZU.trimInternal(text(doc, 'h1.title').trim().replace(/\s*\n/, ':'));
item.abstractNote = text(doc, '#video-panel-details p');
item.distributor = text(doc, '.author a');
item.url = attr(doc, 'link[rel="canonical"]', 'href') || url;
for (let elem = doc.querySelector('.features > *'); elem; elem = elem.nextElementSibling) {
let key = elem.textContent.trim();
let value = (elem = elem.nextElementSibling).textContent.trim();
switch (key) {
case 'Running Time':
item.runningTime = value;
break;
case 'Year':
item.date = value;
break;
case 'Filmmakers':
for (let person of elem.querySelectorAll('a')) {
item.creators.push(ZU.cleanAuthor(person.textContent, 'director'));
}
break;
case 'Features':
for (let person of elem.querySelectorAll('a')) {
item.creators.push(ZU.cleanAuthor(person.textContent, 'contributor'));
}
break;
case 'Languages':
item.language = value;
break;
case 'Subjects':
for (let subj of elem.querySelectorAll('.item')) {
let tag = subj.textContent.replace(/\s*>\s*/g, '--').trim();
if (tag != 'Staff Picks') {
item.tags.push({ tag });
}
}
break;
}
}
item.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "https://berkeley.kanopy.com/video/metropolis-0",
"items": [
{
"itemType": "film",
"title": "Metropolis",
"creators": [
{
"firstName": "Fritz",
"lastName": "Lang",
"creatorType": "director"
}
],
"date": "1927",
"abstractNote": "Perhaps the most famous and influential of all silent films, METROPOLIS had for 75 years been seen only in shortened or truncated versions. Now, restored in Germany with state-of-the-art digital technology, under the supervision of the Murnau Foundation, and with the original 1927 orchestral score by Gottfried Huppertz added, METROPOLIS can be appreciated in its full glory.",
"distributor": "Kino Lorber",
"language": "German, Silent",
"libraryCatalog": "Kanopy",
"runningTime": "149 mins",
"url": "https://berkeley.kanopy.com/video/metropolis-0",
"attachments": [],
"tags": [
{
"tag": "Global Studies & Languages--German Studies"
},
{
"tag": "Movies"
},
{
"tag": "Movies--Early Film"
},
{
"tag": "Movies--Science Fiction & Fantasy"
},
{
"tag": "The Arts--Film Studies"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://berkeley.kanopy.com/video/modern-times",
"items": [
{
"itemType": "film",
"title": "Modern Times",
"creators": [
{
"firstName": "Charlie",
"lastName": "Chaplin",
"creatorType": "director"
},
{
"firstName": "Charlie",
"lastName": "Chaplin",
"creatorType": "contributor"
},
{
"firstName": "Henry",
"lastName": "Bergman",
"creatorType": "contributor"
},
{
"firstName": "Paulette",
"lastName": "Goddard",
"creatorType": "contributor"
}
],
"date": "1936",
"abstractNote": "Charlie Chaplin's last outing as the Little Tramp puts the iconic character to work as a giddily inept factory employee who becomes smitten with a gorgeous gamine (Paulette Goddard).",
"distributor": "The Criterion Collection",
"language": "English, Silent",
"libraryCatalog": "Kanopy",
"runningTime": "88 mins",
"url": "https://berkeley.kanopy.com/video/modern-times",
"attachments": [],
"tags": [
{
"tag": "Movies"
},
{
"tag": "Movies--Classic Cinema"
},
{
"tag": "Movies--Comedy"
},
{
"tag": "Movies--Early Film"
},
{
"tag": "The Arts--Film Studies"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://berkeley.kanopy.com/video/hard-days-night",
"items": [
{
"itemType": "film",
"title": "A Hard Day's Night",
"creators": [
{
"firstName": "Richard",
"lastName": "Lester",
"creatorType": "director"
},
{
"firstName": "George",
"lastName": "Harrison",
"creatorType": "contributor"
},
{
"firstName": "John",
"lastName": "Lennon",
"creatorType": "contributor"
},
{
"firstName": "Paul",
"lastName": "McCartney",
"creatorType": "contributor"
},
{
"firstName": "Ringo",
"lastName": "Starr",
"creatorType": "contributor"
}
],
"date": "1964",
"abstractNote": "Meet the Beatles! Just one month after they exploded onto the U.S. scene with their Ed Sullivan Show appearance, John, Paul, George, and Ringo began working on a project that would bring their revolutionary talent to the big screen, earning them a 1965 BAFTA nomination for Most Promising Newcomer to Leading Film Roles.",
"distributor": "The Criterion Collection",
"language": "English",
"libraryCatalog": "Kanopy",
"runningTime": "89 mins",
"url": "https://berkeley.kanopy.com/video/hard-days-night",
"attachments": [],
"tags": [
{
"tag": "Global Studies & Languages--European/Baltic Studies"
},
{
"tag": "Movies"
},
{
"tag": "Movies--Classic Cinema"
},
{
"tag": "Movies--Comedy"
},
{
"tag": "The Arts--Music"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://berkeley.kanopy.com/video/black-panthers-0",
"items": [
{
"itemType": "film",
"title": "The Black Panthers: Vanguard of the Revolution",
"creators": [
{
"firstName": "Stanley",
"lastName": "Nelson",
"creatorType": "director"
}
],
"date": "2015",
"abstractNote": "In the turbulent 1960s, change was coming to America and the fault lines could no longer be ignored -- cities were burning, Vietnam was exploding, and disputes raged over equality and civil rights. A new revolutionary culture was emerging and it sought to drastically transform the system. The Black Panther Party for Self-Defense would, for a short time, put itself at the vanguard of that change. The Black Panthers: Vanguard of the Revolution is the first feature-length documentary to explore the Black Panther Party, its significance to the broader American culture, its cultural and political awakening for black people, and the painful lessons wrought when a movement derails. Master documentarian Stanley Nelson goes straight to the source, weaving a treasure trove of rare archival footage with the diverse group of voices of the people who were there: police, FBI informants, journalists, white supporters and detractors, and Black Panthers who remained loyal to the party and those who left it.",
"distributor": "PBS",
"language": "English",
"libraryCatalog": "Kanopy",
"runningTime": "115 mins",
"shortTitle": "The Black Panthers",
"url": "https://berkeley.kanopy.com/video/black-panthers-0",
"attachments": [],
"tags": [
{
"tag": "Documentaries"
},
{
"tag": "Documentaries--Ethnicity & Identity"
},
{
"tag": "Documentaries--Historical Perspectives"
},
{
"tag": "Movies--TV Series"
},
{
"tag": "Social Sciences--History - Modern"
},
{
"tag": "Social Sciences--Race & Class Studies"
},
{
"tag": "Social Sciences--Sociology"
}
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "https://berkeley.kanopy.com/video/berlin-symphony-great-city",
"items": [
{
"itemType": "film",
"title": "Berlin, Symphony of a Great City",
"creators": [
{
"firstName": "Walter",
"lastName": "Ruttmann",
"creatorType": "director"
}
],
"date": "1927",
"abstractNote": "At once an invaluable photographic record of life in Weimar Berlin and a timeless demonstration of the cinema's ability to enthrall on a purely visceral level, Berlin, Symphony of a Great City (Berlin, die Symphonie der Grosstadt) offers a kaleidoscopic view of a single day in the life of a bustling metropolis.",
"distributor": "Flicker Alley",
"language": "English, Silent",
"libraryCatalog": "Kanopy",
"runningTime": "63 mins",
"url": "https://berkeley.kanopy.com/video/berlin-symphony-great-city",
"attachments": [],
"tags": [
{
"tag": "Global Studies & Languages--German Studies"
},
{
"tag": "Movies--Early Film"
},
{
"tag": "The Arts"
},
{
"tag": "The Arts--Film Studies"
}
],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/