summaryrefslogtreecommitdiff
path: root/Sueddeutsche.de.js
blob: 716b4c60c8200fd3334594d51505a1125ad432ef (plain)
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
{
	"translatorID": "2e4ebd19-83ab-4a56-8fa6-bcd52b576470",
	"label": "Sueddeutsche.de",
	"creator": "Martin Meyerhoff",
	"target": "^https?://www\\.sueddeutsche\\.de",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2014-04-03 19:57:18"
}

/*
Sueddeutsche.de 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/>.
*/

/*
This one has the search function on a different host, so I cannot scan the search results. A multiple option, though, is given for the page itself.
Test here:
http://www.sueddeutsche.de/politik
http://www.sueddeutsche.de/thema/Krieg_in_Libyen
http://www.sueddeutsche.de/muenchen

Reference article: http://www.sueddeutsche.de/wissen/embryonale-stammzellen-wo-sind-die-naiven-1.1143034
*/

function detectWeb(doc, url) {
	if (ZU.xpathText(doc, '//h2/strong')) {
		return "newspaperArticle";
	} else if (ZU.xpath(doc, '//div[@id="topthemen" or @class="panoramateaser" \
						or contains(@class,"maincolumn") or contains(@class, "teaser")]\
						//a[starts-with(@class,"entry-title") \
						and starts-with(@href,"http://www.sueddeutsche.de") \
						and not(contains(@href,"/app/"))]').length){
		return "multiple";
	}
}

function scrape(doc, url) {
	//don't parse things like image galleries
	//e.g. http://www.sueddeutsche.de/kultur/thomas-manns-villa-in-los-angeles-weimar-am-pazifik-1.1301388
	if(!ZU.xpathText(doc, '//h2/strong')) return;

	var newItem = new Zotero.Item("newspaperArticle");
	newItem.url = url;

	var title = ZU.xpathText(doc, '//meta[contains(@property, "og:title")]/@content');
	newItem.title = Zotero.Utilities.trim(title.replace(/\s?–\s?/, ": "));

	// Author. This is tricky, the SZ uses the author field for whatever they like.
	// Sometimes, there is no author.
	var author =  ZU.xpathText(doc, '//section[@class="authors"]//span[@class="moreInfo"]/strong')

	// One case i've seen: A full sentence as the "author", with no author in it.
	if (author && author.trim().charAt(author.length - 1) != '.') {
		author = author.replace(/^\s*Von\s|Ein Kommentar von/i, '')
		// For multiple Authors, the SZ uses comma, und and u
						.split(/\s+(?:und|u|,)\s+/);

		for (var i in author) {
			if (author[i].match(/\s/)) { // only names that contain a space!
				newItem.creators.push(ZU.cleanAuthor(author[i], "author"));
			}
		}
	}

	// summary
	newItem.abstractNote = ZU.xpathText(doc, '//meta[contains(@property, "og:description")]/@content');

	// Date
	newItem.date = ZU.xpathText(doc, "//time[@class='timeformat']").replace(/\d{2}:\d{2}/, "");

	// Section
	var section = url.match(/sueddeutsche\.de\/([^\/]+)/);
	newItem.section = ZU.capitalizeTitle(section[1]);

	// Tags
	var tags = ZU.xpathText(doc, '//meta[@name="keywords"]/@content');
	if(tags) {
		tags = tags.split(/\s*,\s+/);
		for (var i=0, n=tags.length; i<n; i++) {
			newItem.tags.push(ZU.trimInternal(tags[i]));
		}
	}

	// Publication
	newItem.publicationTitle = "sueddeutsche.de"
	newItem.ISSN = "0174-4917";
	newItem.language = "de";

	// Attachment. inserting /2.220/ gives us a printable version
	var printurl = url.replace(/(.*\/)(.*$)/, '$12.220/$2');
	newItem.attachments.push( { url:printurl,
								title:newItem.title,
								mimeType:"text/html",
								snapshot:true } );

	newItem.complete()
}

function doWeb(doc, url) {
	if (detectWeb(doc, url) == "multiple") {
		var links = ZU.xpath(doc,
						'//div[@id="topthemen" or @class="panoramateaser" \
						or contains(@class,"maincolumn") or contains(@class, "teaser")]\
						//a[starts-with(@class,"entry-title") \
						and starts-with(@href,"http://www.sueddeutsche.de") \
						and not(contains(@href,"/app/"))]');

		var items = new Object();
		var title;
		for(var i=0, n=links.length; i<n; i++) {
			title = ZU.xpathText(links[i], './node()[not(self::div)]', null, '');
			items[links[i].href] = ZU.trimInternal(title);
		}

		Zotero.selectItems(items, function(items) {
			if(!items) return true;

			var articles = new Array();
			for (var i in items) {
				articles.push(i);
			}
			ZU.processDocuments(articles, scrape);
		});
	} else {
		scrape(doc, url);
	}
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.sueddeutsche.de/politik/verdacht-gegen-hessischen-verfassungsschuetzer-spitzname-kleiner-adolf-1.1190178",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"firstName": "Peter",
						"lastName": "Blechschmidt",
						"creatorType": "author"
					},
					{
						"firstName": "Marc",
						"lastName": "Widmann",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [
					"Café",
					"Internet",
					"Polizei",
					"SZ",
					"Süddeutsche Zeitung",
					"Wohnung"
				],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Verdacht gegen hessischen Verfassungsschützer: Spitzname \"Kleiner Adolf\"",
						"mimeType": "text/html",
						"snapshot": true
					}
				],
				"url": "http://www.sueddeutsche.de/politik/verdacht-gegen-hessischen-verfassungsschuetzer-spitzname-kleiner-adolf-1.1190178",
				"title": "Verdacht gegen hessischen Verfassungsschützer: Spitzname \"Kleiner Adolf\"",
				"abstractNote": "Als die Zwickauer Zelle in einem Kasseler Internet-Café Halit Y. hinrichtet, surft ein hessischer Verfassungsschützer dort im Netz. In seiner Wohnung findet die Polizei später Hinweise auf eine rechtsradikale Gesinnung - doch die Ermittlungen gegen den Mann werden eingestellt. Dabei bleiben viele Fragen offen.",
				"date": "16. November 2011",
				"section": "politik",
				"publicationTitle": "sueddeutsche.de",
				"ISSN": "0174-4917",
				"language": "de",
				"libraryCatalog": "Sueddeutsche.de",
				"shortTitle": "Verdacht gegen hessischen Verfassungsschützer"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.sueddeutsche.de/politik",
		"items": "multiple"
	}
]
/** END TEST CASES **/