https://github.com/matt8707/youtube-watching
📦 Containerized app to get latest video from watch history
https://github.com/matt8707/youtube-watching
home-assistant thumbnail youtube
Last synced: about 1 year ago
JSON representation
📦 Containerized app to get latest video from watch history
- Host: GitHub
- URL: https://github.com/matt8707/youtube-watching
- Owner: matt8707
- License: mit
- Created: 2022-08-17T22:43:29.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-01T06:35:44.000Z (over 2 years ago)
- Last Synced: 2025-04-10T23:52:33.996Z (about 1 year ago)
- Topics: home-assistant, thumbnail, youtube
- Language: Python
- Homepage:
- Size: 29.3 KB
- Stars: 14
- Watchers: 5
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# youtube-watching
A containerized flask app to get the latest video from your YouTube watch history. This is as a workaround for YouTube Data API v3 deprecating "watchHistory".
```bash
curl http://127.0.0.1:5678
```
```json
{
"channel": "Bad Friends",
"title": "Bobby's Bank Heist | Ep 129 | Bad Friends",
"video_id": "7bT2zdzWAM4",
"duration_string": "1:16:48",
"thumbnail": "https://i.ytimg.com/vi/7bT2zdzWAM4/hqdefault.jpg",
"original_url": "https://www.youtube.com/watch?v=7bT2zdzWAM4"
}
```
## Cookies
To authenticate with youtube, you need to set a HTTP Cookie File.
> "In order to extract cookies from browser use any conforming browser extension for exporting cookies. For example, [Get cookies.txt LOCALLY](https://chrome.google.com/webstore/detail/get-cookiestxt-locally/cclelndahbckbenkjhflpdbgdldlbecc) (for Chrome) or [cookies.txt](https://addons.mozilla.org/en-US/firefox/addon/cookies-txt/) (for Firefox)".
## Install
Pull and run with docker-compose.
```bash
cd docker-compose && \
docker-compose up -d youtube-watching
```
```yaml
version: '3'
services:
youtube-watching:
container_name: youtube-watching
image: ghcr.io/matt8707/youtube-watching
volumes:
- /volume1/docker/youtube-watching/config:/youtube-watching/config/
environment:
- COOKIE=./config/youtube.com_cookies.txt
network_mode: bridge
ports:
- 5678:5678
restart: always
```
## Build
You can also build the image with docker-compose.
```bash
cd docker-compose && \
docker-compose up -d --build youtube-watching
```
```yaml
version: '3'
services:
youtube-watching:
container_name: youtube-watching
build:
context: /volume1/docker/youtube-watching/
dockerfile: /volume1/docker/youtube-watching/Dockerfile
volumes:
- /volume1/docker/youtube-watching/config:/youtube-watching/config/
environment:
- COOKIE=./config/youtube.com_cookies.txt
network_mode: bridge
ports:
- 5678:5678
restart: always
```
## Home Assistant
The "YouTube" Apple TV app doesn't expose artwork through AirPlay, so the Home Assistant `apple_tv` integration can't show an `entity_picture`. This is an example to get the thumbnail.
**Note:** It's now possible without this container https://github.com/matt8707/hass-config/commit/ad624e0da9520a2b304f82a57b92c2b6f289a4ad
```yaml
rest:
- resource: http://192.168.1.241:5678
sensor:
name: youtube_watching
value_template: >
{{ value_json.thumbnail }}
json_attributes:
- channel
- title
- video_id
- duration_string
- original_url
scan_interval: 86400
automation:
- alias: update_youtube_watching_thumbnail
id: '1781428593188'
mode: single
max_exceeded: silent
variables:
ytw: sensor.youtube_watching
trigger:
platform: state
entity_id:
- media_player.vardagsrum
- media_player.sovrum
to: playing
condition: >
{{ is_state_attr(trigger.entity_id, 'app_id', 'com.google.ios.youtube') and
state_attr(trigger.entity_id, 'media_title') != state_attr(ytw, 'title') }}
action:
- service: homeassistant.update_entity
target:
entity_id: '{{ ytw }}'
```