Skip to content

Commit

Permalink
Merge pull request #295 from fcusson/master
Browse files Browse the repository at this point in the history
retro compat for 3.8 and documentation for getting sp_dc and sp_key
  • Loading branch information
fcusson authored Feb 11, 2022
2 parents 20f1264 + b0e4714 commit 4894887
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 25 deletions.
61 changes: 42 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Spotcast

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs)
[![spotcast](https://img.shields.io/github/release/fondberg/spotcast.svg?1)](https://github.com/fondberg/spotcast)
![Maintenance](https://img.shields.io/maintenance/yes/2021.svg)

[![Buy me a coffee](https://img.shields.io/static/v1.svg?label=Buy%20me%20a%20coffee&message=🥨&color=black&logo=buy%20me%20a%20coffee&logoColor=white&labelColor=6f4e37)](https://www.buymeacoffee.com/fondberg)

# Spotcast

Home Assistant custom component to start Spotify playback on an idle chromecast device or a Spotify Connect device (thanks to @kleinc80) which means that you can target your automation for chromecast as well as connect devices.

This component is not meant to be a full Spotify chromecast media_player but only serves to start the playback. Controlling the chromecast device and the Spotify playback after the initial start is done in their respective components.
Expand Down Expand Up @@ -39,30 +39,53 @@ Note that as of v3.5.2 you must also have the official [Home Assistant Spotify I

Spotcast uses two cookies to authenticate against Spotify in order to have access to the required services.

To obtain the cookies:
To obtain the cookies, these different methods can be used:

#### Chrome based browser

##### Settings page

1. Make sure you are connected on [`https://open.spotify.com`](https://open.spotify.com)
2. Open the url [`chrome://settings/cookies/detail?site=spotify.com`](chrome://settings/cookies/detail?site=spotify.com)
3. Copy the content from `sp_dc` and `sp_key` cookies

![cookie in chrome settings](images/cookies_chrome_1.png)

##### Chrome web console

1. Make sure [`https://open.spotify.com`](https://open.spotify.com) is opened and you are connected

2. Press `Command+Option+I` (Mac) or `Control+Shift+I` or `F12`. This should open the developer tools menu of your browser.
3. Go into the `application` section
4. In the menu on the left go int `Storage/Cookies/open.spotify.com`
5. Find the `sp_dc` and `sp_key` and copy the values

![cookie in chrome developer tools](images/cookies_chrome_2.png)

#### Firefox based browser

* Using Chrome or Edge
##### Firefox web console

>* Open url [`chrome://settings/cookies/detail?site=spotify.com`](chrome://settings/cookies/detail?site=spotify.com)
>* If no cookies appear go to [`https://open.spotify.com`](https://open.spotify.com) and sign-in
>* Copy content from `sp_dc` and `sp_key` cookies
1. Make sure [`https://open.spotify.com`](https://open.spotify.com) is opened and you are connected
2. Press `Command+Option+I` (Mac) or `Control+Shift+I` or `F12`. This should open the developer tools menu of your browser.
3. Go into the `Storage` section. (You might have to click on the right arrows to reveal the section)
4. Select the `Cookies` sub-menu and then `https://open.spotify.com`
5. Find the `sp_dc` and `sp_key` and copy the values

* Using another browser
![Firefox developer tool](images/cookies_firefox_1.png)

>* Use a browser extension like "Export cookies" and look for `sp_dc` and `sp_key` cookies
#### Other methods

or
##### Incognito mode

>* Open a new __Incognito window__ at [https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2F](https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2F)
>* Open Developer Tools in your browser (might require developer menu to be enabled in some browsers)
>* Login to Spotify
>* Search/Filter for `get_access_token` in Developer tools under Network.
>* Under cookies for the request save the values for `sp_dc` and `sp_key`
>* Close the window without logging out (Otherwise the cookies are made invalid)
>
>![Screenshots](images/cookies_1.jpg)
1. Open a new __Incognito window__ at [https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2F](https://accounts.spotify.com/en/login?continue=https:%2F%2Fopen.spotify.com%2F)
2. Open Developer Tools in your browser (might require developer menu to be enabled in some browsers)
3. Login to Spotify
4. Search/Filter for `get_access_token` in Developer tools under Network.
5. Under cookies for the request save the values for `sp_dc` and `sp_key`
6. Close the window without logging out (Otherwise the cookies are made invalid)

* Alternatively you can use a browser plugin like "Export cookies".
![Screenshots](images/cookies_1.jpg)

### Single account

Expand Down
2 changes: 2 additions & 0 deletions custom_components/spotcast/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import collections
import logging
import time
Expand Down
2 changes: 2 additions & 0 deletions custom_components/spotcast/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.components import websocket_api
Expand Down
2 changes: 2 additions & 0 deletions custom_components/spotcast/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import asyncio
import logging
import requests
Expand Down
2 changes: 2 additions & 0 deletions custom_components/spotcast/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Sensor platform for Chromecast devices."""
from __future__ import annotations

import collections
import json
import logging
Expand Down
2 changes: 2 additions & 0 deletions custom_components/spotcast/spotcast_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import collections
import logging
import random
Expand Down
2 changes: 2 additions & 0 deletions custom_components/spotcast/spotify_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Controller to interface with Spotify.
"""
from __future__ import annotations

import logging
import threading
import requests
Expand Down
Binary file added images/cookies_chrome_1.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 images/cookies_chrome_2.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 images/cookies_firefox_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# Spotcast

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) [![spotcast](https://img.shields.io/github/release/fondberg/spotcast.svg?1)](https://github.com/fondberg/spotcast) ![Maintenance](https://img.shields.io/maintenance/yes/2021.svg)

[![Buy me a coffee](https://img.shields.io/static/v1.svg?label=Buy%20me%20a%20coffee&message=🥨&color=black&logo=buy%20me%20a%20coffee&logoColor=white&labelColor=6f4e37)](https://www.buymeacoffee.com/fondberg)

# Spotcast
Home Assistant custom component to start Spotify playback on an idle chromecast device or a Spotify Connect device.

This component is not meant to be a full Spotify chromecast media_player but only serves to start the playback. Controlling the chromecast device and the Spotify playback after the initial start is done in their respective components.
Because starting playback using the API requires more powerful token the username and password used for browser login is used.

Used by https://github.com/custom-cards/spotify-card.
Used by [Spotify Card](https://github.com/custom-cards/spotify-card).

# Minimal Configuration
## Minimal Configuration

## Minimum Home Assistant version
### Minimum Home Assistant version

Spotcast is compatible with any version since 2021.12.0.

## Official Spotify integration
### Official Spotify integration

Note that since v3.5.2 you must also have the official [Home Assistant Spotify Integration](https://www.home-assistant.io/integrations/spotify/) installed and configured for this custom component to work. This is because it provides the correct device list which has the correct scopes in its token.

## Single account
### Single account

Add the following to your config

```yaml
spotcast:
sp_dc: !secret sp_dc
Expand Down

0 comments on commit 4894887

Please sign in to comment.