News for hackers. Stuff that matters.

Show HN: ytcast – cast YouTube videos to your smart TV from command-line

https://github.com/MarcoLucidi01/ytcast

hi, this is a project I've been working on and off for the last three months, it's my first non-trivial, non-hello-world, actually useful (at least to me) go project. it would be very nice if you could just try the program and see if it works on your setup!

the readme[0] explains how it works, why I wrote it and how it fits in my "command-line centric" computing environment (there is also a video demo[1] :)).

if you know go, feel free to take a look at the code and review it! I'm still pretty much new to go and I'd love to hear opinions, feedback and tips from more seasoned go developers :)

[0]: https://github.com/MarcoLucidi01/ytcast#ytcast

[1]: https://www.youtube.com/watch?v=07aWOpi8DVk

( 51 comments | 227 points | on HN )
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by e12e on Wednesday February 16, 2022 @06:29PM (#30367312)
Thank you for taking the time to describe how it works in the readme. I loathe "magic" - and love seeing the mechanics of how stuff like this works. Makes your project useful to me, even if right now, I rarely have computer (with a cli) close to my TV.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:30AM (#30370775)
i'm very glad you appreciated that!

> I loathe "magic" - and love seeing the mechanics of how stuff like this works.

yeah me too :)

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by mobilio on Wednesday February 16, 2022 @07:33PM (#30367957)
I'm using castnow: https://github.com/xat/castnow

and for our needs works perfect.

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:08AM (#30370622)
good for you! good to know about castnow :)
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by mastazi on Thursday February 17, 2022 @03:15AM (#30370689)
Is there something like a chromecast "server"?

What I mean: I have a Linux box connected to my TV - I want to know if there is a way to cast from a phone to the Linux box, by installing some software on the linux box that makes it appear as a Chromecast to other devices

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by MayeulC on Thursday February 17, 2022 @03:46AM (#30370883)
Chromecast is completely closed-source, I'd argue against buying into that ecosystem.

Nymphcast [1] is an alternative, but wouldn't be compatible with existing clients, since the protocol is different.

Miraclecast [2] is an implementation of miracast/wi-fi display that runs on Linux. There is also a myriad of alternatives: vnc, raspicast, etc.

Leapcast [3] used to be an implementation of what you want (while using chrome as a black box).

There are some implementations of airplay servers.

And lastly, a lot of media players implement some way of playing on one another (vlc, kodi, jellyfin, plex).

Funnily, you might just be interested in UPNP and DLNA. Support for these is quite robust, but it tends to disappear on newer devices (to the benefit of proprietary solutions like chromecast and airplay).

[1]: http://nyanko.ws/product_nymphcast.php

[2]: https://github.com/albfan/miraclecast

[3]: https://github.com/dz0ny/leapcast

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by mastazi on Thursday February 17, 2022 @05:18AM (#30371521)
Thank you good list, and yeah I get that it's a closed source system but wouldn't it be cool if the FOSS community was able to reverse engineer it?

Thanks I'll look into the alternatives you linked

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by MayeulC on Friday February 18, 2022 @08:22AM (#30385359)
Even if it succeeded, it would be yet another cat-and-mouse game with Google, for little benefit. Of course anyone is free to work on whatever they want, and I might use it if a solution existed.

Nymphcast and Kodi work relatively well as a substitute, but aren't integrated in google's products like youtube (you can still use "share to" usually).

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by 35mm on Thursday February 17, 2022 @03:32AM (#30370786)
Kodi has this feature for AirPlay, not sure if it works with Chromecast too.

Also maybe look into OpenMax + Raspicast

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by mastazi on Thursday February 17, 2022 @05:18AM (#30371526)
Nice, thank you I will look into those
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by heavyset_go on Wednesday February 16, 2022 @07:12PM (#30367718)
How does this differ from, say, catt[1]?

[1] https://github.com/skorokithakis/catt

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:19AM (#30370708)
i learned about catt in this thread and i never used it, so i may be wrong about something, but these should be the main differences:

- they use a different protocol for device discovery, catt uses mDNS, ytcast uses DIAL.

- catt requires a chromecast to work, ytcast should work with any DIAL enabled device that supports the YouTube on TV app.

- catt can cast from many sources including local files, ytcast merely "tells" the YouTube on TV app to play videos, so it's limited to YouTube.

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by heavyset_go on Thursday February 17, 2022 @05:44PM (#30379726)
Cool, thanks for the explanation. I'll give your project a spin.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by sharmi on Thursday February 17, 2022 @01:35AM (#30370165)
ytcast search functionality is a great feature. When I come across a video that would be interesting for my kids, I cast it on tv. Now I don't need the url to cast, I can just search by the text.

Castnow, mentioned elsewhere in the thread, seems to be able to cast videos saved on the laptop directly. Our usual routine is to copy to pendrive, move to TV and then switch the TV source to usb. This would be a welcome addition.

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:47AM (#30370892)
thank you! the search video functionality is not builtin into ytcast, but is actually a separate script (ytsearch[0]) so you can use it with other tools!

> cast videos saved on the laptop directly.... This would be a welcome addition.

yeah i know this would be great, but unfortunately it's unfeasible with the current implementation. what ytcast does is merely "telling" the YouTube on TV app to play videos.

[0]: https://github.com/MarcoLucidi01/bin/blob/master/ytsearch

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by 1vuio0pswjnm7 on Sunday February 20, 2022 @03:23PM (#30408968)
ytsearch does not support continuation searches. (It only retrieves the first 15 results.)

Continuation searches occur when a user scrolls to the bottom of a search results page.

YouTube (or NewPipe, etc.) sends automated search requests to continue the search, triggered automatically via Javascript when the user scrolls to the bottom of the page.

YouTube continuation searches leak a large amount of unnecessary user data to Google.

1.sh[1] sends continuation searches manually and sends only the minimum ($MIN) data needed to fulfill the request.

It can be used to continue a search indefinitely over an extended period of time. Using an app like NewPipe, often recommended on HN, one could try to do continuation searches by repeatedly scrolling to the bottom of the search results page. However if one goes forward to view a result and then presses a back button, she will be returned to the first page the results, losing all the continuation search results. And if the browser tab or app is closed or crashes, the continuation search results are lost. It is easy to lose one's place when doing continuation searches using a Javascript-enabled browser or app. Using this script, this will never happen.

1.sh only uses TLS1.3 so no server certificate is sent in plaintext over the wire. Nor does it send SNI, i.e., plaintext hostnames on the wire.

ytsearch requires sed, column, awk, jq, fzf, and curl.

1.sh requires sed, netcat, stunnel and flex.

1.sh could be adapted to use curl but how does one disable SNI with curl.

Not to mention curl has a TLS fingerprint that sites may use to try to block requests or treat them with prejudice.

Usage for 1.sh is

   1.sh query; #<-- saves line-oriented JSON to query.yts

   1.sh << query.yts >> query.yts; #<-- appends more JSON to query.yts
To convert our line-oriented JSON to TSV, we can use line-oriented UNIX utilities. In general, this will be faster than jq and more robust for large files.

1. 1.sh is a 25 line, 1000 character shell script. https://news.ycombinator.com/item?id=30408770

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Monday February 21, 2022 @11:51AM (#30417868)
oh wow, that's pretty cool and impressive! thanks for sharing.

> ytsearch does not support continuation searches.... Continuation searches occur when a user scrolls to the bottom of a search results page.

true, I never bothered adding "continuation searches" feature to ytsearch because I very rarely scroll down to the second page of results. usually if what I'm looking for is not in the first 4-5 results, I just "refine" the search query.

ytsearch is a quick-and-dirty script that avoids me to open the browser for simple YouTube searches (I stole the idea from the initial version of ytfzf).

> It only retrieves the first 15 results.

that's not true, I always get more than 20-25 results on average and it's usually enough for my use:

    $ ytsearch foo | sort | uniq | wc -l
    37
> 1.sh only uses TLS1.3 so no server certificate is sent in plaintext over the wire. Nor does it send SNI, i.e., plaintext hostnames on the wire.

> 1.sh could be adapted to use curl but how does one disable SNI with curl.

that's pretty cool if you care about this kind of stuff!

> Not to mention curl has a TLS fingerprint that sites may use to try to block requests or treat them with prejudice.

yes I see how this could become a problem.

> ytsearch requires sed, column, awk, jq, fzf, and curl.

> 1.sh requires sed, netcat, stunnel and flex.

what are you implying here? do you think those 6 dependencies are "too much" for ytsearch compared to those of 1.sh?

anyway, it seems that the 2 tools offer a slightly different user experience out-of-the-box:

- 1.sh dumps json and can be used to continue searches without leaking too much data.

- ytsearch allows to quickly select a few urls and it's meant to be used interactively.

> To convert our line-oriented JSON to TSV, we can use line-oriented UNIX utilities. In general, this will be faster than jq and more robust for large files.

faster yes, but how it will be "more robust for large files" than jq? I always thought jq is the right tool for the job when dealing with json.

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by 1vuio0pswjnm7 on Monday February 21, 2022 @03:37PM (#30420286)
The number of results, as well as the schema of the JSON, might vary based on YouTube's "guess" as to the form factor of the computer being used to send the request. For example, when no User-Agent header is sent I have noticed sometimes web developers just assume the form factor is "mobile".

Providing a list of requirements is a courtesy for the reader.

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by 1vuio0pswjnm7 on Tuesday February 22, 2022 @09:20PM (#30436815)
s/indefinitely/up to 500 results/
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by genericacct on Wednesday February 16, 2022 @04:07PM (#30365684)
Very useful, i dislike using yt's UI on televisions
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by epa on Wednesday February 16, 2022 @05:03PM (#30366391)
Try a Google Chromecast TV and side load SmartTubeNext, no ads and better UI. https://github.com/yuliskov/SmartTubeNext
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:25AM (#30370740)
yeah, i especially dislike searching videos with the remote!
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by phoronixrly on Thursday February 17, 2022 @02:08AM (#30370335)
I found the magic behind "play on TV" so creepy that I made sure my LG TV was never to be connected to a network. I can achieve similar functionality via my libreelec box without proprietary software connected to my LAN.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by Reggino on Thursday February 17, 2022 @01:40AM (#30370184)
Nice! I wrote something similar for local video files:

https://github.com/Reggino/chromecaster

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:33AM (#30370794)
cool! lots of interesting things can be done with a chromecast, unfortunately i don't have one.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by winstonschmidt on Wednesday February 16, 2022 @06:21PM (#30367228)
Great tool! Does going through ytcast have any impact on whether the played video influences youtube's recommendation algorithm (which annoys me a lot)?
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:53AM (#30370935)
thanks! yes, unfortunately the algo is still influenced because ytcast "tells" the YouTube on TV app to play the videos.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by jlkuester7 on Wednesday February 16, 2022 @03:11PM (#30365065)
Nice! Projects like this give me hope for Chromecast support one day from Android devices not running Google Play Services (e.g. GrapheneOS)...
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @04:31AM (#30371196)
thanks!

as already said, ytcast won't work "directly" with chromecast since they use a different protocol, but there are other projects linked in this thread which work very nice with chromecast!

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by andrewshadura on Wednesday February 16, 2022 @04:15PM (#30365790)
ytcast uses a different protocol.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by bncy on Thursday February 17, 2022 @04:14AM (#30371069)
That's amazing, I often have problems with sending video to my tv, somehow chrome is not that good for it, thanks!
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @04:22AM (#30371129)
thank you! another handy thing that ytcast does and that chrome / YouTube smartphone app don't do is to wake-on-lan my tv if it's off when i want to play a video.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by rolandog on Thursday February 17, 2022 @12:39AM (#30369905)
Ooh, nice! I'll be giving it a try today or tomorrow, as I had been having trouble with MkChromecast.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @04:32AM (#30371201)
sounds great!
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by pmoriarty on Wednesday February 16, 2022 @09:42PM (#30368944)
Hopefully this offers some way to avoid the ads, like youtube-dl does.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:26AM (#30370748)
unfortunately it doesn't, it merely "tells" the YouTube on TV app to play videos.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by sahinabi on Wednesday February 16, 2022 @09:10PM (#30368746)
Thank you for the project and detailed readme, very helpful.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @04:11AM (#30371052)
thanks, very glad you liked the readme :)
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by brunoqc on Wednesday February 16, 2022 @03:24PM (#30365204)
Can it remove ads?
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Wednesday February 16, 2022 @03:56PM (#30365562)
nope
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by sdoering on Wednesday February 16, 2022 @05:03PM (#30366395)
Cool. Can't wait to try it out. Thanks.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @04:28AM (#30371173)
sounds great!
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by Loranubi on Thursday February 17, 2022 @01:11AM (#30370062)
So if I don't want to get a HDMI cable to connect my TV, but happened to have a network connection instead I would use that?
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @03:37AM (#30370821)
yes? i mean for YouTube videos yes (if your tv supports the YouTube app and DIAL protocol).
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by stavros on Wednesday February 16, 2022 @04:44PM (#30366170)
CATT (which I wrote) does the same, except it supports whatever site youtube-dl supports (which is basically everything):

https://github.com/skorokithakis/catt/

Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by igravious on Wednesday February 16, 2022 @05:16PM (#30366550)

   groobiest@NH5xAx ~/Code/ytcast [master]  ytcast -l
   ab5d4550 192.168.1.2     "[LG] webOS TV OLED55C16LA"    
   groobiest@NH5xAx ~/Code/ytcast [master]  ytcast -d lg https://www.youtube.com/watch?v=VZx-rLoV4do
   

   groobiest@NH5xAx ~/Code  ~/.local/bin/catt scan
   Scanning Chromecasts...
   Error: No devices found.
   𝑥
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by rahimnathwani on Wednesday February 16, 2022 @05:07PM (#30366447)
OP seems to work for any Smart TV with a YT app (e.g. a Samsung or Roku TV), whereas CATT requires a Chromecast?
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by stavros on Wednesday February 16, 2022 @05:13PM (#30366513)
There are various protocols for TVs to cast things, it seems like this one uses DIAL, whereas CATT uses Google Cast. I was thrown off by the icon, it does seem like the two are slightly different, thanks for the correction.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by rahimnathwani on Wednesday February 16, 2022 @05:16PM (#30366558)
FWIW I didn't know about CATT, and I actually have some use for it. I sometimes want to cast local video files from my PC to a projector on the other side of the room. That already has a Chromecast so CATT should make it easy.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @04:09AM (#30371039)
yes, ytcast should work with any DIAL enabled device that supports the YouTube on TV app, so it doesn't require a specific device, but it's limited to YouTube videos.
Re:Show HN: ytcast – cast YouTube videos to your smart TV fr... by marcolucidi on Thursday February 17, 2022 @04:05AM (#30371018)
cool! good to know about catt! unfortunately i don't have a chromecast to trying it out.