-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathitunes.js
117 lines (94 loc) · 2.99 KB
/
itunes.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
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
const utils = require('./utils');
const namespaces = require('./namespaces');
const getAuthors = (node) => {
const authors = utils.getElementTextContentArray(
node,
'author',
namespaces.itunes
);
return authors.map((author) => ({
name: author,
}));
};
const getBlock = (node) =>
utils.getElementTextContent(node, 'block', namespaces.itunes);
const getSubCategories = (node) => {
const categories = utils.getChildElements(
node,
'category',
namespaces.itunes
);
if (categories.length === 0) {
return [];
}
return categories.map((category) => ({
name: category.getAttribute('text'),
}));
};
const getCategories = (node) => {
const categories = utils.getChildElements(
node,
'category',
namespaces.itunes
);
return categories.map((category) => ({
name: category.getAttribute('text'),
subCategories: getSubCategories(category),
}));
};
const getComplete = (node) =>
utils.getElementTextContent(node, 'complete', namespaces.itunes);
const getDuration = (node) =>
utils.getElementTextContent(node, 'duration', namespaces.itunes);
const getExplicit = (node) =>
utils.getElementTextContent(node, 'explicit', namespaces.itunes);
const getImage = (node) => {
const images = utils.getChildElements(node, 'image', namespaces.itunes);
return images.length > 0 ? images[0].getAttribute('href') : undefined;
};
const getIsClosedCaptioned = (node) =>
utils.getElementTextContent(node, 'isClosedCaptioned', namespaces.itunes);
const getNewFeedUrl = (node) =>
utils.getElementTextContent(node, 'new-feed-url', namespaces.itunes);
const getOrder = (node) =>
utils.getElementTextContent(node, 'order', namespaces.itunes);
const getOwner = (node) => {
const owners = utils.getChildElements(node, 'owner', namespaces.itunes);
if (owners.length === 0) {
return {
name: undefined,
email: undefined,
};
}
return {
name: utils.getElementTextContent(owners[0], 'name', namespaces.itunes),
email: utils.getElementTextContent(owners[0], 'email', namespaces.itunes),
};
};
const getSubtitle = (node) =>
utils.getElementTextContent(node, 'subtitle', namespaces.itunes);
const getSummary = (node) =>
utils.getElementTextContent(node, 'summary', namespaces.itunes);
exports.parseChannel = (node) => ({
authors: getAuthors(node),
block: getBlock(node),
categories: getCategories(node),
complete: getComplete(node),
explicit: getExplicit(node),
image: getImage(node),
newFeedUrl: getNewFeedUrl(node),
owner: getOwner(node),
subtitle: getSubtitle(node),
summary: getSummary(node),
});
exports.parseItem = (node) => ({
authors: getAuthors(node),
block: getBlock(node),
duration: getDuration(node),
explicit: getExplicit(node),
image: getImage(node),
isClosedCaptioned: getIsClosedCaptioned(node),
order: getOrder(node),
subtitle: getSubtitle(node),
summary: getSummary(node),
});