8 releases

new 0.2.2 Nov 12, 2024
0.2.1 Nov 11, 2024
0.1.6 Oct 22, 2024

#431 in Video

Download history 306/week @ 2024-10-14 279/week @ 2024-10-21 8/week @ 2024-10-28 302/week @ 2024-11-04 283/week @ 2024-11-11

889 downloads per month
Used in 2 crates

MIT and LGPL-3.0+

19KB
358 lines

yt-sub-rs Latest Version GH Actions

yt-sub is a simple CLI for subscribing to YouTube RSS feeds without using a YouTube account. Receive Slack notifications about fresh videos based on the configurable schedule.

Usage

YouTube RSS subscription CLI

Usage: ytsub <COMMAND>

Commands:
  init          Initialize config file [aliases: i]
  settings      Display current settings [aliases: s]
  run           Check and notify about fresh videos [aliases: r]
  channel-data  Get a channel data based on its handle [aliases: d]
  follow        Subscribe to a channel [aliases: f]
  unfollow      Unsubscribe [aliases: u]
  list          List followed channels [aliases: l]
  register      Register remote account [aliases: re]
  unregister    Remove remote account [aliases: un]
  sync          Update remote settings to match local [aliases: sc]
  help          Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Install CLI:

cargo install yt-sub

Initialize the settings file at ~/.config/yt-sub-rs/config.toml:

ytsub init

~/.config/yt-sub-rs/config.toml

channels = []

[[notifiers]]
Log = []

Follow preferred channels based on their URL handle:

ytsub follow --handle @ManofRecaps

Display the list of your channels by typing:

ytsub list

# You are following:
#
# name: Man of Recaps
# handle: @ManofRecaps
# channel_id: UCNCTxLZ3EKKry-oWgLlsYsw
# channel_url: https://www.youtube.com/@ManofRecaps
# RSS feed: https://www.youtube.com/feeds/videos.xml?channel_id=UCNCTxLZ3EKKry-oWgLlsYsw

Now you can run:

ytsub run

# New video - Man of Recaps Rings of Power RECAP: Season 2 https://www.youtube.com/watch?v=CjeUx_HHtF0

to trigger notifications about freshly released videos from your observed channels. The first run invocation will notify you about videos released in the last 7 days. Subsequent runs will inform about videos released since the previous run event.

You can customize this period by appending the --hours-offset option:

# notify about videos published in the last 24 hours
ytsub run --hours-offset 24 

The time of the last run is stored in the ~/.yt-sub-rs/last_run_at.txt file.

You can unfollow a channel by typing:

ytsub unfollow --handle @ManofRecaps

Remote account

By registering a remote account, you'll receive Slack notifications about new videos without executting the CLI locally.

To do it run:

ytsub register

it will persist your API key in the config file. You must configure Slack notifications to use this feature.

If your account is registered follow and unfollow commands will automatically update your remote data. If you change the config file manually, you have to run:

ytsub sync

By default, new videos are checked once every hour. Optionally, you can define a notification schedule like this:

~/.config/yt-sub-rs/config.toml

schedule = [8, 20]

Numbers represent UTC hours when notifications should be sent.

Don't forget to run sync after updating this config.

You can remove all your remote data by running:

ytsub unregister

Notifiers configuration

By default, CLI is configured to log to the stdout. You can configure Slack notifications like this:

~/.config/yt-sub-rs/config.toml

[[notifiers]]

[notifiers.Slack]
webhook_url = "https://hooks.slack.com/services/XXX/XXX/XXX"
channel = "yt-videos"

Slack notification

You can obtain the webhook_url value as described in the Slack docs.

Manually finding an RSS channel_id

CLI will try to find the matching channel_id based on the URL handle. But proxied YouTube API calls are sometimes throttled. So if the follow command fails, you have to obtain this data manually. Go to the channel videos tab and run this JS in the console to extract the RSS channel_id:

document.querySelector('link[rel="alternate"][type="application/rss+xml"]').href.match(/channel_id=([^&]+)/)[1];

This snippet works on Firefox. Alternatively, you can look for this value manually in the source code:

RSS feed

Now you can subscribe by providing all the data like this:

ytsub follow --handle @ManofRecaps --channel-id UCNCTxLZ3EKKry-oWgLlsYsw --desc 'Man of Recaps'

CRON invocation

Alternatively, you can use the CLI via the CRON scheduler to receive notifications without a remote account. By appending the --cron flag to the run command CLI will output the logs with timestamps:

RUST_LOG=info ytsub run --cron

# [2024-10-14T13:03:58Z INFO  yt_sub::logger] New video - Man of Recaps Rings of Power RECAP: Season 2 https://www.youtube.com/watch?v=CjeUx_HHtF0

This mode of execution is the most useful with Slack notifications configured.

Status

This project is in the early stages of development, so feedback and PRs are welcome.

Dependencies

~7–18MB
~241K SLoC