Streaming and casting youtube and more .. via Raspberry pi with Gotubecast and KODI TubeCast

How difficult is it to transfer youtube music or videos via your phone or other portable, mobile devices to your Raspberry pi? What if they’re not mobile? Is it easy to manage media content via Windows or Linux PC?

It turns out that it is not difficult. I want to consider installing and configuring several applications on your raspberry with which we can do this.

How it works!

We will assume that streaming in this situation is the process of transferring some kind of media content that is located somewhere on sites on the Internet. Or, say, on a local server with our media library to play it on Raspberry pi. And casting, when we “transfer control” of the media content of an external device to our TV. Or rather, on our Raspberry pi. We connect it to a TV or music center. In this situation, through the mobile, by launching your youtube application, we redirect the output of video or music through our raspberry to the TV. Remember to connect your Raspberry pi to the TV via HDMI.

There are two options to consider these applications. The first option: we have configured everything in our ViaMyBox project. You can not bother with various nuances of configuring linux in this version of raspbian buster and download the distribution https://viamybox.com/downloadpage/ or directly with the Raspberry pi from the repository:

cd /home/pi
git clone https://github.com/viatc/viamybox.git

And run script -> Home Theatre -> Cast youtube :

sudo /home/pi/viamybox/scripts/via-setup.sh

Or set up everything yourself as only you like, following the examples below. I will not compare and describe in detail the functionality of these applications in this article, but just share the experience of configuring and installing them and the nuances that I encountered.

Welcome! Gotubecast!

Project page:

https://github.com/CBiX/gotubecast

Gotubecast is a small program to make your own TV player on YouTube. In other words, by running gotubecast on the Raspberry pi, we can connect to the Raspberry pi via the phone’s youtube app or other devices and launch a youtube video on the TV.

But in order for this to happen, it will take several actions to do this.
This program is written in Go. Therefore, you need to install it:

cd /home/pi
#download it
wget https://dl.google.com/go/go1.13.7.linux-armv6l.tar.gz
#uncompress
sudo tar -C /usr/local/ -xvzf go1.13.7.linux-armv6l.tar.gz
#creating a folder for our project
mkdir -p projects/{src,pkg,bin}
#edit our file
nano /home/pi/.profile

And write our environment variables to it:

export PATH=$PATH:/usr/local/go/bin
export GOBIN="$HOME/projects/bin"
export GOPATH="$HOME/projects/src"
export GOROOT="/usr/local/go"

…..
Checking this package:

go version

Then install gotubecast:

cd /home/pi
go get github.com/CBiX/gotubecast

In the project, which is located in our created folder /home/pi/projects/src/src/github.com/CBiX/gotubecast/examples, the author prudently wrote the raspi.sh script for raspberry, which simplifies the launch of gotubecast.
We launch it and now the magic is close ..

cd /home/pi/projects/src/src/github.com/CBiX/gotubecast/examples
./raspi.sh

After running the script, we will see a string, something like
Your pairing code: 901-900-123-183
This will allow us to find our TV via telephone. Then, we go to the youtube application on the phone and through the “account” icon, then “settings -> watch TV”, and enter our code. After that, an icon appears to view youtube through our Raspberry pi.


But the TV can be lost if the raspberry pi is not connected to the google app for a long time. And so, in addition to pairing code, you can link your TV “forever” to your google app using Screen Id.
Let’s generate it on our Raspberry pi:

wget https://www.youtube.com/api/lounge/pairing/generate_screen_id
cat generate_screen_id

And add it to the file:

nano /home/pi/projects/src/src/github.com/CBiX/gotubecast/examples/raspi.sh

To a variable on the next line :
export SCREEN_ID=”aauaju8Example5539vbb”

To run all this immediately at start, make yourself a small service daemon in the folder:

sudo nano /lib/systemd/system/gotubecast.service

and in it:

[Unit]
Description=Cast youtube
Wants=network-online.target
After=network.target network-online.target

[Service]
Type=simple
ExecStart=/bin/bash /home/pi/projects/src/src/github.com/CBiX/gotubecast/examples/raspi.sh
Restart=on-abort
User=pi
Group=pi

[Install]
WantedBy=multi-user.target

Next, initialize it in the system :

systemctl enable gotubecast.service

And it will start when the system starts. As it turned out, the start of the daemon in the absence of a network falls. More precisely, raspi.sh does not find the network. You can use sudo raspi-config.sh make the network wait before services start. But in General, it is more pleasant when loading raspbian is fast). So let the script check the network itself. Add a waiting check to the file raspi.sh:

while ! ping -q -c 1 8.8.8.8 >/dev/null ; do sleep 1; done

Copy gotubecast to the folder for our executable files:

sudo cp /home/pi/projects/bin/gotubecast /usr/bin/

And everything is ready)

And yes, if you are not a linux fan and your eyes are rippling with commands, I have automated the entire process described above in the script, and it looks like this:

 



To use it download the project via the website or via github:

git clone https://github.com/viatc/viamybox.git

And run the script /home/pi/viamybox/scripts/via-setup.sh and go to the “Home theater” menu:

cd /home/pi
git clone https://github.com/viatc/viamybox.git
sudo /home/pi/viamybox/scripts/via-setup.sh

Tested on Raspbian Buster OS.

Launching Youtube via KODI

If you have KODI on your raspberry, it is much easier to launch a youtube video through it. Actually, you just need to install the TubeCast plugin. On the plus side, this Kodi plugin does not require initial configuration and the plugin perfectly “sees” our Raspberry pi without entering the pairing code manually.



And after installing the plugin, you will immediately see the cast icon on your android youtube application or on the youtube page in the browser:

From the description of the plugin it follows that this is an implementation of the Cast V1 protocol for Youtube mobile applications. In turn, this protocol is based on the DIAL protocol via SSDP. This technology allows you to connect to your youtube channel as an external service via the Internet. Thus, it allows you to find your device with KODI on board. Moreover, not even being on the same network with him. Just update your pairing code on the streaming device. As a result, we connect two devices and transfer control through one device to another, but not the media content itself. Therefore, both the transmitting and receiving device (in this case, our Raspberry pi) must be on the Internet.

I hope it was interesting. If so, write comments!
In the next part, I would like to talk about how to play youtube and other media content from the console terminal with the mps-youtube and straw-viewer and raspicast media combines.