A long-running Go program that watches a Youtube playlist for new videos, and downloads them using yt-dlp or other preferred tool.

Overview

ytdlwatch

A long-running Go program that watches a Youtube playlist for new videos, and downloads them using yt-dlp or other preferred tool.

Ideal for use with Plex, and comes with a mechanism for deleting watched videos from a Plex Library.

  1. Add a video to YouTube playlist
  2. Video appears in Plex library shortly

install

The Go Toolchain is required.

The following will install ytdlwatch to $GOPATH/bin:

go install github.com/raine/ytdlwatch@latest

To build for another platform, clone the repository and run go build like so:

env GOOS=target-OS GOARCH=target-architecture go build .

youtube playlist watching

One method of triggering ytdlwatch to download videos is by watching a playlist for new videos on YouTube.

setup

  1. Create a project and an API key for accessing the Youtube API: https://console.cloud.google.com/apis/credentials

  2. Enable access to YouTube API at https://console.developers.google.com/apis/api/youtube.googleapis.com/overview

  3. Create a new playlist on Youtube. The playlist can be public or unlisted, but not private. In Playlist Settings, enable the setting "Add new videos to top of playlist" (screenshot). Needed so that the program only ever has to read the first page of playlist's items, and API quota does not have to be used for deleting videos.

    Could the personal "Watch later" playlist be used? Unfortunately not, since it's not available through the official API.

  4. Run ytdlwatch with the environment variables listed below set up.

See also the example systemd service: ytdlwatch.service.example

http api

The program can be made to listen for HTTP requests that include video URL to be downloaded.

  1. Define the PORT environment variable
  2. Send a POST request to path /download with video URL as the body.

curl example

curl -X POST http://localhost:8080/download -d'https://www.youtube.com/watch?v=dQw4w9WgXcQ'

plex integration (optional)

automatically delete watched videos

One use case for ytdlwatch is to download videos into a Plex library. That part is doable by just creating a new library in Plex, and adding the directory at OUTPUT_PATH as media source. What maybe remains desired is a mechanism for automatically deleting watched videos. You can make ytdlwatch to delete watched videos periodically by configuring the Plex related environment variables below.

video metadata

Plex can read Youtube metadata embedded to video files (--embed-metadata), so using the YouTube-Agent is not strictly necessary, especially if you don't care about video metadata, however, Plex reads metadata only from a mp4 container, so yt-dlp arguments (YOUTUBE_DL_ARGS) need to be adjusted accordingly to only produce mp4 containers.

So probably a more reliable and less-hassle way is to use the YouTube-Agent, although setting it up requires some work. Youtube-Agent's README is not the most helpful so small setup guide here:

  1. Locate the plug-ins folder for your Plex server: https://support.plex.tv/articles/201106098-how-do-i-find-the-plug-ins-folder/
  2. Clone the Youtube-Agent in that directory: git clone https://github.com/ZeroQI/YouTube-Agent.bundle
  3. Restart plex media server.
  4. In Plex web UI, configure Youtube API key for the Youtube-Agent.
  5. In Plex web UI, configure your video library that you use ytdlwatch with to use Youtube-Agent as agent.

Note that video filenames produced by yt-dlp need to contain the video id. This is configured as default in ytdlwatch.

env vars

  • LOG_LEVEL: Log level of the program. Defaults to info.
  • PORT: The port http server will bind to.
  • YOUTUBE_API_KEY: Youtube API key. Needed for accessing the given Youtube playlist. Create one here (and a new project, if necessary): https://console.cloud.google.com/apis/credentials required
  • YOUTUBE_PLAYLIST_ID: An ID for the Youtube playlist that is monitored by the program. You can see this in browser's page URL when viewing a playlist on Youtube. A long string that begins with characters PL. required
  • OUTPUT_PATH: A path to a directory where videos should be downloaded to. required
  • YOUTUBE_DL_PATH: Path to executable that is used to download videos from Youtube. Defaults to yt-dlp, which is a fork of youtube-dl.
  • YOUTUBE_DL_ARGS: Parameters passed to the executable configured above. This can be used to override the default parameters used by ytdlwatch. If set, OUTPUT_PATH has no effect, and --paths <output path> has to be manually included in the args, if desired.
  • PLEX_API_TOKEN: Plex API Token. This official support article has details on how to obtain it: Finding an authentication token / X-Plex-Token
  • PLEX_API_URL: URL to Plex server. This might be something like http://localhost:32400.
  • PLEX_LIBRARY_KEY: Key to the Plex library where YouTube videos are added to. The program will delete watched videos from this library. You can find the key by opening a library with browser in Plex UI and checking page URL for a query parameter like source=7.

development

The project uses just as a command runner (or make alternative).

See just -l for recipes.

You might also like...
Plays videos using Prometheus, e.g. Bad Apple.
Plays videos using Prometheus, e.g. Bad Apple.

prom_bad_apple Plays videos using Prometheus, e.g. Bad Apple. Inspiration A while back I thought this blog post and the corresponding source code were

quick debug program running in the k8s pod
quick debug program running in the k8s pod

quick-debug English | 中文 What Problem To Solve As the k8s becomes more and more popular, most projects are deployed in k8s, and so is the development

Turn your Go program(s) into an appliance running on the Raspberry Pi 3 or 4 (or on amd64 PCs!)

Overview gokrazy packs your Go application(s) into an SD card image for the Raspberry Pi 3 or 4 which — aside from the Linux kernel and proprietary Ra

Tape backup software optimized for large WORM data and long-term recoverability

Mixtape Backup software for tape users with lots of WORM data. Draft design License This codebase is not open-source software (or free, or "libre") at

Grafana Mimir provides horizontally scalable, highly available, multi-tenant, long-term storage for Prometheus.
Grafana Mimir provides horizontally scalable, highly available, multi-tenant, long-term storage for Prometheus.

Grafana Mimir Grafana Mimir is an open source software project that provides a scalable long-term storage for Prometheus. Some of the core strengths o

How to get a Go / Golang app using the Gin web framework running natively on Windows Azure App Service WITHOUT using a Docker container

Go on Azure App Service View the running app - https://go-azure-appservice.azurewebsites.net 😎 This is an example repo of how to get a Go / Golang a

A simple tool who pulls data from Online.net API and parse them to a Prometheus format

Dedibox backup monitoring A simple tool who reads API from Online.net and parse them into a Prometheus-compatible format. Conceived to be lightweight,

 The Ultimate Engineer Toolbox YouTube 🔨 🔧
The Ultimate Engineer Toolbox YouTube 🔨 🔧

The Ultimate Engineer Toolbox YouTube 🔨 🔧

A shields.io API for your youtube channel to protect your api key
A shields.io API for your youtube channel to protect your api key

Youtube-Channel-Badge A shields.io API for your youtube channel to protect your

Owner
Raine Virta
Raine Virta
Watches for zips and unzips them

unziploc Watches for zips/tars/rars and unzips them Options: PATHS = /data #Comma seperated list of paths to watch WRITE_DELAY = 1m #How long to wait

null 1 Nov 28, 2021
A go (golang) library to search videos in YouTube.

YT Search A go (golang) library to search videos in YouTube. Installation go get github.com/AnjanaMadu/YTSearch Usage package main import ( "fmt"

Anjana Madu 4 Oct 1, 2022
A simple go application that uses Youtube Data API V3 to show the real-time stats for a youtube channel such as the subs, views, avg. earnings etc.

Youtube-channel-monitor A simple go application that uses Youtube Data API V3 to show the real-time stats for a youtube channel such as the subs, view

null 0 Dec 30, 2021
Orchestra is a library to manage long running go processes.

Orchestra Orchestra is a library to manage long running go processes. At the heart of the library is an interface called Player // Player is a long ru

Stephen Afam-Osemene 111 Oct 21, 2022
S3pd - CLI utility that downloads multiple s3 objects at a time, with multiple range-requests issued per object

S3 Parallel Downloader CLI utility that downloads multiple s3 objects at a time,

Colin Bookman 2 May 13, 2022
A kubernetes controller that watches the Deployments and “caches” the images

image-cloner This is just an exercise. It's a kubernetes controller that watches

Luca Sepe 1 Dec 20, 2021
A kubernetes operator demo generated by code-generator, it only watches cr's events

intro a small operator demo which only watches car cr's events. environment: ubuntu-20.04-amd64 k3s-1.21 docker-20.10.7 go-1.17 tools code-generator d

shank 0 Dec 13, 2021
A Controller written in kubernetes sample-controller style which watches a custom resource named Bookstore

bookstore-sample-controller A Controller written in kubernetes sample-controller style which watches a custom resource named Bookstore. A resource cre

Abdullah Al Shaad 0 Jan 20, 2022
Application open new tab in chrome when your favourite youtuber add new video.

youtube-opener This application open new tab in Chrome when your favourite youtuber add new video. It checks channel every one minute. How to run go r

null 1 Jan 16, 2022
kitex running in kubernetes cluster and discover each other in kubernetes Service way

Using kitex in kubernetes Kitex [kaɪt'eks] is a high-performance and strong-extensibility Golang RPC framework. This go module helps you to build mult

adolli 1 Feb 21, 2022