summaryrefslogtreecommitdiff
path: root/Eastview.js
blob: af2204d8882ef41706abdbe09f7654347bc6ce2c (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
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
{
	"translatorID": "c59896bc-4beb-43ed-8109-a73a13251828",
	"label": "Eastview",
	"creator": "Sebastian Karcher",
	"target": "^https?://dlib\\.eastview\\.com/(search/(advanced|simple)/|browse/(doc|favorites|issue))",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsb",
	"lastUpdated": "2014-09-01 13:01:04"
}

/*
	***** BEGIN LICENSE BLOCK *****
	
	Copyright © 2014 Sebastian Karcher
	
	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.search("/search/simple/articles?") != -1 || url.indexOf("/search/advanced/articles") != -1 || url.search(/browse\/(favorites|issue)/) != -1) {
		if (ZU.xpath(doc, '//td[contains(@class, "title-cell")]/a').length) return "multiple";
	} else {
		return "newspaperArticle"
	}
}

var typeMap = {
	"Argumenty i fakty": "magazineArticle",
	"Argumenty nedeli": "magazineArticle",
	"Ekonomika i zhizn'": "magazineArticle",
	"Ekspert": "magazineArticle",
	"Izvestiia": "newspaperArticle",
	"Kommersant. Daily": "newspaperArticle",
	"Komsomol'skaia pravda": "newspaperArticle",
	"Kul'tura": "magazineArticle",
	"Literaturnaia gazeta": "magazineArticle",
	"Moscow Times, The": "newspaperArticle",
	"Moskovskaia pravda": "newspaperArticle",
	"Moskovskii komsomolets": "newspaperArticle",
	"New Times, The": "magazineArticle",
	"Nezavisimaia gazeta": "newspaperArticle",
	"Novaia gazeta": "newspaperArticle",
	"Novye izvestiia": "newspaperArticle",
	"Ogonek": "magazineArticle",
	"Pravda": "newspaperArticle",
	"President": "magazineArticle",
	"Profil'": "magazineArticle",
	"RBK Daily": "newspaperArticle",
	"Rossiiskaia gazeta": "newspaperArticle",
	"Rossiiskie vesti": "newspaperArticle",
	"Russkii reporter": "magazineArticle",
	"Sankt-Peterburgskie vedomosti": "newspaperArticle",
	"Slovo": "magazineArticle",
	"Sovetskaia Rossiia": "newspaperArticle",
	"Trud": "newspaperArticle",
	"Vecherniaia Moskva": "newspaperArticle",
	"Vedomosti": "newspaperArticle",
	"Zavtra": "newspaperArticle"
}

function permaLink(URL) {
	var id = URL.match(/id=(\d+)/);
	if (id) return "http://dlib.eastview.com/browse/doc/" + id[1];
	else return URL
}


function scrape(doc, url) {
	Z.debug(url)
	var item = new Zotero.Item("newspaperArticle");
	var publication = ZU.xpathText(doc, '//a[@class="path" and contains(@href, "browse/publication")]');
	item.publication = publication;
	var voliss = ZU.xpathText(doc, '//a[@class="path" and contains(@href, "browse/issue/")]');
	if (voliss) {
		var issue = voliss.match(/No\. (\d+)/);
		if (issue) item.issue = issue[1];
		var volume = voliss.match(/Vol\. (\d+)/);
		if (volume) item.volume = volume[1];
	}
	var database = ZU.xpathText(doc, '//a[@class="path" and contains(@href, "browse/udb")]');
	if (database) item.libraryCatalog = database.replace(/\(.+\)/, "") + "(Eastview)";
	if (doc.getElementById('metatable')) {
		//we have the metadata in a table
		var metatable = doc.getElementById('metatable');
		var title = ZU.xpathText(metatable, './/td[@class="hdr" and contains(text(), "Article Title")]/following-sibling::td[@class="val"]');
		var source = ZU.xpathText(metatable, './/td[@class="hdr" and contains(text(), "Source")]/following-sibling::td[@class="val"]');
		if (source) {
			var date = source.match(/(January|February|March|April|May|Juni|July|August|September|October|November|December)\s+(\d{1,2},\s+)?\d{4}/);
			if (date) item.date = ZU.trimInternal(date[0]);
			var pages = source.match(/page\(s\): (\d+(?:-\d+)?)/);
			if (pages) item.page = pages[1]
		}
		var author = ZU.xpathText(metatable, './/td[@class="hdr" and contains(text(), "Author(s)")]/following-sibling::td[@class="val"]');
		if (author) {
			//Z.debug(author)
			authors = author.trim().split(/\s*,\s*/);
			for (var i=0; i<authors.length; i++) {
				item.creators.push(ZU.cleanAuthor(authors[i], "author"))
			}
		}
		item.place = ZU.xpathText(doc, '//table[@id="metatable"]//td[@class="hdr" and contains(text(), "Place of Publication")]/following-sibling::td');
	} else {
		var title = ZU.xpathText(doc, '//div[@class="change_font"]');
		//the "old" page format. We have very little structure here, doing the best we can.	
		var header = ZU.xpathText(doc, '//tbody/tr/td/ul');
		Z.debug(header);
		var date = header.match(/Date:\s*(\d{2}-\d{2}-\d{2,4})/);
		if (date) item.date = date[1];
	}

	//see if we have a match for item type; default to newspaper otherwise.
	var itemType = typeMap[item.publication];
	if (itemType) item.itemType = itemType;
	item.attachments.push({
		document: doc,
		title: "Eastview Fulltext Snapshot",
		mimeType: "text/html"
	});
	if (title && title == title.toUpperCase()) {
		title = ZU.capitalizeTitle(title, true);
	}
	item.title = title;
	//sometimes items actually don't have a title: use the publication title instead.
	if (!item.title) item.title = item.publication;
	item.complete();

}

/**
* function to scrape directly from the search table. Not used at this point, but leaving in case we'll want to implement it
function scrapeSearch(doc, url) {
	//Z.debug(ZU.xpathText(doc, './td'))
	var dataTags = new Object();
	var newItem = new Zotero.Item("journalArticle");
	
	var title = ZU.xpathText(doc, './td[contains(@class, "title-cell")]/a');
	if (title==title.toUpperCase()){
		title = ZU.capitalizeTitle(title.toLowerCase(), true);
	}
	newItem.title=  title;
	
	var author = ZU.xpathText(doc, './td[contains(@class, "title-cell")]/following-sibling::td[1]');
	if (author){
		//Z.debug(author)
		authors = author.replace(/—/, "").trim().split(/\s*,\s/);
		for (var i in authors){
			if (authors[i]) newItem.creators.push(ZU.cleanAuthor(authors[i], "author"))
		}
	}
	
	newItem.publication = ZU.xpathText(doc, './td[contains(@class, "source-cell")]');
	newItem.date = ZU.xpathText(doc, './td[contains(@class, "source-cell")]/following-sibling::td[1]');
	
	var attachmentLink = ZU.xpathText(doc, './td[contains(@class, "title-cell")]/a/@href');
	if (attachmentLink){
		newItem.attachments.push({url:attachmentLink, title:title, mimeType:"text/html"})
	}
	newItem.complete();
} */


function doWeb(doc, url) {
	var articles = new Array();
	var items = {};
	if (detectWeb(doc, url) == "multiple") {
		var titles = ZU.xpath(doc, '//td[contains(@class, "title-cell")]/a');
		//var number = ZU.xpath(doc, '//td[contains(@class, "check-cell")]/following-sibling::td[1]');
		for (var i = 0; i < titles.length; i++) {
			items[titles[i].href] = titles[i].textContent.trim();
		}
		Zotero.selectItems(items, function(items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				/* For scraping search table 
				var xpath = '//tr[td[text()="' + i + '"]]'
				var node = ZU.xpath(doc, xpath);
				scrapeSearch(node, url); */
				articles.push(permaLink(i))
			}
			ZU.processDocuments(articles, scrape)
		});
	} else {
		if (url.search(/doc\/\d+/) != -1) {
			scrape(doc, url);
		}
		//always scrape from the permalink page, which has extra publication info at the top
		else {
			ZU.processDocuments(permaLink(url), scrape);
		}
	}
}/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://dlib.eastview.com/search/simple/articles?isTranslite=&doajax=1&searchForOriginal=%d0%a3%d0%9a%d0%a0%d0%90%d0%98%d0%9d*%20AND%20(%d0%9f%d0%92%d0%9e%20OR%20%d0%91%d0%a3%d0%9a%20OR%20%d0%97%d0%a0%d0%9a)%20&predefined=0&fromDay=1&fromMonth=0&fromYear=2014&toDay=17&toMonth=6&toYear=2014&dateRangeType=range&rangeType=all&udbIds=1450&_udbIds=on&udbIds=1019&_udbIds=on&udbIds=1310&_udbIds=on&udbIds=870&_udbIds=on&udbIds=2210&_udbIds=on&udbIds=1790&_udbIds=on&udbIds=1670&_udbIds=on&udbIds=1490&_udbIds=on&udbIds=1030&_udbIds=on&udbIds=1710&_udbIds=on&udbIds=1130&_udbIds=on&udbIds=1610&_udbIds=on&udbIds=1590&_udbIds=on&udbIds=690&_udbIds=on&udbIds=1990&_udbIds=on&udbIds=691&_udbIds=on&udbIds=692&_udbIds=on&udbIds=350&_udbIds=on&udbIds=1230&_udbIds=on&udbIds=1&_udbIds=on&udbIds=4&_udbIds=on&udbIds=2190&_udbIds=on&udbIds=1970&_udbIds=on&udbIds=5&_udbIds=on&udbIds=730&_udbIds=on&udbIds=12&_udbIds=on&udbIds=1890&_udbIds=on&udbIds=293&_udbIds=on&udbIds=1950&_udbIds=on&udbIds=270&_udbIds=on&udbIds=890&_udbIds=on&udbIds=6&_udbIds=on&udbIds=390&_udbIds=on&udbIds=1210&_udbIds=on&udbIds=9&_udbIds=on&udbIds=550&_udbIds=on&udbIds=570&_udbIds=on&udbIds=2&_udbIds=on&udbIds=1650&_udbIds=on&udbIds=1830&_udbIds=on&udbIds=8&_udbIds=on&udbIds=491&_udbIds=on&udbIds=292&_udbIds=on&udbIds=490&_udbIds=on&show=1&search=Search",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "http://dlib.eastview.com/browse/doc/2945904",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Eastview Fulltext Snapshot",
						"mimeType": "text/html"
					}
				],
				"publication": "ITAR-TASS  Daily",
				"issue": "9",
				"libraryCatalog": "Russian Central Newspapers (Eastview)",
				"date": "02-11-98",
				"title": "Moscow"
			}
		]
	},
	{
		"type": "web",
		"url": "http://dlib.eastview.com/browse/doc/39272962",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [
					{
						"firstName": "Rostislav",
						"lastName": "Angel'skii'",
						"creatorType": "author"
					},
					{
						"firstName": "Vladimir",
						"lastName": "Korovin",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Eastview Fulltext Snapshot",
						"mimeType": "text/html"
					}
				],
				"publication": "Tekhnika i vooruzhenie",
				"issue": "3",
				"libraryCatalog": "Military & Security Periodicals (Eastview)",
				"date": "March 2014",
				"page": "20-24",
				"place": "Moscow, Russian Federation",
				"title": "Zanitnyi' raketnyi' kompleks S-300F \"Fort\""
			}
		]
	},
	{
		"type": "web",
		"url": "http://dlib.eastview.com/browse/doc/42109039",
		"items": [
			{
				"itemType": "newspaperArticle",
				"creators": [],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [
					{
						"title": "Eastview Fulltext Snapshot",
						"mimeType": "text/html"
					}
				],
				"publication": "Narodnaia gazeta",
				"libraryCatalog": "Baltics, Belarus, Moldova, Ukraine (Eastview)",
				"date": "March 20, 2014",
				"place": "Minsk, Belarus",
				"title": "Narodnaia gazeta"
			}
		]
	}
]
/** END TEST CASES **/