Skip to content

Commit

Permalink
Added program categories to XMLTV endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
reeseovine committed Oct 5, 2021
1 parent 17f7120 commit 361cb2a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
20 changes: 19 additions & 1 deletion services/generate-xmltv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import moment from 'moment';

import { db } from './database';

const formatCategories = categories => {
const tagList = [];
for (const category of categories){
tagList.push({
category: [
{
_attr: {
'lang': 'en',
},
},
category
]
});
}
return tagList;
}

export const generateXml = async (numChannels: number, startChannel: number) => {
const wrap: any = {
tv: [
Expand Down Expand Up @@ -81,9 +98,10 @@ export const generateXml = async (numChannels: number, startChannel: number) =>
},
],
},
...formatCategories((entry as any).categories)
],
});
}

return xml(wrap);
}
}
11 changes: 11 additions & 0 deletions services/get-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import moment from 'moment';

import { db } from './database';

const parseCategories = event => {
const categories = ['Sports'];
for (const classifier of [event.category, event.subcategory, event.sport, event.league]){
if (classifier !== null && classifier.name !== null){
categories.push(classifier.name);
}
}
return [...new Set(categories)];
}

const parseAirings = async events => {
for (const event of events) {
const entryExists = await db.entries.findOne({id: event.id});
Expand All @@ -18,6 +28,7 @@ const parseAirings = async events => {
end: moment(event.startDateTime).add(event.duration, 'seconds').valueOf(),
feed: event.feedName,
image: event.image?.url,
categories: parseCategories(event)
});
}
}
Expand Down

0 comments on commit 361cb2a

Please sign in to comment.