cast YouTube videos to your smart TV from command-line
cast YouTube videos to your smart TV from command-line
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:

(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).
(video demo on YouTube if above doesn't play).
ytcast and the target device must be on the same network.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=dQw4w9WgXcQto 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" cachedto 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" cachedif 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" cachedremember 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=dQw4w9WgXcQwhen 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.
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=t0Q2otsqC4Iwhen 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 -pyou 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).
I would like to thank all the people whose work has helped me tremendously in
building ytcast, especially the following projects/posts:
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/urlssee license file for copyright and license details.
No open issues yet, or sync has not completed.