Skip to content

tonib/shoesbox

Repository files navigation

Shoesbox

Shoesbox is an simple application to play and stream mp3 files and radio on a Raspberry Pi 2. This project is buggy, unfinished and UNSUPPORTED.

It should work on other devices too.

Souce code: github.com/tonib/shoesbox

Features

  • Play MP3 files

  • Play internet radio

  • Play on speakers plugged to the Raspberry, or throught streaming on a browser

  • MP3 files organizer

  • Allow to get winamp playlists to the MP3 files on the Raspberry. The files are shared with Samba

  • The player can be controlled with a web interface, or with a numeric keypad plugged to the Raspberry

Why you should not try this

I did this to learn Ruby / Rails, and, well, to have a music player. As a first project to learn a new language, it should be throw away, but it works for me. If you are looking for a good music player, keep searching:

  • It’s not finished (and probably it will never be)

  • It lacks basic functions of any music player

  • It’s all itself an entire security hole: The rail server runs as root, it runs mpg321 as root

How it does work

It runs two processes:

  • A Ruby process to play on the raspberry speakers and handle a keypad for manual operation

  • A Rails app to control remotelly the player, serve streaming

The music on the speakers is played with mpg321

Set up

An uncomplete guide to setup the project:

Raspberry

  • Get a Raspberry Pi 3

  • Install Raspbian on the Raspberry (Stretch lite)

  • Configure raspberry (sudo raspi-config)

Install prerequisites

Setup Ruby v2.2.9 (with RBENV) / Rails / MySql (check gorails.com/setup/ubuntu/14.04)

# Install git and dependencies
sudo apt-get update
sudo apt-get install git-core
# See https://github.com/rbenv/ruby-build/wiki#openssl-usrincludeopensslasn1_mach102-error-error-this-file-is-obsolete-please-update-your-software
# ruby 2.2.9 will not compile with ssl1.1
sudo apt-get install libssl1.0-dev libreadline-dev

# Do a bashrc backup
cd
cp .bashrc .bashrc-BACKUP

# Install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

# Install ruby-build
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
# Install ruby. This will take a LONG time
rbenv install 2.2.9
rbenv global 2.2.9
ruby -v

# Install bundler
gem install bundler
rbenv rehash

# Install rails
# NOT needed. This will be do by "bundle install" on the app dir. The
# project Gemfile contains a reference to rails
#gem install rails -v 4.2.5
#rbenv rehash

# Install mysql and client-dev (required by mysql2 gem)
#sudo apt-get install mysql-server mysql-client libmysqlclient-dev
sudo apt-get install mysql-server mysql-client libmariadbclient-dev

# Install node.js from the node.js repository (required by rails)
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs

Install samba (to share music files with playlists)

sudo apt-get install samba
sudo nano /etc/samba/smb.conf

Now add something like this at the end of the file. This will create a readable / writable directory (Warning: no security!)

############################################
# TONIB:
############################################

# Carpeta compartida
[pi compartida]
comment = Carpeta compartida
path = /home/pi/compartida
writeable = Yes
create mask = 0777
directory mask = 0777
browseable = Yes
#valid users @users
guest ok = yes
force user = pi

Start the samba service, and check it’s working

sudo /etc/init.d/smbd restart

Install ‘Utilities for configuring and using ALSA’

sudo apt-get install alsa-utils

Install rmagick (for images handling):

sudo apt-get install libmagickwand-dev imagemagick

Install mpg321

sudo apt-get install mpg321

There is a bug with mpg321 parsing http headers. This patch will fix it: sourceforge.net/p/mpg321/patches/19/

Install espeak

sudo apt-get install espeak

Install taglib-ruby requirements

sudo apt-get install libtag1-dev

Install zip

sudo apt-get install zip

For youtube-dl (rg3.github.io/youtube-dl/download.html)

sudo apt-get install ffmpeg
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

Setup Gems

cd [application_directory]
# Install gems
bundle install

Setup MySql database

Login on mysql as root, and create the application user:

#mysql shoesbox -u root -p
sudo mysql shoesbox -u root
CREATE USER 'shoesbox'@'localhost' IDENTIFIED BY 'shoesbox';
GRANT ALL PRIVILEGES ON * . * TO 'shoesbox'@'localhost';
FLUSH PRIVILEGES;
\q

Create the database:

cd [application_directory]
rake db:create RAILS_ENV="production"
rake db:migrate RAILS_ENV="production"

Services setup

Edit the files music_daemon and rails_daemon on [application_directory]/bin to set the right USER, APP_FILE and APP_DIR variables.

Create the services:

cd /etc/init.d/
sudo ln -s [application_directory]/bin/music_daemon
sudo update-rc.d music_daemon defaults
sudo ln -s [application_directory]/bin/rails_daemon
sudo update-rc.d rails_daemon defaults

With this, the speakers player and the rails daemon will be started when Raspberry is booted. To start / stop the services:

sudo /etc/init.d/rails_daemon [ start | stop ]
sudo /etc/init.d/music_daemon [ start | stop ]

To run the services on the console, not as daemon, to debug errors:

cd [application_directory]
ruby lib/music/music_daemon.rb run
rails server -e production --binding=0.0.0.0 -p 8080

Other (personal) stuff

If you have your music, as I do, on a USB pendrive, you should add it to the mount table

sudo nano /etc/fstab

Add a line with something like this

/dev/sda1        /home/pi/compartida/musica/discousb vfat  defaults,uid=pi,gid=pi,umask=000,utf8   0   0

If you want a static IP for wifi, then:

sudo nano /etc/dhcpcd.conf

Add these to set the static IP

# tonib: Static IP for wifi
interface wlan0
static ip_address=192.168.1.100/24
static routers=192.168.1.1

Shoesbox settings

On the browser, go to “/setting/edit”, and set the configuration:

Music path

Path on Raspberry file system where the MP3 files are stored

Music trashcan folder

Path on Raspberry file system where the MP3 files will be moved when they are “deleted”

Youtube downloaded songs destination

Path on Raspberry file system where are stored the downloaded MP3 files

Shared folder

UNC path for the Samba shared folder corresponding to the “Music path” directory

Speech command line

Command line used to speach texto on the Raspberry speakers

Initial message

Text speaked on the Raspberry speakers when it’s booted

Wikipedia host

Wikipedia hostname used to fetch an image for the artists

Wikipedia artist image selector

HTML selector to fetch the artists images on the wikipedia page

Keypad device

Device of the keypad to control the player. Set empty if you don’t have a keypad

Keypad usage

  • Key 7 = Switch between radio and MP3 files play

  • Key 0 = Stop

  • Key Enter = Play

  • Key “.” = Pause

  • Key “+” = Increase volume 10%

  • Key “-” = Decrease volume 10%

  • Key “*” = Speak the current playing song / radio info

  • Key 2 = Play previous song / radio

  • Key 3 = Play next song / radio

Remarks

Artists images are stored on [app_root]/public/artist_images/. If you upgrade or reinstall the app, keep in mind this

Licenses

Shoesbox is distributed under MIT License. It distributes the following software:

  • bootstrap-slider (Apache License)

  • jquery-ui (MIT license)

  • jquery-cookie (MIT license)

  • toastr (MIT license)

About

A music player for Raspberry Pi

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published