forked from josephschmitt/alexa-libby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for displaying cards in the Alexa app (josephschmitt#10)
This requires providing an API key for TMDB, which is where we get the artwork from. You can do so in the config in the new `artwork` section: ``` "server": {...}, "movies": {...}, "shows": {...}, "artwork": { "tmdbApiKey": "abcdefghijklmnopqrstuvwxyz123456" } ``` Once configured correctly, a card will be displayed for Movies and Shows in the Alexa app (or in the Echo Show if you have one) after checking if a movie or show is already on your list, or after adding a new movie or show.
- Loading branch information
1 parent
2c9bc28
commit 6f8fb5e
Showing
16 changed files
with
256 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function buildCard(title, image, text) { | ||
return { | ||
type: 'Standard', | ||
title, | ||
text, | ||
image | ||
}; | ||
} |
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,63 @@ | ||
import config from 'config'; | ||
import themoviedbclient from 'themoviedbclient'; | ||
|
||
/** | ||
* @typedef {Object} ArtworkOptions | ||
* @property {String} [tmdbId] | ||
* @property {String} [tvdbId] | ||
* @property {String} [imdbId] | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} ArtworkImages | ||
* @property {String} smallImageUrl | ||
* @property {String} largeImageUrl | ||
*/ | ||
|
||
/* Dumb workaround to make this easier to stub and test */ | ||
export const API = { | ||
Client: themoviedbclient | ||
}; | ||
|
||
/** | ||
* Fetches TMDB for artwork for a MediaResult and returns a large and small image url for use in a | ||
* skill card. | ||
* | ||
* @param {ArtworkOptions} options -- An object with a tmdb, tvdb, or imdb id on it. Usually a | ||
* MediaResult from one of the API clients. | ||
* @returns {PromiseLike<ArtworkImages>} | ||
*/ | ||
export default async function getArtwork({tmdbId, tvdbId, imdbId}) { | ||
if (!(tmdbId || tvdbId || imdbId)) { | ||
throw new Error('You must provide a valid tmdbId, tvdbId, or imdbId to fetch artwork'); | ||
} | ||
|
||
try { | ||
const apiKey = config.get('alexa-libby.artwork.tmdbApiKey'); | ||
const tmdb = new API.Client(apiKey); | ||
tmdb.configure({ssl: true}); | ||
|
||
let media; | ||
if (tmdbId) { | ||
media = await tmdb.call(`/movie/${tmdbId}`); | ||
} | ||
else { | ||
const results = await tmdb.call(`/find/${tvdbId || imdbId}`, { | ||
external_source: tvdbId ? 'tvdb_id' : 'imdb_id' | ||
}); | ||
media = results.tv_results.length ? results.tv_results[0] : results.movie_results[0]; | ||
} | ||
|
||
if (!media) { | ||
return null; | ||
} | ||
|
||
return { | ||
smallImageUrl: tmdb.getImageUrl(media.poster_path, 'w780'), | ||
largeImageUrl: tmdb.getImageUrl(media.poster_path, 'w1280') | ||
}; | ||
} | ||
catch (e) { | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.