This repository has been archived by the owner on Jan 3, 2020. It is now read-only.
forked from zotero/translators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpiegel Online.js
353 lines (326 loc) · 11.4 KB
/
Spiegel Online.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
{
"translatorID": "eef50507-c756-4081-86fd-700ae4ebf22e",
"label": "Spiegel Online",
"creator": "Martin Meyerhoff",
"target": "^https?://www\\.spiegel\\.de/",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2015-03-06 09:02:26"
}
/*
Spiegel Online Translator
Copyright (C) 2011 Martin Meyerhoff
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Test with the following URLs:
http://www.spiegel.de/suche/index.html?suchbegriff=AKW
http://www.spiegel.de/international/search/index.html?suchbegriff=Crisis
http://www.spiegel.de/international/topic/german_french_relations/
http://www.spiegel.de/international/europe/0,1518,700530,00.html
*/
function detectWeb(doc, url) {
var spiegel_article_XPath = '//h2[@class="article-title"]';
if ( url.indexOf('/thema/')>-1 || url.indexOf('/suche/')>-1 || url.indexOf('/international/search/')>-1 || url.indexOf('/international/topic/')>-1 ) {
return "multiple";
} else if (ZU.xpathText(doc, spiegel_article_XPath)) {
//the print edition is a magazine. Since the online edition is updated constantly it
//makes sense to treat it like a newspaper.
if (url.indexOf('/print/')>-1) {
return "magazineArticle";
} else {
return "newspaperArticle";
}
}
}
function scrape(doc, url) {
var newItem = new Zotero.Item(detectWeb(doc, url));
newItem.url = url;
// This is for the title
newItem.title = ZU.xpathText(doc, '//h2[@class="article-title"]')
|| ZU.xpathText(doc, '//meta[@property="og:title"]/@content')
|| ZU.xpathText(doc, '//title');
newItem.title = ZU.trimInternal(newItem.title);
// Tags
var tags = ZU.xpathText(doc, '//meta[contains(@name, "keywords")][1]/@content');
if (tags) {
// The first 5 Tags are generic or section info. TODO check if that is anymore true
newItem.tags = tags.trim().split(/(?:\s*,\s*)+/).slice(5);
}
// Author
var author = ZU.xpathText(doc, '//p[contains(@class, "author")]') // Most of the time, the author has its own tag. Easy Case, really.
|| ZU.xpathText(doc, '//span[contains(@class, "author")]')
|| ZU.xpathText(doc, '//*[@id="spIntroTeaser"]/strong/i'); // Sometimes, though, the author is in italics in the teaser.
if (author) {
author = author.replace(/^\s*By\s|^\s*Von\s/, '');
author = author.replace(/^\s*Ein.+? von\s|\s*$/, '');//e.g "Ein Kommentar von Peter Müller, Leipzig"
author = author.replace(/^\s*Aus.+?berichtet\s*/, "");
author = author.replace(/^\s*Interview (Conducted )?by /, '');// e.g. Interview Conducted by Klaus Brinkbäumer
// Spiegel Online and the Spiegel Archive have different formatting for the author line
var formatSpiegelArchive = url.indexOf('http://www.spiegel.de/spiegel/')>-1;
if (formatSpiegelArchive) {
//e.g. Von Neubacher, Alexander; Neumann, Conny; Winter, Steffen
author = author.split(/\sund\s|\su\.\s|\;\s|\sand\s/);
} else {
//e.g. By Jörg Diehl, Hubert Gude, Barbara Schmid and Fidelius Schmid
author = author.replace(/,\s\S*$/, ''); //e.g "Ein Kommentar von Peter Müller, Leipzig"
author = author.replace(/\sin\s\S*(,\s\S*)?$/g, ""); //e.g. "By Susanne Beyer in Kaliningrad, Russia"
author = author.split(/\sund\s|\su\.\s|\,\s|\sand\s/);
}
for (var i in author) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(author[i], "author", author[i].indexOf(',')>-1));
}
}
// Section
newItem.section = ZU.xpathText(doc, '//a[@class="channel-name"]');
// attachement
if (url.match(/^http\:\/\/www\.spiegel\.de\/spiegel/)){
var printurl_xPath = ".//div[contains(@class, 'article-function-box')]/ul/li[1]/a/@href";
var printurl = ZU.xpathText(doc, printurl_xPath);
//Zotero.debug(printurl);
newItem.attachments.push({url:printurl, title:"Full Text PDF", mimeType:"application/pdf"});
} else {
// Attachment. Difficult. They want something inserted into the URL.
var printurl = url;
printurl = printurl.replace(/(\d+\,\d+\.html.*$)/, 'druck-$1'); //done!
newItem.attachments.push({url:printurl, title:"Snapshot", mimeType:"text/html"});
}
// Ausgabe/Volume für Print
if (ZU.xpathText(doc, '//div[@class="spiegel-magazin-title asset-title"]') && newItem.itemType == "magazineArticle"){
newItem.volume = ZU.xpathText(doc, '//div[@class="spiegel-magazin-title asset-title"]').match(/(\d+)\/\d{4}/)[1];
}
// Summary
var summary = ZU.xpathText(doc, './/p[@class="article-intro"]')
if (summary) {
newItem.abstractNote = summary.trim();
}
// Date
var date = ZU.xpathText(doc, './/h5[contains(@id, "ShortDate")]')
|| ZU.xpathText(doc, '//meta[@name="date"]/@content')
|| ZU.xpathText(doc, '//div[@id="spShortDate"]');
if (date) {
date = date.replace(/(\d\d)\/(\d\d)\/(\d\d\d\d)/, "$3-$1-$2");
date = date.replace(/(\d\d)\.(\d\d)\.(\d\d\d\d)/, "$3-$2-$1");
date = date.replace(/T.+/,""); // e.g. date = "2014-10-20T12:10:00+0200"
newItem.date = date.trim();
}
// publicationTitle
if (url.indexOf('http://www.spiegel.de/spiegel')>-1) {
newItem.publicationTitle = "Der Spiegel";
} else {
newItem.publicationTitle = "Spiegel Online";
}
newItem.complete()
}
function doWeb(doc, url) {
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
if (url.match(/^https?\:\/\/www\.spiegel\.de\/(suche|international\/search)/)){
var titles = doc.evaluate(".//div[@class='search-teaser']/a", doc, null, XPathResult.ANY_TYPE, null);
} else if (url.match(/^https?\:\/\/www\.spiegel\.de\/(thema\/|international\/topic)/)){
var titles = doc.evaluate(".//div[contains(@class, 'teaser')]/h2/a", doc, null, XPathResult.ANY_TYPE, null);
}
var next_title;
while (next_title = titles.iterateNext()) {
//The search searches also manager-magazin.de, which won't work
if (next_title.textContent != "mehr..." && next_title.href.match(/^https?:\/\/www\.spiegel\.de\//) ) {
items[next_title.href] = Zotero.Utilities.trim(next_title.textContent);
}
}
Zotero.selectItems(items, function(items) {
if(!items) return true;
var articles = new Array();
for (var i in items) {
articles.push(i);
}
Zotero.Utilities.processDocuments(articles, scrape);
});
} else {
scrape(doc, url);
}
}
/** BEGIN TEST CASES **/
var testCases = [
{
"type": "web",
"url": "http://www.spiegel.de/politik/deutschland/cdu-parteitag-partei-im-koma-a-797954.html",
"items": [
{
"itemType": "newspaperArticle",
"title": "CDU-Parteitag: Partei im Koma",
"creators": [
{
"firstName": "Peter",
"lastName": "Müller",
"creatorType": "author"
}
],
"date": "2011-11-15",
"abstractNote": "Die CDU feiert sich in Leipzig selbst, doch in Wahrheit befindet sie sich in einem traurigen Zustand: Die Partei ist in ein kollektives Koma gefallen, politische Debatten finden kaum noch statt. Hauptverantwortlich dafür ist Angela Merkel.",
"libraryCatalog": "Spiegel Online",
"publicationTitle": "Spiegel Online",
"section": "Politik",
"shortTitle": "CDU-Parteitag",
"url": "http://www.spiegel.de/politik/deutschland/cdu-parteitag-partei-im-koma-a-797954.html",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
"Betreuungsgeld",
"Eurokrise",
"Mindestlohn"
],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://www.spiegel.de/international/topic/german_french_relations/",
"items": "multiple"
},
{
"type": "web",
"url": "http://www.spiegel.de/suche/index.html?suchbegriff=AKW",
"items": "multiple"
},
{
"type": "web",
"url": "http://www.spiegel.de/international/search/index.html?suchbegriff=Crisis",
"items": "multiple"
},
{
"type": "web",
"url": "http://www.spiegel.de/spiegel/print/d-84789653.html",
"items": [
{
"itemType": "magazineArticle",
"title": "WIRTSCHAFTSPOLITIK VEB Energiewende",
"creators": [
{
"firstName": "Alexander",
"lastName": "Neubacher",
"creatorType": "author"
},
{
"firstName": "Conny",
"lastName": "Neumann",
"creatorType": "author"
},
{
"firstName": "Steffen",
"lastName": "Winter",
"creatorType": "author"
}
],
"date": "2012-04-07",
"libraryCatalog": "Spiegel Online",
"publicationTitle": "Der Spiegel",
"url": "http://www.spiegel.de/spiegel/print/d-84789653.html",
"volume": "15",
"attachments": [
{
"title": "Full Text PDF",
"mimeType": "application/pdf"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://www.spiegel.de/thema/atomkraftwerke/",
"items": "multiple"
},
{
"type": "web",
"url": "http://www.spiegel.de/international/europe/madame-non-and-monsieur-duracell-german-french-relations-on-the-rocks-a-700530.html",
"items": [
{
"itemType": "newspaperArticle",
"title": "Madame Non and Monsieur Duracell: German-French Relations On the Rocks",
"creators": [],
"date": "2010-06-14",
"abstractNote": "For decades, the German-French relationship has been the most important one in the European Union. These days, however, Chancellor Angela Merkel and President Nicolas Sarkozy can hardly stand each other. Why can't they just get along?",
"libraryCatalog": "Spiegel Online",
"publicationTitle": "Spiegel Online",
"section": "International",
"shortTitle": "Madame Non and Monsieur Duracell",
"url": "http://www.spiegel.de/international/europe/madame-non-and-monsieur-duracell-german-french-relations-on-the-rocks-a-700530.html",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [],
"notes": [],
"seeAlso": []
}
]
},
{
"type": "web",
"url": "http://www.spiegel.de/einestages/kinder-vom-kamper-see-grab-unter-wasser-a-1021273.html",
"items": [
{
"itemType": "newspaperArticle",
"title": "Kinder vom Kamper See Das Grab im Wasser",
"creators": [
{
"firstName": "Matthias",
"lastName": "Kneip",
"creatorType": "author"
}
],
"date": "2015-03-03",
"abstractNote": "Am 5. März 1945 stürzte ein Flugzeug in den Kamper See. An Bord: fast 80 deutsche Kinder auf der Flucht vor der Roten Armee. Eine Initiative will nun ihre Leichen vom Grund des Sees bergen.\n\t\t\t\t\t\t\tVon Matthias Kneip",
"libraryCatalog": "Spiegel Online",
"publicationTitle": "Spiegel Online",
"section": "einestages",
"url": "http://www.spiegel.de/einestages/kinder-vom-kamper-see-grab-unter-wasser-a-1021273.html",
"attachments": [
{
"title": "Snapshot",
"mimeType": "text/html"
}
],
"tags": [
"Flucht",
"Flucht und Vertreibung",
"Flugzeugabsturz",
"Flugzeugunglücke",
"Kamper See",
"Kinder",
"Kriegsende",
"Zweiter Weltkrieg",
"]1945",
"einestages"
],
"notes": [],
"seeAlso": []
}
]
}
]
/** END TEST CASES **/