Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
af27ca5
Fix command not working the first time
jinxo13 Jul 24, 2020
5590714
updated broken youtube search library
jinxo13 Jul 25, 2020
79218a0
Added ping, and graceful shutdown
jinxo13 Dec 6, 2020
d76f8ed
merged
jinxo13 Dec 6, 2020
bb045b3
Some renames and added more comments
jinxo13 Dec 7, 2020
e06069c
change logging level to INFO
jinxo13 Dec 7, 2020
a8c708d
Changed youtube search to youtube-dl
jinxo13 Dec 7, 2020
a356267
Added restart function
jinxo13 Dec 16, 2020
278491b
fixed restart
jinxo13 Dec 16, 2020
ce49a08
Updated restart function
jinxo13 Dec 16, 2020
433e11a
remove error on no subscriptions
jinxo13 Dec 17, 2020
03518b2
change youtube seearch to 10 results
jinxo13 Feb 14, 2021
aa4481f
Minor refactor changes
jinxo13 Feb 14, 2021
9bd8330
Added plex support
jinxo13 Jun 12, 2021
f9305b6
Added open app intent handler
jinxo13 Jun 12, 2021
4d9249c
Added rewind intent handler
jinxo13 Jun 12, 2021
99582f9
Fix play on app
jinxo13 Jun 12, 2021
74835c9
fixed plex variables
jinxo13 Jun 12, 2021
76dc6c8
Added more Plex commands
jinxo13 Jun 14, 2021
75fb5f9
Added more Plex commands
jinxo13 Jun 14, 2021
a0778fd
Working on Plex
jinxo13 Jun 15, 2021
a55d847
Added shuffle and looping for Plex
jinxo13 Jun 16, 2021
46a0511
Added integration tests
jinxo13 Jun 29, 2021
e319bf5
Updated readme
jinxo13 Jun 29, 2021
fded944
Update README.markdown
jinxo13 Jun 29, 2021
a0d2518
Update README.markdown
jinxo13 Jun 29, 2021
c45d095
Update README.markdown
jinxo13 Jun 29, 2021
314a7c0
Merge branch 'Pizzaface:master' into master
jinxo13 Jun 29, 2021
8a14b87
Change YouTube search to use the Google API v3
jinxo13 Jul 3, 2021
909ac72
Fix for Issue#46, when installing from a folder with a space.
jinxo13 Jul 3, 2021
260f4a5
Improved language support
jinxo13 Jul 15, 2021
06cb03d
Restructured to allow language support
jinxo13 Jul 17, 2021
dac7d8e
Update stan_controller.py
jinxo13 Jul 17, 2021
d82722d
A couple of fixes
jinxo13 Jul 17, 2021
82c562a
Updated en-AU to en for interaction_model.json
jinxo13 Jul 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ lambda/node_modules
hooks/
__pycache__
*.log
*.log.*
*.log.*
venv
/.vscode/
/.idea/
/sonar-project.properties
/.scannerwork/report-task.txt
/.scannerwork/.sonar_lock
/.coverage
128 changes: 102 additions & 26 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Alexa Chromecast Skill

Allows Amazon Alexa to control Google Chromecast
Allows Amazon Alexa to control your Google Chromecast

This skill supports controlling a single Chromecast or multiple Chromecasts in different rooms.
Each Alexa device can be set to control a different room. This is done by matching the room name to your Chromecast device's name.
Expand All @@ -17,25 +17,88 @@ You can control another room by saying something like:
To change the room a particular Alexa device controls you can say:
> Alexa, ask the Chromecast to set the room

Here are some example voice commands:

> Alexa, tell Chromecast to play

> Alexa, tell Chromecast to play songs by Macklemore

> Alexa, tell Chromecast to play maroon 5 playlist

> Alexa, tell Chromecast to play The Matrix trailer

> Alexa, tell Chromecast to set the volume to 5

> Alexa, tell Chromecast to stop

Or:

> Alexa, ask the Chromecast in the Media Room to stop
### Standard commands
The following media commands are available:
```
VOICE COMMAND ACTION
--------------------------------------------------------------------------------
pause -> Pause a playing item
play -> Play a paused item
stop -> Stop the currently playing item
set volume to 5 -> Change the volume between 0 and 10
mute -> mute the volume
unmute -> unmute the volume
rewind -> Rewind back 15 seconds ("skip back" or "go back" also work)
rewind 30 seconds -> Rewind back 30 seconds
fast forward -> Fast forward 15 seconds ("skip forward" or "go forward" also work)
fast forward 1 minute -> Fast forward 1 minute
restart -> Restarts the media item from the beginning
next -> Play or show the next item
previous -> Play or show the previous item
open {app} -> Open a specific app. Plex and YouTube are supported.
```
NOTE: Stop doesn't work as expected on the Netflix app and will quit the app instead.

### YouTube app commands
Play items on YouTube.
```
VOICE COMMAND ACTION
--------------------------------------------------------------------------------
play/find {title} -> Play videos matching the title
play/find videos of {title} -> Play videos matching the title
play/find the trailer for {title} -> Play trailers matching title
play/find the show {title} -> Play a Youtube show matching the title
play/find the movie {title} -> Play a Youtube movie matching the title
play/find the song {title} -> Play a song matching the title
play/find the album {title} -> Play an album matching the title
play/find the playlist {title} -> Play a playlist matching the title
play/find songs by {artist} -> Play songs by the specified artist
```

> Alexa, ask the Chromecast to play in the Media Room
### Plex app commands
Find and play items on your Plex server.
```
VOICE COMMAND ACTION
---------------------------------------------------------------------------------
play -> Resumes from pause, or plays the displayed item
stop -> Stops playing and displays the item details
play/find {title} -> Play/Find the title
play/find the video {title} -> Play/Find the title
play/find the tv show {title} -> Play/Find a tv show matching the title
play/find the movie {title} -> Play/Find a movie matching the title

play the song {title} -> Play a song matching the title
play/find the album {title} -> Play/Find an album matching the title
shuffle the album {title} -> Play an album matching the title in shuffled order
play/find songs by {artist} -> Play/Find songs by the specified artist
shuffle songs by {artist} -> Play songs by the specified artist in shuffled order
play/find the playlist {title} -> Play/Find a playlist matching the title

play/shuffle photos from {year} -> Play/Shuffle photos from the specified year
play/shuffle photos from {month} {year} -> Play/Shuffle photos from the specified month and year
play/shuffle photos from {title} -> Play/Shuffle photos from albums matching the title

set/change quality to {level} -> Transcode the media to "low" (480p), "medium" (720p), "high" (1080p) or "maximum".
raise/lower the quality -> Increase or lower the video quality from the current setting
turn on subtitles -> Turns on subtitles in the configurged language
turn off subtitles -> Turns off subtitles
switch audio -> Switches to another audio track if available (e.g. to the directors commentry)

play/find the episode {title} of {show} -> Play/Find the specified show episode by the title
play/find season {#} episode {#} of {show} -> Play/Find the specified show episode by the season and episode number
```

## Example Commands
> Alexa, ask Chromecast to pause
>
> Alexa, ask Chromecast to resume
>
> Alexa, ask Chromecast to rewind 2 minutes
>
> Alexa, ask Chromecast to play Mythic Quest on Plex
>
> Alexa, ask Chromecast to play The Matrix trailer

## How it works

Expand Down Expand Up @@ -65,7 +128,7 @@ Installation requires a UNIX environment with:
3. Go to [ASK Console](https://developer.amazon.com/alexa/console/ask) and choose "Create Skill"
4. Select "Custom" and "Provision your own", then click "Create skill". On the template screen just use the "Hello World Skill" template
5. Click on "Interaction Model" in the left menu, then "JSON Editor"
6. Copy and paste the content from `config/interaction_model.json` into the editor, then click "Save Model"
6. Copy and paste the content from `config/en/interaction_model.json` into the editor, then click "Save Model"
7. Click on "Endpoint" in the left menu. Enter the Lambda function ARN by the aws-setup.sh. Click "Save Endpoints"
8. Click on "Invocation" in the left menu. Click on "Build Model"
9. Click on the "Test" tab. Enter
Expand All @@ -90,10 +153,24 @@ When run you should see something like the following:
2020-07-12 11:10:47,344 - local.SkillSubscriber - INFO - Received subscription confirmation...
2020-07-12 11:10:47,431 - local.SkillSubscriber - INFO - Subscribed.
```
### Finally
### Setup the Chromecast that Alexa will control
12. Say "Alexa ask Chromecast to play"
The skill will take you through any required room setup.

### Setup connection to Youtube
After running the skill as below `.custom_env` file will be created.

Fill out the required Youtube API Key to allow the skill to connect to Youtube.

To get a key follow the instructions here: https://sns-sdks.lkhardy.cn/python-youtube/getting_started/

### Setup connection to Plex
Fill out the required Plex variables to allow the skill to connect to Plex.

To get the required token https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/

## Running Alexa Chromecast Skill

### Shell example

`./start.sh`
Expand All @@ -116,29 +193,25 @@ The skill subscriber (local) uses these environment variables:

If you have run `aws configure`, you will not need to set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or AWS_DEFAULT_REGION.

## Scripts
## Supporting Scripts

### aws-setup.sh

Sets up an AWS environment for the Alexa Skill:

1. Creates an IAM role for Alexa (with permissions for SNS)
2. Creates an SNS topic to communicate over
3. Creates an S3 persistent store for persisting the room to Alexa device mapping
4. Creates a Lambda function

### build-lambda-bundle.sh

Creates a lambda-bundle.zip, which can be uploaded to an AWS Lambda function.

### aws-update-lambda.sh

Runs build-lambda-bundle and automatically uploads the bundle to AWS Lambda.


## FAQ

### "No Chromecasts found"
### No Chromecasts found
When the local service starts it searches for Chromecasts on the network. If there are no ChromeCasts found, it will exit.
To fix this, you must confirm that the Chromecast is on and working, make sure you can access it from your phone, and make sure that everything is on the same network.
To debug, a tool to search and list found ChomeCasts is provided at `./search-chromecasts` (make sure to make it executable with `chmod +x ./search-chromecasts`).
Expand All @@ -158,3 +231,6 @@ e.g. to use port 30000 run `./start.sh -p 30000` or `./docker-start.sh -p 30000`
### Alexa accepted the command but it didn't seem to work
1. Check the local listener output, it should show the received command and any error that was encountered
2. To check the docker service logs run something like `docker logs alexa_chromecast --since=30m`, which shows the logs for the last 30 minutes
3. If the command wasn't received then try restarting the service. Consider scheduling a daily restart if it's a common issue.
e.g.
`docker restart alexa_chromecast`
4 changes: 2 additions & 2 deletions aws-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ -z "$(type zip)" ]; then
exit 1
fi

source ./config/variables
source ./config/aws_variable_names

if [ -z "$(type aws)" ]; then
echo "aws not found. Installing AWS CLI tools."
Expand All @@ -46,7 +46,7 @@ rm -f .env
AWS_DEFAULT_REGION="$( /usr/bin/awk -F' = ' '$1 == "region" {print $2}' ~/.aws/config )"
# Create Role
echo "Creating $ROLE_NAME role."
role_response=$(aws iam create-role --role-name $ROLE_NAME --assume-role-policy-document file://$(pwd)/config/aws-lambda-role-policy.json)
role_response=$(aws iam create-role --role-name $ROLE_NAME --assume-role-policy-document file://config/aws-lambda-role-policy.json)
role_arn=$(echo $role_response | python3 -c "import sys, json; print(json.load(sys.stdin)['Role']['Arn'])")
aws iam attach-role-policy --role-name $ROLE_NAME --policy-arn arn:aws:iam::aws:policy/AmazonSNSFullAccess
aws iam attach-role-policy --role-name $ROLE_NAME --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Expand Down
2 changes: 1 addition & 1 deletion aws-teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

cd $(dirname $0)

source ./config/variables
source ./config/aws_variable_names

if [ -f .env ]; then
source .env
Expand Down
2 changes: 1 addition & 1 deletion aws-update-lambda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e -o pipefail

cd $(dirname $0)

source config/variables
source config/aws_variable_names

./build-lambda-bundle.sh

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions config/custom_variables
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
############ Custom parameters #################
# PLEX Config - configure if you want to find and play items on Plex
export PLEX_IP_ADDRESS=
export PLEX_PORT=32400
# Refer here on steps to get your token
# https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/
export PLEX_TOKEN=
export PLEX_SUBTITLE_LANG=eng

# YouTube Config - configure if you want to find and play items on YouTube
# To get a key follow the instructions here: https://sns-sdks.lkhardy.cn/python-youtube/getting_started/
export YOUTUBE_API_KEY=
################################################
Loading