Running YTuner on Raspberry Pi

A guide to installation on headless Raspberry Pi

An AVR
×
An AVR
vTuner based AVR Internet Radios can be saved from death by YTuner.

YTuner is a terrific program that can breathe new life into Internet radio receivers that were based on vtuner. It can be found at https://github.com/coffeegreg/YTuner. My huge thanks to its developer, coffeegreg.

I have a Denon X2300W AVR that I use to listen to Radio Swiss Jazz. It stopped working when vtuner required a subscription, I paid up, but now it fails to work too often for my liking and I felt the need for an alternative and independence. The two main substitutes for vtuner seem to me to be YCast, and, the subject of this article, YTuner.
I decided to try installing YTuner on Raspberry Pi, and it works very well for me.

I had two Raspberry PI's just lying around, a 4b, and a 3b, so I installed YTuner on both of them in desktop Raspberry Pi OS, and as headless versions. They all work with the Denon AVR. There are two small issues with the Denon X2300W AVR that I haven't had time to get deeper into, mostly because they don't bother me. First, the station logo disappears periodically; it can be refreshed by restarting the station from My Stations. Secondly, "favorites" is not working. I assume that Denon favorites is the same as bookmark. If I bookmark a station it is bookmarked but doesn't show in favorites. If I bookmark the same station it tells me that it is already bookmarked.

I have written down my recipe for the headless installation in the hope that it may help other folk with a similar issue, and so that I have a reference when I have forgotten how to do it (a couple of weeks from now).

So to begin:

Requirements and Architecture

Requirements are simple:

  1. The system runs YTuner
  2. The Denon AVR X2300W is supported
  3. My favorite stations are programmed as presets
  4. The system connects to the local network, optionally by cable, or by WiFi
  5. The system runs on a Raspberry Pi, and starts up automatically, i.e. YTuner is started automatically at boot time
  6. The system normally runs headless, no monitor or keyboard connected
  7. Management (and installation) is performed using an SSL connection from a PC running PuTTY
  8. A monitor, keyboard and mouse can be connected to manage the system in the event that network, or other issues prevent access by SSL

Note: The system will also run on a RPi with a desktop. Just follow the same instructions, or use the GUI to perform some of the operations if you prefer, for example, you could copy and paste from this page open in your browser to the terminal, or you could use your favorite GUI editor instead of nano. Bear in mind that some of the editing will have to be done at a privileged level (sudo equivalent).

The architecture to support these requirements:

Requirements 1 to 3 are handled by YTuner itself, the denon.vtuner.com forwarding is set up in YTuner's main configuration file, and the preferred stations are set up in the stations.ini configuration file.

Requirement 4: is set up by the Raspberry Pi hardware, if the Pi has an Ethernet port and you connect it to your network, it uses a cable connection. If you want to use WiFi you set it up in the OS image created by the Raspberry Pi Imager.

Requirement 5: YTuner is run as a service, once initialized during the installation it will run automatically each time the system is booted.

Requirements 6, 7, and 8: The system is managed from an external PC, or other terminal using SSL and a terminal emulator, PuTTY. A monitor, keyboard and mouse can be used, but they are only required if the system cannot be reached using SSL.

When the OS image is created in Raspberry Pi Imager, one of the options is to set up SSL. SSL provides the mechanism for logging in to the system using an external PC (or other terminal), and SSL terminal emulation software like PuTTY. See the developer's website at https://www.chiark.greenend.org.uk/~sgtatham/putty/

Where in the Raspberry Pi is the YTuner software installed?

YTuner is installed under the /opt folder, it is owned and run by a ytuner user that is created for this one purpose. It is controlled by a service control file in /etc/systemd/system/

Initially YTuner is set up in the main user's home folders. It is configured there by editing the necessary configuration files. Then the folder tree containing YTuner is copied to /opt.
If anything goes wrong with the files in /opt the original files can be copied from the home folders, and the system restarted. If any updates are made to the YTuner files in /opt it would be wise to copy them to the master copy in the home area once they have been fully tested.

The Installation

The steps covered by the instructions include:

  1. Setting up the Raspberry Pi OS ready for use
  2. Creating the ytuner user and giving it a password.
  3. Downloading and unzipping the YTuner files to the user's folders.
  4. Preparing the files for use, and editing the configuration.
  5. Copying the prepared files to /opt.
  6. Giving ownership of the files to the ytuner user.
  7. Giving the YTuner executable the "executable" permission
  8. Authorizing the YTuner executable to access/bind to port 80.
  9. Setting up the service control file in /etc/systemd/system/.
  10. Initializing the service.
  11. Shutting down and restarting the system to test automatic start.

You will need

  1. For installing and maintaining the system:
    1. Access to Internet
    2. A PC or similar with microSD cardreader/writer, with PuTTY and the Raspberry Pi Imager software installed.
    3. PuTTY or similar SSL terminal emulator program. (thanks Simon)
    4. Raspberry Pi Imager, download from the Raspberry Pi website, www.raspberrypi.com/software/
    5. In case a network connection to the Raspberry Pi is not available for any reason, a keyboard, mouse, monitor, and cables, etc. are required.
  2. To run YTuner:
    1. A Raspberry Pi with power supply, and optionally a network cable.
    2. A boot drive, e.g. I used a 32 GB microSD card.
    3. A static/fixed IP address for the YTuner server.
  3. YTuner from coffeegreg github, https://github.com/coffeegreg/YTuner.
    Binaries are at, github.com/coffeegreg/YTuner/releases
    I used ytuner-1.2.6-arm64-linux-rpi-3-5.zip for both the 3B and the 4b

A. Setting up the Raspberry Pi OS ready for use

  1. Create a boot drive for the system using the PC with a cardreader, and Raspberry Pi Imager
    1. Insert the microSD card into the reader
    2. Open Raspberry Pi Imager
    3. Select a device type appropriate for your RPi board
    4. Select an OS (for headless versions first choose "OS(Other)", then choose an OS without Desktop) For a RPi 3b I used Raspberry Pi OS Lite (64-bit)
    5. Select your storage device
    6. Click Next
    7. At "Would you like to apply OS customisation settings?", click "EDIT SETTINGS"
    8. Enter your preferred hostname, username, and password. If you want to use WiFi then enter your network's SSID, password, and country. Enter your timezone and keyboard layout.
      Note: This username is used for all installation steps.
    9. Click on the Services tab, make sure that SSL is enabled, and select "Use password authentication"
    10. Click SAVE
    11. Now, in answer to: "Would you like to apply OS customisation settings?", click YES
    12. Confirm deletion of existing data if it is safe to do so, and the SD card will be written to, and verified.
    13. When the card is ready, remove it from the reader and install it in the Raspberry Pi
  2. Boot the system using the prepared drive

    Connect any required cables, and power up to boot the system.

    If you have a monitor connected you will see the system boot a few times as the OS is configured. Eventually you will see information about the OS, the hostname that was entered in the imaging tool, the IP address, and a login prompt.
    At this point you can login to the system using PuTTY.
    If you do not have a monitor connected, wait five minutes before trying PuTTY.
    In PuTTY, enter hostname.local in the "Host Name" box in the configuration page, (where hostname is the name entered in the imaging tool) and select SSH as the connection type.
    Click Open - If the system is up and running you will get a login prompt, if not, try again later.

    Putty Configuration Dialog
    ×
    Putty Configuration Dialog
    Putty Configuration Dialog, enter the host name and select SSH.
  3. If you have logged in successfully you should find yourself in the /home/username folder.
    Tip: use the pwd command (present working directory) to see what your current directory is.
    Tip: use the ls command to see the files and folders in the current directory (probably none at the moment).
    Tip: use the ls -l command to see the files, folders, their ownership and permissions in the current directory.

  4. Before starting the install make sure that the Raspberry Pi OS is up to date. Also, install the tree command, it is useful for checking folders and contents, ownership and permissions.
    Issue the following commands:

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install tree

    This will take some time, and you will have to answer some prompts during the update.
    Tip: To copy commands from this webpage into PuTTY, select the command with the mouse, use Right-click-copy, or Ctrl-C, to copy the text, place the mouse cursor over the PuTTY terminal window, and right click to drop the text into PuTTY.

B. Creating the ytuner user and giving it a password

  1. Set up a ytuner user:
    Using the command line in the Terminal

    sudo useradd ytuner

  2. Set a password for the ytuner user using the Terminal:

    sudo passwd ytuner

    (the system will ask for the new password and for confirmation)

C. Downloading and unzipping the YTuner files to the user's folders.

  1. Download YTuner from Github using:

    wget -nv https://github.com/coffeegreg/YTuner/releases/download/1.2.6/ytuner-1.2.6-arm64-linux-rpi-3-5.zip

    It will be placed in your current location /home/username

    Note: The commands shown are for 64-bit Raspberry Pi versions. For other Raspberry Pi types choose the appropriate zip file and modify the commands accordingly. (Thanks Hans for your comments.)

  2. Unzip the file with the command

    unzip ytuner-1.2.6-arm64-linux-rpi-3-5.zip

    Tip: type unzip yt, then press tab, the filename should be automatically expanded

  3. Use the ls command to see the newly created folder name. The new folder has the same name as the zip file. To simplify the naming rename the new folder to ytuner. Use the mv command:

    mv ytuner-1.2.6-arm64-linux-rpi-3-5 ytuner

    Tip: as above, type mv yt, then press tab, the filename should be automatically expanded

  4. Type the tree command in the terminal:

    tree

    It will show a tree of files and folders that should look like this:

    ytuner home folders
    ×
    ytuner home folders
    YTuner folders in the home directory after unpacking (click to enlarge).

D. Preparing the YTuner files for use, and editing the configuration.

  1. Delete the files, stations.yaml, and avr.ini.example, unless they are specifically required for your implementation, I did not use them.

    cd ytuner/config
    rm stations.yaml
    rm avr.ini.example

  2. Modify stations.ini, avr.ini, and ytuner.ini using the nano editor, to suit your required configuration.

    Tip: nano is a text based editor, simple but not necessarily simple to use for new users.
    Move the cursor with up, down, right, and left arrow keys.
    To make changes, enter and delete text at the cursor.
    Save changes with ctrl-o, and enter at the prompt to confirm.
    Exit with ctrl-x.
    To exit and start again without saving changes use ctrl-x to exit and answer, "N" at the prompt to save the buffer.
    At the bottom of the nano editor page there is a summary of commands. Those shown with the "^" sign, e.g. "^X" mean press control with the character key, those showing "M-", e.g. "M-W" mean press Alt with the character key.

    nano stations.ini

    In the stations.ini file I replaced the contents with my preferred stations. The first link on each line is the actual radio link, the second half is a link to a logo:

    [Jazz]
    Radio Swiss Jazz mp3=http://stream.srg-ssr.ch/srgssr/rsj/mp3/128|http://www.radioswissjazz.ch/_nuxt/img/rsj-logo-claim-desktop.beb322c.png
    Radio Swiss Jazz aac=http://stream.srg-ssr.ch/srgssr/rsj/aac/96|http://www.radioswissjazz.ch/_nuxt/img/rsj-logo-claim-desktop.beb322c.png

    This gives me two streams at radioswissjazz, one mp3, the other aac.
    Enter the genre and stations of your preference.

    Similarly, edit avr.ini if you want to make changes. I left avr.ini unchanged.:

    nano avr.ini

    Now, edit ytuner.ini. First go to the ytuner folder. username is the user that you entered when making the image file.

    cd /home/username/ytuner
    nano ytuner.ini

    In my configuration I have one Denon AVR, and my internal router/gateway address is 192.168.1.1.
    The lines that I changed in the ytuner.ini file are:

    1. UseSSL=0
    2. InterceptDNs=*.vtuner.com,*.radiosetup.com,*.my-noxon.net,*.radiomarantz.com,denon.vtuner.com,denon2.vtuner.com
    3. DNSServers=192.168.1.1
    This disables SSL, adds the denon vtuner links, and sets dns to use the home router

E. Copying the prepared files to /opt.

  1. Make sure that you are in the home folder, /home/username, (use pwd to check), and use the cp command to copy the ytuner file tree to /opt. -R means copy files recursively, that is, copy entire directories to new directories.

    cd /home/username
    sudo cp -R ytuner /opt

    Use the tree command to see the current status of the new ytuner folder (the -ugp switches show group and user ownership, and permissions):

    cd /opt
    tree -ugp

F. Give ownership of the YTuner files in /opt to the ytuner user

  1. The YTuner service runs under the user ytuner. User ytuner must have ownership of the files in /opt. In the terminal use the command:

    sudo chown -R ytuner:ytuner /opt/ytuner

G. Give the YTuner executable the "executable" permission

  1. An executable file in linux has to have the executable permission. The ytuner file has to be given the executable permission so that it can be run. In the terminal use the command:

    sudo chmod +x /opt/ytuner/ytuner

  2. Type the tree command in the terminal, it will show a tree of files and folders that should look like this:

    ytuner folders in /opt
    ×
    ytuner folders in /opt
    YTuner folders in the opt directory after preparation (click to enlarge).

    Files and folders are owned by ytuner, and the ytuner executable has x permissions.

H. Authorizing the YTuner executable to access/bind to port 80

  1. The executable needs to be able to access/bind to port 80. This is privileged so ytuner has to be given permission. Use:

    sudo setcap CAP_NET_BIND_SERVICE=+eip /opt/ytuner/ytuner

I. Setting up the service control file in /etc/systemd/system/.

  1. At this point ytuner is runnable. To make it run automatically as a service when the system starts up, a control file is needed. The control file describes how the service should be started, and when it should be started in relation to other services. User control files live in /etc/systemd/system. In the terminal create the control file with:

    sudo nano /etc/systemd/system/ytuner.service

    Now copy the text below into nano.

    [Unit]
    Description=YTuner Internet Radio Service
    Wants=network-online.target
    After=network-online.target

    [Service]
    Type=simple
    User=ytuner
    Group=ytuner
    ExecStart=/opt/ytuner/ytuner

    [Install]
    WantedBy=multi-user.target

    To check that the file has been created correctly and contains the correct text, use the command cat on the new file:

    cat /etc/systemd/system/ytuner.service

    The contents of the file will be printed in the terminal.

J. Initializing the service.

  1. Enable and start the ytuner service using systemctl commands. Commands that change the state of a service are privileged and require sudo.:

    sudo systemctl enable ytuner.service
    sudo systemctl start ytuner.service

    Check the status of the service with:

    systemctl status ytuner.service

    The result should be something like:

    ytuner folders in /opt
    ×
    ytuner folders in /opt
    YTuner service healthy systemctl status (click to enlarge).

    Notes: The image above shows (amongst other things)

    1. "Successfully loaded 2 my stations", my Radio Swiss Jazz stations, 128k MP3, and aac, are loaded.
    2. "DNS Service: listening on: 192.168.1.8:53", the system has found my RPi's address, and has started it's DNS service.
    3. "Web Service: listening on: 192.168.1.8:80", the system has found my RPi's address, and has started the vtuner replacement service, i.e. YTuner.

K. Shutting down and restarting the system to test automatic start.

  1. One of the main requirements for the system is that it starts up automatically at boot time. To test this, restart the system, or shutdown, power off, and power on again to restart.
    To restart:

    sudo shutdown -r now

    Alternatively, shutdown to a halt, then power off and power on the system.

    sudo shutdown -h now

    Wait until the system has restarted, this may take a few minutes. Check the status of the service, as in section J above, with:

    systemctl status ytuner.service

    The result should be something like the figure in section J.