Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
Y

ytcast

> 编程语言
Open source

cast YouTube videos to your smart TV from command-line

799 stars0 likes0 views
WebsiteGitHub

About

cast YouTube videos to your smart TV from command-line

ytcast

cast YouTube videos to your smart TV from command-line.

this program does roughly the same thing as the "Play on TV" button that appears on the player bar when you visit youtube.com with Chrome or when you use the YouTube smartphone app:

Play on TV button

(the feature is also described here).

I don't use Chrome as my daily driver because of reasons and I tend to use my smartphone the least as possible when I'm at home... but still I want the "Play on TV" functionality to watch videos on the big television screen without having to search them with the remote! this is why I wrote this tool. also my computing workflow is "command-line centric" and ytcast fits well in my toolbox (see other tools).

https://user-images.githubusercontent.com/23704923/147848611-0d20563e-f656-487a-9774-9eb6feca1f58.mp4

(video demo on YouTube if above doesn't play).

contents

  • usage
  • install
  • how it works
  • BUGS
  • workarounds
  • THANKS
  • other tools

usage

  • the computer running ytcast and the target device must be on the same network.
  • the target device must support the DIAL protocol (see [how it works][14]).
  • the target device must have the YouTube on TV app already installed.

run ytcast -h for the full usage, here I'll show the basic options.

the -d (device) option selects the target device matching by name, hostname (ip), or unique service name:

$ ytcast -d fire https://www.youtube.com/watch?v=dQw4w9WgXcQ

to see the already discovered (cached) devices use the -l (list) option:

$ ytcast -l
28bc7426 192.168.1.35    "FireTVStick di Marco"         cached lastused
d0881fbe 192.168.1.227   "[LG] webOS TV UM7100PLB"      cached

to update the devices cache use the -s (search) option (it's implicit when the cache is empty or when -d doesn't match anything in the cache):

$ ytcast -s
28bc7426 192.168.1.35    "FireTVStick di Marco"         lastused
d0881fbe 192.168.1.227   "[LG] webOS TV UM7100PLB"      cached

if your target device doesn't show up, you can try increasing the search timeout with the -t (timeout) option to give the device more time to respond to the query:

$ ytcast -s -t 10s
28bc7426 192.168.1.35    "FireTVStick di Marco"         lastused
d0881fbe 192.168.1.227   "[LG] webOS TV UM7100PLB"      cached

remember that the computer and the target device must be on the same network. if it doesn't show up after several tries, you may consider using the -pair option to skip the discovery process altogether. this adds some limitations though, see [workarounds][15].

to cast to the last used device use the -p option:

$ ytcast -p https://www.youtube.com/watch?v=dQw4w9WgXcQ

when no url is passed in the arguments, ytcast reads video urls (or ids) from stdin one per line:

$ ytcast -d lg  Linked devices` menu. it used to show

up there and there was a button to "unlink all devices" which caused the screenId to change, but a YouTube update "broke" this feature.

workarounds

  • some devices don't support the DIAL protocol (notably Chromecast) so they can't be discovered by ytcast. the YouTube on TV app has a "link with code" functionality which can be used as workaround to pair ytcast with these devices. the pairing code can be found in Settings > Link with TV code and then you can use the -pair option to do the pairing:

    $ ytcast -pair 123456789101
    8a59f138 unknown         "YouTube on TV"

    once paired you can cast videos in the usual way:

    $ ytcast -d 8a59 https://www.youtube.com/watch?v=t0Q2otsqC4I

    when using this method, ytcast and the target device do not need to be on the same network, but it adds many manual steps i.e. the YouTube on TV app must be already open because ytcast won't be able to start it nor to Wake-On-Lan the TV and it won't automatically "re-pair" when the screenId changes (I don't know how often that happens).

  • playlist urls don't work with ytcast, I haven't found a reliable way to pass playlist ids to the api. youtube-dl comes to the rescue (see also other tools) since it can extract all video urls of YouTube playlists:

    $ youtube-dl -j --flat-playlist https://www.youtube.com/playlist?list=PLrOv9FMX8xJHqMvSGB_9G9nZZ_4IgteYf | jq -r '.url' | ytcast -p

    you can of course filter the pipeline as you like and this makes it so flexible that I actually don't feel the need for ytcast to support playlist urls: less is more!

  • this might sound obvious, but if you are tired of typing the device name (even a substring of it) every time you want to cast something or if you have multiple devices with the same name, you can define shell aliases and benefit from shell tab-completion feature:

    $ alias ytcbed="ytcast -d 'LG 32'"
    $ ytcbed https://www.youtube.com/watch?v=dQw4w9WgXcQ

    (see your shell documentation to make aliases persistent, usually you have to add them in the shell's rc file).

THANKS

I would like to thank all the people whose work has helped me tremendously in building ytcast, especially the following projects/posts:

  • https://0x41.cf/automation/2021/03/02/google-assistant-youtube-smart-tvs.html
  • https://github.com/thedroidgeek/youtube-cast-automation-api
  • https://github.com/mutantmonkey/youtube-remote
  • https://bugs.xdavidhu.me/google/2021/04/05/i-built-a-tv-that-plays-all-of-your-private-youtube-videos
  • https://github.com/aykevl/plaincast
  • https://github.com/ur1katz/casttube

other tools

as I said earlier, my computing environment is very command-line centric and I'd like to showcase the other tools I use to enjoy a "no frills" YouTube experience from the terminal!

  • youtube-dl (actually yt-dlp these days) doesn't need introduction, it's an awesome tool and it's well integrated with mpv so I can watch videos with my favorite player without having my laptop fan spin like an airplane engine thanks to this mpv config:

    ytdl-format=bestvideo[height> ~/.newsboat/urls

see license file for copyright and license details.

Issues· 2 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gocastdialsmart-tvssdp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言