summaryrefslogtreecommitdiff
path: root/Schweizer Radio und Fernsehen SRF.js
blob: 187c0e2bba8e8b58a0d07e6ac7f4c43f181ed325 (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
{
	"translatorID": "a8e51f4e-0372-42ad-81a8-bc3dcea6dc03",
	"label": "Schweizer Radio und Fernsehen SRF",
	"creator": "ibex, Sebastian Karcher",
	"target": "^https?://(www\\.)?srf\\.ch/.",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2013-02-25 21:02:50"
}

/*
	DRS Translator - Parses Schweizer Radio DRS articles and creates Zotero-based
	metadata.
	Copyright (C) 2011 ibex, 2012 Sebastian Karcher

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

/*
Barebones re-write. This will work for radio shows, but nothing else & no search results. Shouldn't be too hard to add more.
*/

/* Zotero API */
function detectWeb(doc, url) {
	if (doc.location.href.match(/.*\/sendungen\/.*/i) && (ZU.xpath(doc, '//h1[@class="article-heading"]').length > 0)) {
		return "radioBroadcast";
	// Archive pages
	} else if (doc.location.href.match(/.*\/sendungen\/.*/i) && ZU.xpath(doc, '//div[contains(@class, "container_episodes")]').length > 0) {
		return "multiple";
	}
}

/* Zotero API */
function doWeb(doc, url) {
	// Z.debug("ibex doWeb URL = " + url);
	var urls = new Array();
	if (detectWeb(doc, url) == "multiple") {
		var items = {}
	var titles = ZU.xpath(doc, '//div[@class="module-content"]/h3/a');
	for (var i in titles){
		items[titles[i].href] = titles[i].textContent.trim();	
	}
	Zotero.selectItems(items, function (items) {
			if (!items) {
				return true;
			}
			for (var i in items) {
				urls.push(i);
			}
			Zotero.Utilities.processDocuments(urls, scrape);
		});
	} else {
		scrape(doc,url)
	}
}

/* Zotero API */
function scrape(doc) {
	// Z.debug("ibex scrape URL = " + doc.location.href);

	// Fetch meta tags and fill meta tag array for associateMeta() function
	var newItem = new Z.Item('radioBroadcast');
	newItem.url = doc.location.href;

	newItem.title = ZU.xpathText(doc, '//h1[@class="article-heading"]');
	
	var date = ZU.xpathText(doc, '//li[@class="publication"]');
	if (date) newItem.date = date.match(/^[^,]+,([^,]+),.+/)[1]


	newItem.language = 'de-CH';
	newItem.programTitle = ZU.xpathText(doc, '//header//h1/img/@alt')
	newItem.network = "Schweizer Radio und Fernsehen SRF";
	newItem.abstractNote = ZU.xpathText(doc, '//p[contains(@class, "lead-text")]');
	

	var runningTime = ZU.xpath(doc, '//div[@id = "article"]//a[@class = "beitrag_hoeren"]');
	if (runningTime.length > 0) {
		newItem.runningTime = ZU.trimInternal(runningTime[0].textContent.match(/(\d|:)+/)[0]);
	}

	var authors = ZU.xpath(doc, '//p[@class = "author"]/span');
	for (var i = 0; i < authors.length; i++) {
		var author = authors[i].textContent;
		// Remove prefix
		newItem.creators.push(ZU.cleanAuthor(author, "author"));
	}

	newItem.complete();
}
/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "http://www.srf.ch/sendungen/echo-der-zeit/micheline-calmy-rey-zu-ihrem-ruecktritt",
		"items": [
			{
				"itemType": "radioBroadcast",
				"creators": [
					{
						"firstName": "Ursula",
						"lastName": "Hürzeler",
						"creatorType": "author"
					},
					{
						"firstName": "Markus",
						"lastName": "Mugglin",
						"creatorType": "author"
					}
				],
				"notes": [],
				"tags": [],
				"seeAlso": [],
				"attachments": [],
				"url": "http://www.srf.ch/sendungen/echo-der-zeit/micheline-calmy-rey-zu-ihrem-ruecktritt",
				"title": "Micheline Calmy-Rey zu ihrem Rücktritt",
				"date": "7. September 2011",
				"language": "de-CH",
				"programTitle": "Echo der Zeit",
				"network": "Schweizer Radio und Fernsehen SRF",
				"libraryCatalog": "Schweizer Radio und Fernsehen SRF",
				"accessDate": "CURRENT_TIMESTAMP"
			}
		]
	},
	{
		"type": "web",
		"url": "http://www.srf.ch/sendungen/echo-der-zeit/sendungen",
		"items": "multiple"
	}
]
/** END TEST CASES **/