Skip to content

Commit

Permalink
added playing named playlists
Browse files Browse the repository at this point in the history
smart and regular playlists supported.

Closes #194
  • Loading branch information
keydon committed Aug 20, 2019
1 parent aa8d663 commit 72cc04e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ There are many more windows to choose from, a full list can be found [here](http
"Hey Google, kodi toggle **party mode**" --> starts the kodi party mode.

### **Playlist Control:**
"Hey Google, kodi playlist previous/next/list item number" --> This will go forward/backward or select an item on the playlist #.

"Hey Google, kodi play playlist [playlistname]" --> This will look for a playlist with that name and play it. Smart and regular playlist supported.
"Hey Google, kodi playlist previous/next/[list item number]" --> This will go forward/backward or select an item on the currently playing playlist #.

------------
## How to setup
Expand Down Expand Up @@ -539,6 +541,7 @@ For **PVR TV support - Set channel by number**, use "Say a phrase with a number"
| Say a phrase with a text ingredient | Kodi play the album $ | _YOUR_NODE_SERVER_/playalbum?q={{TextField}} |
| Say a phrase with a text ingredient | Kodi play the artist $ | _YOUR_NODE_SERVER_/playartist?q={{TextField}} |
| Say a phrase with a text ingredient | Kodi play the music genre $ | _YOUR_NODE_SERVER_/playgenre?q={{TextField}} |
| Say a phrase with a text ingredient | Kodi play playlist $ | _YOUR_NODE_SERVER_/playplaylist?q={{TextField}} |
| Say a phrase with a text ingredient | Kodi playlist $ | _YOUR_NODE_SERVER_/playercontrol?q={{TextField}} |
| Say a simple phrase | Kodi toggle party mode | _YOUR_NODE_SERVER_/togglePartymode |
| Say a phrase with a text ingredient | Kodi open $ from my favourites | _YOUR_NODE_SERVER_/playfavourite?q={{TextField}} |
Expand Down
42 changes: 30 additions & 12 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,18 @@ const kodiGetMovieGenres = (Kodi) => {
});
};

const getDirecoryContents = (kodi, path) => {
return kodi.Files.GetDirectory({ // eslint-disable-line new-cap
directory: path
})
.then((kodiResponse) => {
if (!(kodiResponse && kodiResponse.result && kodiResponse.result.files && kodiResponse.result.files.length > 0)) {
throw new Error('directory was empty');
}
return kodiResponse.result.files;
});
};

const kodiGetProfiles = (Kodi) => {
return Kodi.Profiles.GetProfiles() // eslint-disable-line new-cap
.then((profiles) => {
Expand Down Expand Up @@ -820,6 +832,24 @@ exports.playercontrol = (request, response) => { // eslint-disable-line no-unuse
return kodiGoTo(Kodi, playlistindex);
};

exports.kodiPlayPlaylist = (request, response) => { // eslint-disable-line no-unused-vars
let Kodi = request.kodi;
const playlistName = request.query.q.trim();

console.log(`Request for playing playlist "${playlistName}" received!`);

return getDirecoryContents(Kodi, `special://profile/playlists/music`)
.then((lists) => fuzzySearchBestMatch(lists, playlistName))
.catch(() =>
getDirecoryContents(Kodi, `special://profile/playlists/video`)
.then((lists) => fuzzySearchBestMatch(lists, playlistName)))
.then((playlist) => Kodi.Player.Open({ // eslint-disable-line new-cap
item: {
directory: playlist.file
}
}));
};

exports.kodiStop = (request, response) => { // eslint-disable-line no-unused-vars
console.log('Stop request received');
let Kodi = request.kodi;
Expand Down Expand Up @@ -1264,18 +1294,6 @@ exports.kodiTogglePartymode = (request) => {
.then((playerid) => togglePartyMode(kodi, playerid));
};

const getDirecoryContents = (kodi, path) => {
return kodi.Files.GetDirectory({ // eslint-disable-line new-cap
directory: path
})
.then((kodiResponse) => {
if (!(kodiResponse && kodiResponse.result && kodiResponse.result.files && kodiResponse.result.files.length > 0)) {
throw new Error('directory was empty');
}
return kodiResponse.result.files;
});
};

exports.kodiToggleFullscreen = (request) => { // eslint-disable-line no-unused-vars
console.log('Toggle Fullscreen request received');
let Kodi = request.kodi;
Expand Down
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ app.all('/togglePartymode', exec(Helper.kodiTogglePartymode));
app.all('/toggleFullscreen', exec(Helper.kodiToggleFullscreen));

// Playlist Control
app.all('/playplaylist', exec(Helper.kodiPlayPlaylist));

app.all('/playercontrol', exec(Helper.playercontrol));

app.all('/playfavourite', exec(Helper.kodiOpenFavourite));
Expand Down

0 comments on commit 72cc04e

Please sign in to comment.