Skip to content

Commit 7855650

Browse files
committed
New and updated APIs
1 parent bb83757 commit 7855650

File tree

6 files changed

+260
-37
lines changed

6 files changed

+260
-37
lines changed

europeana.js

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ const axios = require('axios');
22
const turf = require('@turf/turf');
33
const BASE_URL = "https://api.europeana.eu/record/v2/search.json";
44

5+
if (process.env.EUROPEANA_API_KEY == undefined) {
6+
console.log("Set environment variable EUROPEANA_API_KEY to your EUROPEANA API key.");
7+
}
8+
59
module.exports = {
610
async getImagesEuropeana(topic,language) {
11+
12+
let query = '"' + JSON.parse(topic).join('" OR "') + '"';
13+
714
const requestConfig = {
815
baseURL: BASE_URL + "/",
916
params: {
10-
wskey: 'BXEGTQYKm',
11-
query: topic,
17+
wskey: process.env.EUROPEANA_API_KEY,
18+
query: query,
1219
qf: '',
1320
media: true,
1421
thumbnail: true,
@@ -41,10 +48,11 @@ module.exports = {
4148
institutions: [],
4249
subjects: item.subject,
4350
//legacy_tags: result.legacy_tags,
44-
//license: result.license,
45-
//license_id: result.license, //rights
51+
license: '',
52+
license_id: '',
4653
//license_version: result.license_version,
4754
license_link: item.rights,
55+
rightsstatement: '',
4856
infoURL: '',
4957
inventoryNumber: '',
5058
geoLocations: '',//transformation FIX
@@ -61,7 +69,7 @@ module.exports = {
6169
language: ''
6270
}
6371

64-
if (!!item.year && item.year.length > 0) {
72+
if (item.year) {
6573
image.year = item.year[0];
6674
}
6775

@@ -75,18 +83,54 @@ module.exports = {
7583
}
7684
}
7785

78-
if (!!item.dcCreator && item.dcCreator.legth > 0) {
86+
if (item.dcCreator) {
7987
for (let creator of item.dcCreator) {
8088
image.creators.push(creator);
8189
}
8290
}
8391

84-
if (!!item.dataProvider && item.dataProvider > 0) {
92+
if (item.dataProvider) {
8593
for (let provider of item.dataProvider) {
8694
image.institutions.push(provider);
8795
}
8896
}
8997

98+
if (!!item.rights && item.rights > 0) {
99+
switch (item.rights) {
100+
case "http://creativecommons.org/licenses/by/4.0":
101+
license = "CC BY 4.0";
102+
license_id = "CC BY 4.0";
103+
case "http://creativecommons.org/licenses/by-sa/4.0":
104+
license = "CC BY-SA 4.0";
105+
license_id = "CC BY-SA 4.0";
106+
case "http://creativecommons.org/licenses/by-nc/4.0":
107+
license = "CC BY-NC 4.0";
108+
license_id = "CC BY-NC 4.0";
109+
case "http://creativecommons.org/licenses/by-nd/4.0":
110+
license = "CC BY-ND 4.0";
111+
license_id = "CC BY-ND 4.0";
112+
case "http://creativecommons.org/licenses/by-nc-sa/4.0":
113+
license = "CC BY-NC-SA 4.0";
114+
license_id = "CC BY-NC-SA 4.0";
115+
case "http://creativecommons.org/licenses/by-nc-nd/4.0":
116+
license = "CC BY-NC-ND 4.0";
117+
license_id = "CC BY-NC-ND 4.0";
118+
case "http://creativecommons.org/publicdomain/mark/1.0/":
119+
license = "CC0";
120+
license_id = "CC0";
121+
case "http://rightsstatements.org/vocab/InC/1.0/":
122+
rightsstatement = "In copyright";
123+
case "http://rightsstatements.org/vocab/NoC-OKLR/1.0/":
124+
rightsstatement = "Other legal restrictions";
125+
}
126+
}
127+
128+
if (!!item.type && item.type > 0) {
129+
for (let type of item.type) {
130+
image.formats.push(type);
131+
}
132+
}
133+
90134
images.push(image);
91135
}
92136

finna.js

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@ const BASE_URL = "https://api.finna.fi";
44

55
module.exports = {
66
async getImagesFromFinnaWithTitle(topic, lat, lon, maxradius) {
7+
8+
let query = '"' + JSON.parse(topic).join('" OR "') + '"';
79

810
//construct query
911
const requestConfig = {
1012
baseURL: BASE_URL+"/",
1113
url: "/v1/search",
1214
method: "get",
1315
params: {
14-
lookfor: topic,
16+
lookfor: query,
1517
type: 'AllFields',
1618
limit: 100,
17-
"filter[0]": '~format:"0/Image/"',
18-
"filter[1]": '~format:"0/WorkOfArt/"',
19-
"filter[2]": 'usage_rights_str_mv:"usage_E"',
20-
"filter[3]": 'online_boolean:"1"',
19+
//"filter[0]": '~format:"0/Image/"',
20+
//"filter[1]": '~format:"0/WorkOfArt/"',
21+
//"filter[2]": 'usage_rights_str_mv:"usage_E"',
22+
//"filter[0]": 'free_online_boolean:"1"',
23+
'filter[0]': '~format_ext_str_mv:"0/Image/"',
24+
'filter[1]': '~format_ext_str_mv:"0/Map/"',
25+
'filter[2]': '~format_ext_str_mv:"0/WorkOfArt/"',
26+
'filter[3]': 'free_online_boolean:1',
2127
"field[0]": 'id',
2228
"field[1]": 'title',
2329
"field[2]": 'geoLocations',
@@ -138,32 +144,33 @@ module.exports = {
138144

139145
//assign data to metadata properties
140146
var image = {
141-
id: record.id,
142-
inventoryNumber: record.identifierString,
143-
source: "Finna",
144-
title: [],
145-
geoLocations: (record.geoLocations != undefined ? record.geoLocations : []),
146-
measurements: record.measurements,
147-
materials: materials,
148-
imageURL: BASE_URL + record.images[0],
149-
thumbURL: thumbURL,
150-
formats: formats,
151-
year: (record.year != undefined ? parseInt(record.year, 10) : null),
152-
publisher: (record.publisher != undefined ? record.publisher : null),
153-
// authors: authors,
154-
creators: record.nonPresenterAuthors,
155-
institutions: [],
156147
actors: record.subjectActors,
157-
details: record.subjectDetails,
158-
subjects: subjects,
159-
places: record.subjectPlaces,
160148
collection: collection,
161-
imageRights: record.imageRights,
162-
license: (record.imageRights != undefined ? record.imageRights.copyright : ""),
149+
creators: record.nonPresenterAuthors,
150+
creditline: record.imagesExtended[0].rights.creditline,
151+
datecreated: datecreated,
163152
description: record.summary,
153+
details: record.subjectDetails,
154+
downloadURL: '',
155+
formats: formats,
156+
geoLocations: (record.geoLocations != undefined ? record.geoLocations : []),
157+
id: record.id,
158+
imageURL: BASE_URL + record.images[0],
164159
infoURL: "https://www.finna.fi/Record/" + encodeURIComponent(record.id),
165160
inscriptions: record.inscriptions,
166-
datecreated: datecreated
161+
institutions: [],
162+
inventoryNumber: record.identifierString,
163+
license: (record.imageRights != undefined ? record.imageRights.copyright : ""),
164+
materials: materials,
165+
measurements: record.measurements,
166+
places: record.subjectPlaces,
167+
publisher: (record.publisher != undefined ? record.publisher : null),
168+
rightsstatement: '',
169+
source: "Finna",
170+
subjects: subjects,
171+
thumbURL: thumbURL,
172+
title: [],
173+
year: ''
167174
}
168175

169176
if (record.title) {
@@ -176,6 +183,10 @@ module.exports = {
176183
}
177184
}
178185

186+
if (record.year != undefined) {
187+
image.year = parseInt(record.year, 10);
188+
}
189+
179190
images.push(image);
180191
}
181192
}

flickr.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ if (process.env.FLICKR_KEY == undefined) {
77

88
module.exports = {
99
async getImagesFlickr(topic, lat, lon, maxradius) {
10+
11+
let query = '"' + JSON.parse(topic).join('" OR "') + '"';
12+
1013
const requestConfig = {
1114
baseURL: "https://api.flickr.com/",
1215
url: "/services/rest/",
1316
method: "get",
1417
params: {
1518
method: "flickr.photos.search",
1619
api_key: process.env.FLICKR_KEY,
17-
text: topic,
20+
text: query,
1821
license: "1,2,3,4,5,6,7,8,9,10",
1922
is_commons: "false",
2023
extras: "license,description,owner_name,geo,tags,url_l,url_n,path_alias,date_taken",

rest.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const { getHistoricalMaps } = require('./historical-maps');
2626
const { getImagesFromFinnaWithTitle } = require('./finna');
2727
const { getImagesFromCommonsWithTitle } = require('./wikimedia-commons');
2828
const { getImagesFlickr } = require('./flickr');
29-
const { getImagesCC } = require('./cc');
29+
//const { getImagesTroveTextsearch } = require('./trove');
30+
//const { getImagesSmithsonianTextsearch } = require('./smithsonian');
31+
//const { getImagesCC } = require('./cc');
3032
const { getImagesEuropeana } = require('./europeana');
3133
const { getWikidata } = require('./wikidata');
3234
const { getWikidataByLatLon } = require('./wikidata-latlon');
@@ -132,8 +134,10 @@ app.get('/images', asyncMiddleware(async function(req, res) {
132134
getImagesFromFinnaWithTitle(topic, req.query.lat, req.query.lon, req.query.maxradius),
133135
getImagesFromCommonsWithTitle(topic, req.query.commons_category),
134136
getImagesFlickr(topic, req.query.lat, req.query.lon, req.query.maxradius),
135-
getImagesCC(topic),
136-
getImagesEuropeana(topic, language)
137+
//getImagesCC(topic),
138+
getImagesEuropeana(topic, language),
139+
getImagesTroveTextsearch(topic, language),
140+
getImagesSmithsonianTextsearch(topic, language)
137141
];
138142
const safeRequests = requests.map(promise => promise.catch(err => {
139143
console.error(err.stack);

smithsonian.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const axios = require('axios');
2+
const turf = require('@turf/turf');
3+
const BASE_URL = "https://api.si.edu/openaccess/api/v1.0/search";
4+
5+
if (process.env.SMITHSONIAN_API_KEY == undefined) {
6+
console.log("Set environment variable SMITHSONIAN_API_KEY to your Smithsonian API key.");
7+
}
8+
9+
module.exports = {
10+
async getImagesSmithsonianTextsearch(topic,language) {
11+
12+
//let query = '"' + JSON.parse(topic).join('" OR "') + '"';
13+
let query = JSON.parse(topic)[0];
14+
15+
const requestConfig = {
16+
baseURL: BASE_URL + "/",
17+
params: {
18+
api_key: process.env.SMITHSONIAN_API_KEY,
19+
q: query,
20+
rows: 50,
21+
sort: 'relevancy'
22+
//include: 'tags'
23+
}
24+
}
25+
26+
const response = await axios.request(requestConfig);
27+
28+
let images = [];
29+
30+
if (!response.data.response || !response.data.response.rows.length) {
31+
return [];
32+
}
33+
34+
//format response
35+
for (var i = 0; i < response.data.response.rows.length; i++) {
36+
var item = response.data.response.rows[i];
37+
38+
var image = {
39+
//download_url: result.detail,
40+
//legacy_tags: result.legacy_tags,
41+
//license_version: result.license_version,
42+
actors: item.content.indexedStructured.object_type.name,
43+
collection: '',
44+
creators: '',
45+
datecreated: item.content.indexedStructured.date,
46+
description: '',
47+
formats: item.content.indexedStructured.object_type,
48+
geoLocations: '',
49+
id: item.content.descriptiveNonRepeating.record_ID,
50+
imageRights: '',
51+
imageURL: '',
52+
infoURL: item.content.descriptiveNonRepeating.record_link,
53+
inscriptions: '',
54+
institutions: item.content.descriptiveNonRepeating.data_source,
55+
inventoryNumber: '',
56+
language: '',
57+
license_id: '',
58+
license_link: '',
59+
license: '',
60+
measurements: '',
61+
places: item.content.indexedStructured.place,
62+
publisher: '',
63+
rightsstatement: '',
64+
source: 'Smithsonian',
65+
subjects: '',
66+
thumbURL: '',
67+
title: [],
68+
year: ''
69+
}
70+
71+
if (item.title) {
72+
image.title.push(item.title);
73+
}
74+
75+
images.push(image);
76+
}
77+
78+
return images;
79+
}
80+
};

0 commit comments

Comments
 (0)