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

image

How difficult is it to transfer youtube music or video through a phone or other portable, mobile device to your Raspberry pi? And if not portable? Is it easy to manage media content through Windows or Linux PC? It turns out that no. I want to consider installing, and setting up several applications on your raspberry with the help of which we can do this.
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, for example, on a local server with our media library to play it on raspberry pi. And casting, in turn, comes from the word cast when we “transfer control” of the media content of an external device to our television, and more precisely, to our raspberry pi connected to a television or music center. In this situation, through the mobile, by launching your youtube application, we redirect the output of video or music through our malinka 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 configured everything in our project ViaMyBox and you can not bother with various nuances of linux configuration, in this version of the raspbian buster and download the distribution https://viamybox.com/downloadpage/ or directly from raspberry pi from the repository:

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

and run the script -> Home Theater -> Cast youtube:

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

Well, or configure everything yourself as you like, following the examples below. I will not compare and describe in detail the functionality in this article of these applications, but simply share the experience of configuration and installation and the nuances that I encountered.

We meet! 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 launching gotubecast on raspberry pi, we can use the youtube application of the phone or other devices to connect to raspberry pi and launch the youtube movie on the TV.



But in order for this to happen, you will need to take several actions for this ...

This program is written in Go. Therefore, you need to install it:

cd /home/pi
# 
wget https://dl.google.com/go/go1.13.7.linux-armv6l.tar.gz
# 
sudo tar -C /usr/local/ -xvzf go1.13.7.linux-armv6l.tar.gz
#    
mkdir -p projects/{src,pkg,bin}
# 
nano /home/pi/.profile

And write into it our environment variables:

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

Check this package:

go version

Then install our 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 starting the script, we will see a line, something like
Your pairing code: 901-900-123-183
It will allow us to find our TV through the phone. We go to the youtube application on the phone and then through the account icon in the settings -> watch TV and drive in our code. After that, an icon appears through which youtube will be available to view through our raspberry pi.





But the TV can be lost if there is no connection of the raspberry pi with the google application for a long time, etc. Therefore, in addition to pairing code, it is possible to link your TV to your goggle application using Screen Id forever.

We will 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

into a variable on the following line:

export SCREEN_ID = "aauaju8Example5539vbb"

To start all this at once at startup, 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, starting the demon, in the absence of a network, it crashes. More precisely, raspi.sh does not find the network. You can make the network services wait settings through sudo raspi-config.sh, but it’s generally more pleasant when raspbian downloads quickly) Therefore, let the script check the network itself. Add a wait check to the raspi.sh file:

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

copy gotubecast to the daddy for our executable files

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

And everything is ready :-)
Yes, if you are not a Linuxoid and you have ripples in the eyes of the teams, I automated the entire process described above in the script and it looks like this:



To use it, download the project through the site or through 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.

Launch Youtube through KODI


If you have KODI, then launching a youtube movie through it is much easier. To do this, you just need to install the TubeCast plugin. Of the advantages, this kodi plugin does not require initial configuration and the plugin perfectly “sees” our raspberry pi without manually pairing code.



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



From the description, it follows that this is an implementation of the Cast V1 protocol for Youtube mobile applications, which in turn 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. This allows you to find your device with KODI on board without even being on the same network with it. Just update your pairing code on the streaming device. Thus, we connect two devices and transfer control through one device to another, but not the media content itself. Therefore, 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.

All Articles