I started studying Japanese two years ago, however this last year was terrible for my Japanese knowledge, I have spent very little time reading or listening to Japanese as I have no contact with the language on my daily routine and had no time nor motivation during the last twelve months for studying. If I could watch Japanese TV daily maybe I won't lose contact with the language but... How?

Somehow I don't remember, the other day I discovered abema.tv, it is just what I was looking for, a site where you can freely watch several high quality TV streams directly from Japan. I clicked the link and browsed the site, however the typical web player appeared on the screen, and on top of it, an alert message notifying me that the stream was only available from Japan. How disappointing!

So much Japanese content!

But I am very sturdy so I didn't want to leave the idea there, I knew that geographically blocked streams can be watched by using a VPN so later that day I tried connecting Firefox through a Japanese VPN and succeeded, the message did not pop up and the stream loaded.

How could someone get the same thing on a Kodi powered TV and a phone? I started to think about it and came with the following idea:

Diagram for the solution

A Raspberry Pi would be placed on my home network, permanently connected to a VPN host physically based in Japan, making use of these hosts the Pi responsibility would be to capture the stream, transform it and then make it accessible to any other host in the home network, wether it is a phone, the TV or any other device. It seems a cool experiment to try.

So first things first, I took an old Raspberry Pi 2 I bought in the second hand market I had lying around, an SD card and installed Raspbian Stretch Lite as this Pi will not need graphical environment or anything like that, just remember adding an empty file called  ssh on the boot partition so ssh access is active by default.

After connecting directly the Pi to the router using an Ethernet cable the Pi appeared listed on the devices connected to the LAN.

After doing the typical maintenance operations like updating packages, passwords and so, the next thing is to make the Pi connect to the Internet through a Japanese VPN host.

There is this curl command to check what country your IP is curl ifconfig.co/country.

I installed OpenVPN and got the configuration file for the Japanese host, I'm afraid I won't post the information here on how did I find the host so if you need one you'll have to look somewhere else.

Then I could use the command mentioned above to check my Pi's IP will become Japanese when running OpenVPN.

Now for processing the stream I used Streamlink, it already has an Abema plugin. The installation process for ARM (The Pi's architecture) is quite straightforward if you follow these steps. But first the following packages need to be installed using aptitude: python-dev, libffi-dev,  libssl-dev.

Once streamlink is installed, we can check connecting it to Abema without running OpenVPN:

Without a Japanese IP the stream is blocked.

And while running OpenVPN:

Streamlink works using OpenVPN.

Streamlink comes with a --player--external-http option that instead of running the stream on some player installed on the computer, will just open an HTTP port for other players on other hosts to connect to, which is exactly what I wanted. You can also specify the HTTP port with --player--external-http-port.

Running streamlink without running a player.

Now I can run VLC on my desktop PC and point to the Raspberry Pi's address to watch the stream, or I could just point Kodi on my TV and watch the stream on my TV or my phone.

It seems to be working

Finally, due to network issues, the stream stopped a couple of times, nothing to worry about but it got me thinking... What if I could just dump the stream content as well and then just watch it tomorrow? or rsync the stream dump to my phone so I can watch it while going to work. So I installed ffmpeg  on the Pi and tried dumping the content directly from the same port streamlink was serving the content.

I left it running for a while and then checked the results.

Playing a stored dump

To run OpenVPN client on startup for every configuration file as stated here you should uncomment the AUTOSTART="all" line on/etc/default/openvpn. After restarting the daemon like a thousand times, I discovered you have to move your configuration files from /etc/openvpn/client to /etc/openvpn in order to be automatically picked on startup.

Finally for start streaming TV and dumping it to a file on startup, we will turn our commands into systemd services. And then enable them on startup, this way as soon as the Pi turns on it starts recording. The only tricky thing I encountered here was a way to add a timestamp to the ffmpeg command in order to generate ordered and unique filenames for the stream dumps, the final line on the service definition file was:

ExecStart=/bin/bash -c '/usr/bin/ffmpeg -i -c copy "/home/pi/dumps/$$(date +%%Y-%%m-%%d_%%H-%%M-%%S)_abema.mkv"'

That way once the Pi is booted it will start storing files like this:

Example dump files

It works very well! The only limitation now is storage space, but this can be easily resolved by for example rsyncing your files to a NAS or something like that. So this is how you can build a system to get automatically unlimited Japanese language audiovisual material. By the way, this is just a research I made to see if this was possible or not, I actually don't know if it is legal or not making use of a system like this or distribute material gathered like this, so, if you know it is, don't do it! Anyway I hope you found this experiment as entertaining as I did.