-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christine Emrich
committed
Mar 12, 2017
1 parent
ecebd0c
commit 8f88b70
Showing
7 changed files
with
96 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
const channels = require('./../models/channels'); | ||
const downloaders = [ | ||
require('./zdf-downloader') | ||
]; | ||
const channelIds = downloaders.reduce((ids, downloader) => | ||
ids.concat(downloader.channelIds), [] | ||
); | ||
|
||
exports.getShows = function() { | ||
return channels.ids.map(function (channelId) { | ||
return exports.getShow(channelId); | ||
}); | ||
return Promise.all(channelIds.map(channelId => { | ||
return exports.getShow(channelId).catch(e => { | ||
console.error(e.message); | ||
return null; | ||
}); | ||
})); | ||
}; | ||
|
||
exports.getShow = function(channelId) { | ||
return { | ||
title: "The Title", | ||
subtitle: "The Subtitle", | ||
description: "description", | ||
channel: channelId, | ||
startTime: new Date().getTime(), | ||
endTime: new Date().getTime() | ||
}; | ||
for (let downloader of downloaders) { | ||
if (downloader.channelIds.includes(channelId)) { | ||
return downloader.getShow(channelId); | ||
} | ||
} | ||
return Promise.reject('no downloader available'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const request = require('request'); | ||
const moment = require('moment-timezone'); | ||
|
||
const baseUrl = 'https://api.zdf.de/cmdm/epg/broadcasts?to=2017-03-11T12%3A58%3A42Z&limit=1&page=1&order=desc'; | ||
const headers = { | ||
"Host": "api.zdf.de", | ||
"Accept": "application/vnd.de.zdf.v1.0+json", | ||
"Api-Auth": "Bearer d2726b6c8c655e42b68b0db26131b15b22bd1a32", | ||
"Origin": "https://www.zdf.de" | ||
}; | ||
const channelIdMap = { | ||
"zdf": "zdf", | ||
"dreisat": "3sat", | ||
"kika": "ki.ka", | ||
"phoenix": "phoenix", | ||
"zdf_info": "zdfinfo", | ||
"zdf_neo": "ZDFneo", | ||
"arte": "arte", | ||
}; | ||
|
||
exports.channelIds = ["zdf", "dreisat", "kika", "phoenix", "zdf_info", "zdf_neo", "arte"]; | ||
|
||
function getShow(json, channelId) { | ||
let broadcast = json['http://zdf.de/rels/cmdm/broadcasts'][0]; | ||
|
||
return { | ||
title: broadcast.title, | ||
subtitle: broadcast.subtitle, | ||
channel: channelId, | ||
startTime: moment(broadcast.airtimeBegin), | ||
endTime: moment(broadcast.airtimeEnd) | ||
}; | ||
} | ||
|
||
exports.getShow = function (channelId) { | ||
let urlChannel = channelIdMap[channelId]; | ||
let url = `${baseUrl}&tvServices=${urlChannel}`; | ||
return new Promise((resolve, reject) => { | ||
request.get({ | ||
url: url, | ||
json: true, | ||
headers: headers | ||
}, (err, res, data) => { | ||
if (err) { | ||
reject(err); | ||
} else if (res.statusCode !== 200) { | ||
return reject('wrong status code: ' + res.statusCode); | ||
} else { | ||
return resolve(getShow(data, channelId)); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
const downloader = require('./../downloader/show-downloader'); | ||
|
||
function sendErrorResponse(e, res) { | ||
let message = e.message; | ||
if (typeof(message) === 'undefined') { | ||
message = e; | ||
} | ||
|
||
console.error(message); | ||
res.send({error: message}); | ||
} | ||
|
||
function sendShowsResponse(shows, res) { | ||
res.send({shows: shows }); | ||
} | ||
|
||
exports.findAll = function(req, res) { | ||
res.send(downloader.getShows()); | ||
downloader.getShows() | ||
.then(shows => sendShowsResponse(shows.filter(show => show !== null), res)) | ||
.catch(e => sendErrorResponse(e, res)); | ||
}; | ||
|
||
exports.findByChannel = function(req, res) { | ||
res.send([downloader.getShow(req.params.channelId)]); | ||
downloader.getShow(req.params.channelId) | ||
.then(show => sendShowsResponse(show === null ? [] : [show], res)) | ||
.catch(e => sendErrorResponse(e, res)); | ||
}; |