Skip to content

Commit

Permalink
App store compatible
Browse files Browse the repository at this point in the history
- Added music support
- Added TV Show latest episode support
- Made solution appstore valid
  • Loading branch information
MarvinSchenkel committed Mar 14, 2016
1 parent fa509af commit 3921baa
Show file tree
Hide file tree
Showing 16 changed files with 368 additions and 50 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Adds Kodi support to your Homey!
Currently working:
- Adding a Kodi instance as a device
- Playing movies via speech
- Playing music via speech (EXPERIMENTAL. Only artist is currently implemented)
- Playing music via speech
- By artist
- Playing tv shows via speech
- Latest unwatched episode of a tv show
- Play / pause / stop through speech
- Various flow triggers / actions

Expand All @@ -13,13 +16,15 @@ Note: Only adding 1 device is currently supported
### Speech support
* "Play movie Finding Nemo"
* "Play music by artist Armin van Buuren"
* "Play the latest episode of The Walking Dead"
* "Pause"
* "Resume" (prevent interference with 'play')
* "Stop"

### Flow support
*Triggers*
* On movie start
* On episode start
* On pause (only triggered when pausing through Homey)
* On resume (only triggered when resuming through Homey)
* On stop (only triggered when stopping through Homey)
Expand Down
84 changes: 75 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* global __ */
/* global Homey */
'use strict'

function init () {
Homey.log('init()')

// Register functions
// Register functions to Homey
Homey.manager('speech-input').on('speech', parseSpeach)
Homey.manager('flow').on('action.play_movie_kodi', onFlowActionPlayMovieKodi)
Homey.manager('flow').on('action.pause_resume_kodi', onFlowActionPauseResumeKodi)
Expand Down Expand Up @@ -43,19 +41,20 @@ function parseSpeach (speech, callback) {
return true

case 'kodi_play_music' :
var transcriptWithoutTrigger = speech.transcript.replace(trigger.text, '')
var musicTranscriptWithoutTrigger = speech.transcript.replace(trigger.text, '')
// Check how to search for music
if (transcriptWithoutTrigger.indexOf(__('by')) > -1 || transcriptWithoutTrigger.indexOf(__('artist')) > -1) {
var artistSearchQuery = transcriptWithoutTrigger.replace(__('by'), '').replace(__('artist'), '')
if (musicTranscriptWithoutTrigger.indexOf(__('by')) > -1 || musicTranscriptWithoutTrigger.indexOf(__('artist')) > -1) {
var artistSearchQuery = musicTranscriptWithoutTrigger.replace(__('by'), '').replace(__('artist'), '')
// NOTE: no multiple device support yet, pass null as device so 1st registered device gets picked
searchAndPlayMusic(null, 'ARTIST', artistSearchQuery)
.then(console.log)
.catch(
function (err) {
// Driver should throw user friendly errors
Homey.manager('speech-output').say(err)
}
)
} else if (1 === 0) {
// Add search by album / genre
}
// Only fire 1 trigger
return true
Expand All @@ -81,7 +80,7 @@ function parseSpeach (speech, callback) {

case 'kodi_stop' :
Homey.manager('drivers').getDriver('kodi').stop(null)
.then(function () {
.then(function () {
Homey.log('Triggering flow kodi_stop')
Homey.manager('flow').trigger('kodi_stop')
})
Expand All @@ -92,6 +91,44 @@ function parseSpeach (speech, callback) {
}
)
return true // Only fire one trigger

case 'kodi_next' :
Homey.manager('drivers').getDriver('kodi').nextOrPreviousTrack(null, 'next')
.then(function (episodeToPlay) {
// TODO FLOW TRIGGER
})
.catch(
function (err) {
// Driver should throw user friendly errors
Homey.manager('speech-output').say(err)
}
)
return true // Only fire one trigger

case 'kodi_previous' :
Homey.manager('drivers').getDriver('kodi').nextOrPreviousTrack(null, 'previous')
.then(function () {
// TODO FLOW TRIGGER
})
.catch(
function (err) {
// Driver should throw user friendly errors
Homey.manager('speech-output').say(err)
}
)
return true // Only fire one trigger

case 'kodi_play_latest_episode' :
var episodeTranscriptWithoutTrigger = speech.transcript.replace(trigger.text, '').replace(__('of'), '')

playLatestEpisode(null, episodeTranscriptWithoutTrigger)
.catch(
function (err) {
// Driver should throw user friendly errors
Homey.manager('speech-output').say(err)
}
)
return true // Only fire one trigger
}
})

Expand Down Expand Up @@ -121,6 +158,7 @@ function onFlowActionStopKodi (callback, args) {
.then(callback)
.catch(console.error)
}

/* ******************
COMMON FUNCTIONS
********************/
Expand Down Expand Up @@ -158,7 +196,35 @@ function searchAndPlayMusic (device, queryProperty, searchQuery) {
KodiDriver.searchMusic(device, queryProperty, searchQuery)
.then(
function (songsToPlay) {
KodiDriver.playMusic(device, songsToPlay)
KodiDriver.playMusic(device, songsToPlay, true)
.catch(reject)
}
)
.catch(reject)
})
}

function playLatestEpisode (device, seriesName) {
return new Promise(function (resolve, reject) {
Homey.log('playLatestEpisode()', device, seriesName)
// Get the device from driver and search for the latest episode of the series
var KodiDriver = Homey.manager('drivers').getDriver('kodi')
KodiDriver.getLatestEpisode(device, seriesName)
.then(
function (episodeToPlay) {
KodiDriver.playEpisode(device, episodeToPlay)
.then(
function () {
// Trigger action kodi_episode_start
Homey.log('Triggering flow kodi_episode_start, tvshow_title: ', episodeToPlay.showtitle, 'episode_title: ', episodeToPlay.label, 'season: ', episodeToPlay.season, 'episode: ', episodeToPlay.episode)
Homey.manager('flow').trigger('kodi_episode_start', {
tvshow_title: episodeToPlay.showtitle,
episode_title: episodeToPlay.label,
season: episodeToPlay.season,
episode: episodeToPlay.episode
})
}
)
.catch(reject)
}
)
Expand Down
79 changes: 74 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"description": {
"en": "Control your Kodi device with Homey!"
},
"version": "0.0.1",
"version": "1.0.0",
"compatibility": "0.x || 1.x",
"category": [
"music",
"video"
],
"author": {
"name": "Marvin Schenkel",
"email": "marvinschenkel@gmail.com"
Expand Down Expand Up @@ -47,6 +51,27 @@
"triggers" : {
"en" : ["stop", "exit", "quit"]
}
},
{
"id": "kodi_next",
"importance": 0.7,
"triggers": {
"en" : ["next track"]
}
},
{
"id": "kodi_previous",
"importance": 0.7,
"triggers": {
"en" : ["previous track"]
}
},
{
"id": "kodi_play_latest_episode",
"importance": 1,
"triggers": {
"en": ["play latest episode of", "play the latest episode of", "play latest episode", "play latest episode of"]
}
}
],
"drivers": [
Expand All @@ -56,8 +81,8 @@
"en": "Kodi"
},
"images": {
"large": "./drivers/kodi/assets/images/large.jpg",
"small": "./drivers/kodi/assets/images/small.jpg"
"large": "./drivers/kodi/assets/images/large.png",
"small": "./drivers/kodi/assets/images/small.png"
},
"class": "videoplayer",
"capabilities": [ "play", "pause", "stop" ],
Expand Down Expand Up @@ -113,8 +138,8 @@
}
],
"images":{
"large":"./assets/kodi_large.png",
"small":"./assets/kodi_small.png"
"large":"./assets/images/large.png",
"small":"./assets/images/small.png"
},
"flow": {
"triggers":[
Expand All @@ -135,6 +160,50 @@
}
]
},
{
"id":"kodi_episode_start",
"title": {
"en":"An episode has started"
},
"tokens":[
{
"name":"tvshow_title",
"title": {
"en":"Show"
},
"example":{
"en":"The Walking Dead"
}
},
{
"name":"episode_title",
"title": {
"en":"Episode"
},
"example":{
"en":"First Time Again"
}
},
{
"name":"season",
"title": {
"en":"Sea #"
},
"example":{
"en":"1"
}
},
{
"name":"episode",
"title": {
"en":"Ep #"
},
"example":{
"en":"2"
}
}
]
},
{
"id":"kodi_pause",
"title": {
Expand Down
Binary file added assets/images/Thumbs.db
Binary file not shown.
Binary file added assets/images/large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/kodi.png
Binary file not shown.
Binary file removed assets/kodi_small.png
Binary file not shown.
Binary file added drivers/kodi/assets/images/Thumbs.db
Binary file not shown.
Binary file modified drivers/kodi/assets/images/large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified drivers/kodi/assets/images/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3921baa

Please sign in to comment.