Standardize searching for movies with optional release date (#17)

* Don’t filter locally for year
* Add new utterance for searching by year
* Standardize release date query building
* Update README with new utterances
* Version bump to 1.1.1
This commit is contained in:
Joseph J. Schmitt 2016-10-30 13:03:20 -04:00 committed by GitHub
parent eaf8f70c4f
commit 8eeb0ae515
5 changed files with 38 additions and 18 deletions

View File

@ -4,8 +4,9 @@ This is a skill built for Amazon's Alexa service that tells you about your Couch
allows you to ask Alexa the following:
> Alexa, ask Couch Potato to add The Godfather
> Alexa, ask Couch Potato to add The Godfather released in 1974
> Alexa, ask Couch Potato if The Dark Knight is on the list
> Alexa, ask Couch Potato if Batman 1989 is on the list
If you're just getting started developing skills for Alexa, I'd recommend reading [Getting Started
with the Alexa Skills

View File

@ -19,6 +19,13 @@ AddMovie add {The Avengers|movieName} from {releaseDate}
AddMovie add {The Dark Knight|movieName} from {releaseDate}
AddMovie add {Live or Let Die|movieName} from {releaseDate}
AddMovie add {The Godfather|movieName} year {releaseDate}
AddMovie add {Star Wars|movieName} year {releaseDate}
AddMovie add {Star Wars Episode Four A New Hope|movieName} year {releaseDate}
AddMovie add {The Avengers|movieName} year {releaseDate}
AddMovie add {The Dark Knight|movieName} year {releaseDate}
AddMovie add {Live or Let Die|movieName} year {releaseDate}
AddMovie add {The Godfather|movieName} released in {releaseDate}
AddMovie add {Star Wars|movieName} released in {releaseDate}
AddMovie add {Star Wars Episode Four A New Hope|movieName} released in {releaseDate}
@ -68,6 +75,13 @@ FindMovie if {The Avengers|movieName} from {releaseDate} is on the list
FindMovie if {The Dark Knight|movieName} from {releaseDate} is on the list
FindMovie if {Live or Let Die|movieName} from {releaseDate} is on the list
FindMovie if {The Godfather|movieName} year {releaseDate} is on the list
FindMovie if {Star Wars|movieName} year {releaseDate} is on the list
FindMovie if {Star Wars Episode Four A New Hope|movieName} year {releaseDate} is on the list
FindMovie if {The Avengers|movieName} year {releaseDate} is on the list
FindMovie if {The Dark Knight|movieName} year {releaseDate} is on the list
FindMovie if {Live or Let Die|movieName} year {releaseDate} is on the list
FindMovie is {The Godfather|movieName} released in {releaseDate} already
FindMovie is {Star Wars|movieName} released in {releaseDate} already
FindMovie is {Star Wars Episode Four A New Hope|movieName} released in {releaseDate} already

View File

@ -1,6 +1,6 @@
{
"name": "alexa-couchpotato",
"version": "1.1.0",
"version": "1.1.1",
"description": "A skill to ask Alexa about your Couch Potato queue.",
"main": "src/index.js",
"scripts": {

View File

@ -4,9 +4,9 @@ import CouchPotato from 'node-couchpotato';
import {
buildPrompt,
buildMovieQuery,
sendSearchResponse,
formatSearchResults,
parseDate
formatSearchResults
} from './utils.js';
import {
@ -32,16 +32,19 @@ export default function handleLaunchIntent(req, resp) {
}
export function handleFindMovieIntent(req, resp) {
const movieName = req.slot('movieName');
const query = buildMovieQuery(req);
cp.movie.list({search: movieName, limit_offset: NUM_RESULTS}).then(function (searchResp) {
cp.movie.list({
search: query,
limit_offset: NUM_RESULTS
}).then(function (searchResp) {
const movies = searchResp.movies;
if (!movies || !movies.length) {
resp.say(`Couldn't find ${movieName} queued for download. `);
resp.say(`Couldn't find ${query} queued for download. `);
cp.movie.search(movieName).then(function (searchResults) {
sendSearchResponse(searchResults, resp);
cp.movie.search(query).then(function (searchResults) {
sendSearchResponse(searchResults, null, resp);
});
}
else {
@ -57,13 +60,8 @@ export function handleFindMovieIntent(req, resp) {
}
export function handleAddMovieIntent(req, resp) {
const movieName = req.slot('movieName');
const releaseDate = parseDate(req.slot('releaseDate'));
const filterFn = (movie) => movie.year === releaseDate.year;
// Grab more results since we'll end up filtering by date
cp.movie.search(movieName, NUM_RESULTS * 2).then(function (movies) {
movies = formatSearchResults(movies, releaseDate ? filterFn : undefined);
cp.movie.search(buildMovieQuery(req), NUM_RESULTS).then(function (movies) {
movies = formatSearchResults(movies);
sendSearchResponse(movies, movieName, resp);
});

View File

@ -17,6 +17,13 @@ export function buildPrompt(movies) {
return promptData;
}
export function buildMovieQuery(req) {
const movieName = req.slot('movieName');
const releaseDate = parseDate(req.slot('releaseDate'));
return releaseDate ? `${movieName} ${releaseDate.year}` : movieName;
}
export function sendSearchResponse(movies, movieName, resp) {
if (!movies || !movies.length > 0) {
return resp.say('No movie found for ' + movieName).send();
@ -29,7 +36,7 @@ export function sendSearchResponse(movies, movieName, resp) {
.send();
}
export function formatSearchResults(movies, filterFn = () => { return true }) {
export function formatSearchResults(movies) {
if (movies) {
return movies.map((movie) => {
return {
@ -39,7 +46,7 @@ export function formatSearchResults(movies, filterFn = () => { return true }) {
titles: movie.titles,
imdb: movie.imdb
}
}).filter(filterFn);
});
}
return [];