Streaming Pandora with Pianobar on QubesOS

The other day Kris Nóva was broadcasting her effort to get pianobar working. Pianobar is a Pandora radio CLI application written in C.

Typically my day is filled with some lo-fi hip hop streamed from YouTube. But the constant ads and “Video Paused. Click to continue” prompts are quite annoying. The idea is to have some chill background music not something that requires constant petting throughout the day, when I found out about pianobar I had to get it going.

My setup is a bit different than Kris', I run QubesOS, so things like this end up in their own VM. This is a short overview of how I’ve set this up to have instant radio in a terminal with no more ads / prompts. You’ll need a pandora account and a Qubes install to follow along.

QubesOS Methodology

I won’t go into incredible details on Qubes, but the basic concepts are:

  • XEN based virtualization
  • Template VM: Virtual machine templates, think O/S base image for App VM
  • App VM: App VMs use a Template VM for the base system and have persistent storage for your particular settings

Since I use the standard template VMs to reduce the attack surface and supply chain risk for my clients, they’re kept quite pristine and don’t have any software on them that isn’t from the official repositories. Rather than compile Pinanobar, I decided to use the Fedora RPM Fusion packages. This requires a new template VM with the fusion repositories added so that our standard fedora-30 Template VM isn’t tainted (no slight implied here, that’s just how I roll).

New TemplateVM

We’ll clone the existing fedora-30 VM so we don’t modify the original, other VMs use that template.

  1. Run the following in a Dom0 terminal

    qvm-clone fedora-30 fedora-30-fusion
    qvm-run fedora-30-fusion xterm
    

    This should provide you with a barebones xterm that we’ll use to install pianobar from the fusion repositories.

  2. We add the fusion repositories in the fedora-30-fusion xterm

    sudo dnf config-manager --set-enabled rpmfusion-{non,}free
    sudo dnf install pianobar
    
  3. Next we shutdown the template VM. We don’t have to touch this again.

    shutdown -h now
    

New App VM

Next, we create the App VM. It will use the Template VM we created above, but also house our configs.

  1. In a Dom0 terminal, create the App VM “personal-radio”, and launch an xterm. We’ll use the xterm to configure pianobar.

    qvm-create --template fedora-30-fusion --label green personal-radio
    qvm-run personal-radio xterm
    

Pianobar Config

By default, pianobar will prompt you for your credentials on startup. We want this to be automated so we have a single click music system.

  1. In the personal-radio xterm that we started, you should be able to run pianobar and login. To have that automated for us, we’ll create a config file.

    mkdir ~/.config/pianobar
    vi ~/.config/pianobar/config
    

    For complete pianobar configuration details, see man pianobar. I use pass with split-gpg to secure my password, but you can put any command in the password_command, or, specify the password plaintext.

    audio_quality = high
    # station IDs can be displayed by pressing i in pianobar when a song is playing
    autostart_station = 4541690573152710643
    user = [email protected]
    password_command = pass services/pandora/[email protected]
    #password = dobetter
    

    Save this file and then run pianobar again. It should automatically log you in and start playing the Electronic Ambient Radio station.

Create Pianobar Menu Item

We can add a shortcut in the Qubes Menu for our personal-radio VM.

  1. Create the pianobar XDG configuration

    mkdir ~/.local/share/applications/
    vi ~/.local/share/applications/pianobar.desktop
    

    Add the following content and save the file

    [Desktop Entry]
    Name=Pianobar
    Type=Application
    Exec=pianobar
    Terminal=true
    
  2. In a dom0 terminal run qvm-sync-appmenus personal-radio

  3. In a dom0 terminal run qvm-vm-settings personal-radio

    1. Click Applications
    2. Select Pianobar in the Available column
    3. Click the > Arrow to move to the Selected column
    4. Click Apply.

You can now use this menu item to start your music or resume it if you close the terminal it plays in.

Start Pianobar Automatically

I also want pianobar to start automatically when the pianobar VM starts. This is useful as I use the CLI to launch app VMs instead of the menu option we created above.

  1. In a personal-radio terminal, create the autostart shortcut

    mkdir ~/.config/autostart
    cd ~/.config/autostart
    ln -s ~/.local/shared/applications/pianobar.desktop
    
  2. Shutdown the personal-radio VM via shutdown -h now from the personal-radio terminal or qvm-shutdown personal-radio from the Dom0 terminal.

  3. Launch the personal-radio VM, pianobar should run, login, and start playing all on it’s own. qvm-start personal-radio from a Dom0 terminal.


Illustration of Vince

Vince Hillier is the President and Founder of Revenni Inc. He is an opensource advocate specializing in system engineering and infrastructure. Outside of building solid infrastructure that doesn't break the bank, he's interested in information security, privacy, and performance.