-
Notifications
You must be signed in to change notification settings - Fork 5
/
yle.js
80 lines (70 loc) · 2.17 KB
/
yle.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
const axios = require('axios');
const BASE_URL = "https://external.api.yle.fi";
module.exports = {
async getImagesYle(topic) {
//construct query
const requestConfig = {
baseURL: BASE_URL + "/",
url: "/v1/programs/items.json",
method: "get",
params: {
app_id: "cac1239e",
app_key: "71eab9be802dc9f2f142639673fc16f4",
availability: "ondemand",
mediaobject: "video",
category: "5-130",
order: "playcount.24h:desc",
q: topic
}
}
const response = await axios.request(requestConfig);
let images = [];
if (!response.data) {
return [];
}
for (var i = 0; i < response.data.length; i++) {
var video = response.data[i];
//assign data to metadata properties
var image = {
actors: '',
collection: '',
creators: video.creator,
datecreated: '',
description: video.description,
details: '',
download_url: '',
formats: '',
geoLocations: '',
id: '',
imageRights: '',
imageURL: '',
infoURL: '',
inscriptions: '',
institutions: video.creator,
inventoryNumber: '',
language: video.language,
license: '',
license_id: '',
license_link: '',
license_version: '',
materials: '',
measurements: '',
places: '',
publisher: '',
source: '',
subjects: video.subject.title,
thumbURL: '',
title: video.title.fi,
year: '',
}
if (video.title) {
image.title.push(video.title);
}
images.push(image);
}
if(images.length > 30) { // Good practice
images = images.slice(0, 30);
}
return images;
}
}