Skip to content

Commit

Permalink
added tagesschau
Browse files Browse the repository at this point in the history
  • Loading branch information
keydon committed Apr 19, 2021
1 parent b7d7b32 commit f46adf1
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ For **PVR TV/radio support - Set channel by number**, use "Say a phrase with a n
| Say a phrase with a text ingredient | Kodi open $ from my tvshows | _YOUR_NODE_SERVER_/opentvshow?q={{TextField}} |
| Say a phrase with a text ingredient | Kodi open $ from my movies | _YOUR_NODE_SERVER_/openmovie?q={{TextField}} |
| Say a simple phrase | Kodi toggle fullscreen | _YOUR_NODE_SERVER_/togglefullscreen |
| Say a phrase with a text ingredient | Kodi load profile $ | _YOUR_NODE_SERVER_/loadProfile |
| Say a phrase with a text ingredient | Kodi load profile $ | _YOUR_NODE_SERVER_/loadProfile |
| Say a simple phrase | Kodi play tagesschau | _YOUR_NODE_SERVER_/tagesschau/playTodaysBroadcast |


To **Start/resume a movie/tv episode with a delay**
The commands marked with *delay (above) take an optional delay parameter to delay startup of the media by the specified number of seconds.
Expand Down
60 changes: 60 additions & 0 deletions apps/tagesschau.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

const express = require('express');
const axios = require('axios');
var xmlParser = require('fast-xml-parser');
const { response } = require('express');

const feedUrl = 'https://www.tagesschau.de/export/video-podcast/webxl/tagesschau_https/';

const playTodaysBroadcast = (response ) => {
console.log("tagesschau", response);
}

const fetchAndPlayTodaysBroadcast = async (request) => {
let feedContent = await axios.get(feedUrl);
let json = xmlParser.parse(feedContent.data, {
ignoreAttributes : false,
});
let lastestItem = json.rss.channel.item[0];
let dayOfPublication = lastestItem.title.split('.', 2)[0];
let todaysDay = (new Date).getDate();

if (dayOfPublication == todaysDay) {
return playFile(request, lastestItem.enclosure['@_url']);
} else {
console.log({dayOfPublication, todaysDay, lastestItem});
return showNotification(request, response, "Heutige Ausgabe noch nicht online", "error");
}
};

exports.build = (exec) => {
const app = express();

app.set('json spaces', 2);
app.all('/playTodaysBroadcast', exec(fetchAndPlayTodaysBroadcast));

return app;
};

const playFile = (request, fileName) => {
return request.kodi.Player.Open({ // eslint-disable-line new-cap
item: {
file: fileName
},
options: {
resume: false
}
});
};


const showNotification = (request, response, message, image) => {
let param = {
title: 'GoogleHomeKodi',
message: message,
image: image
};

return request.kodi.GUI.ShowNotification(param); // eslint-disable-line new-cap
};
9 changes: 8 additions & 1 deletion broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,12 @@ exports.matchPhraseToEndpoint = matchPhraseToEndpoint;
exports.processRequest = (request, response) => {
let endpointKey = matchPhraseToEndpoint(request, response);
let endpoint = endpointKey.split(`:`, 1)[0];
return Helper[endpoint](request, response);

let legacyRoute = Helper[endpoint];
if(legacyRoute){
return Helper[endpoint](request, response);
}

request.url = '/' + endpoint;
return Promise.resolve(request.app.handle(request, response));
};
1 change: 1 addition & 0 deletions broker/de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tagesschau/playTodaysBroadcast": "(spiele|spiel|starte)?( die)?( heutige)? ?tagesschau ?(folge|episode|ausstrahlung)?( von heute)?( ab)?",
"kodiBingeWatchTvshow": "(binge|spiele|spiel|starte) die (komplette|ganze) (serie|sendung) (?<q>.+)",
"kodiCleanLibrary": ".*bibliothek (aufräumen|bereinigen)",
"kodiDecreaseVolume": "verringere die lautstärke( um (?<q>.+))?",
Expand Down
1 change: 1 addition & 0 deletions broker/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tagesschau/playTodaysBroadcast": "(play )?(todays )?tagesschau( broadcast| episode)?",
"kodiActivateTv": "activate",
"kodiBingeWatchTvshow": "binge watch (?<q>.+)",
"kodiCleanLibrary": "clean library",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"test": "mocha --recursive --require should"
},
"dependencies": {
"axios": "^0.21.1",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"fast-xml-parser": "^3.19.0",
"fuse.js": "^5.2.1",
"node-fetch": "^2.6.0",
"words-to-numbers": "^1.5.1",
Expand Down
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Broker = require('./broker.js');
const bodyParser = require('body-parser');
const LoadConfig = require('./config.js');
const SettingsApp = require('./apps/settings.js');
const TagesschauApp = require('./apps/tagesschau.js');
const ResponseException = require('./exceptions.js').ResponseException;

const config = new LoadConfig();
Expand Down Expand Up @@ -295,6 +296,8 @@ app.all('/broker', exec(Broker.processRequest));

app.use('/settings', SettingsApp.build(exec));

app.use('/tagesschau', TagesschauApp.build(exec));

// error handlers need to be last
app.use(handleError);

Expand Down
11 changes: 11 additions & 0 deletions test/broker/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@
{ "phrase": "starte eine folge aus Rick & Morty", "q": "rick & morty" }
]
},
{
"endpoint": "tagesschau/playTodaysBroadcast",
"phrases": [
{ "phrase": "tagesschau"},
{ "phrase": "spiele tagesschau"},
{ "phrase": "spiele die tagesschau ab"},
{ "phrase": "spiele die heutige tagesschau folge"},
{ "phrase": "spiele tagesschau ausstrahlung ab"},
{ "phrase": "tagesschau ausstrahlung von heute"}
]
},
{
"endpoint": "kodiPlayYoutube",
"phrases": [
Expand Down
17 changes: 17 additions & 0 deletions test/broker/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@

]
},
{
"endpoint": "tagesschau/playTodaysBroadcast",
"phrases": [
{ "phrase": "tagesschau"},
{ "phrase": "play tagesschau"},
{ "phrase": "play todays tagesschau"},
{ "phrase": "play todays tagesschau episode"},
{ "phrase": "play todays tagesschau broadcast"},
{ "phrase": "play tagesschau episode"}
]
},
{
"endpoint": "kodiResumeMovie",
"phrases": [
Expand All @@ -109,6 +120,12 @@
{ "phrase": "resume the tv show jack ryan", "q": "jack ryan"}
]
},
{
"endpoint": "kodiToggleFullscreen",
"phrases": [
{ "phrase": "toggle fullscreen" }
]
},
{
"endpoint": "kodiMuteToggle",
"phrases": [
Expand Down

0 comments on commit f46adf1

Please sign in to comment.