Categories
Linux open source Raspberry Pi

Maintaining the Raspberry Pi Squeezebox server (aka Logitech Media Server)

I wrote earlier about the Logitech Media Server (LMS), open source software that I’ve used to turn a Raspberry Pi into a music server for my Squeezebox devices. I’m using my Raspberry Pi based Logitech Media Server a couple of months and I’ve grown very fond of it. What started as an experiment now has become a device I’m starting to rely on. I guess that eventually I have to replace the USB-HDD that I connected to the Raspberry Pi with a better one. In the meantime however I do need to maintain the LMS. In this blogpost I’ll explain how I add and remove music files from the LMS and create a simple backup of your music files. Finally I provide a tip to debug problems with the Logitech Media Server. All software that I used for this project is free and open source.

Adding, changing and deleting music files

When I buy a new CD I want to add it to my LMS. All the ripping is done using Asunder, a low resource ripper for Linux. Asunder has a simple interface but it has many options can encode to many different formats. It can also tag the files using CDDB but I use MusicBrainz Picard because does a much better job when it comes to tagging (in addition MusicBrainz can organize your digital music library). The tagger completes the metadata on the music files which is very convenient when uploading the files to the LMS. A simple example is that album art is added to the file.

Now about moving the encoded files to the LMS. At first I unmounted the USB hard disk from the LMS, removed it and connected it to the laptop and copied the albums. For adding new albums this proved to be be a clumsy method and I quickly found myself looking for an alternative.

I decided to use FTP to transfer files over the network to the Raspberry Pi. FTP is a network protocol to transfer files between a client and a server. The software that I’m using is either FileZilla or gFTP. They have basically the same functionality but gFTP is not available for Windows while FileZilla is available for GNU/Linux, OSX and Windows. Working with both is easy enough.

Later I also used the scp command (Linux, OSX) in the terminal and simply copy the music files on my PC to the music folder on my Raspberry Pi powered LMS.

Read this if you (like me) run into problems with file ownership on your Raspberry Pi. In the past I couldn’t set the ownership for the USB hard disk on the Raspberry Pi. Only root was able to write to the disk. The reason is a bit technical and maybe confusing but I had used the Windows FAT filesystem for the USB hard disk and when I mounted it on my Linux laptop (Puppy Linux distribution), ownership of all files was changed by Puppy Linux to root. At this point it was impossible to change ownership and permissions with chmod and chown from the media server. To solve this problem I had to first unmount and mount the USB hard disk. To mount the hard disk use the following general command is used:

mount device mount-point -o uid=foo -o gid=foo

or in my specific case

sudo umount ~/media/usb-drive

and then mount

sudo mount /dev/sda1 ~/media/usb-drive -o uid=pi -o gid=pi

This command sets the ownership of all files on the USB hard disk to pi instead of root enabling me to use FileZilla and gFTP to copy files from a remote PC to the Raspberry Pi.

Adding Podcasts to the server

Podcasts can be easily added to the Logitech Media Server and there is no need to subscribe to a service. First the Podcasts app must be added to myApps on the Squeezebox player or players. Next to add podcasts to the list a plugin needs to be installed. To do this open the web interface in your browser and type:

<your_Raspberry_Pi_ip_address:9000> (in my case 192.168.178.69:9000)

Choose Settings at the bottom right of the web browser and then choose the Plugins tab. Now enable the Podcasts (v2.0) plugin and reboot the Raspberry Pi for the changes to take effect. The Podcasts plugin is now active and can be entered through a new tab in the Settings menu. In this tab new feeds can be entered that will immediatly be available on the Squeezebox players. To find a certain feed look for the rss feed of your favorite podcast and copy the link into ‘add a new feed’ in the podcast tab of the Settings menu mentioned above (e.g. http://feed.thisamericanlife.org/talpodcast for This American Life).

Creating a backup of the music collection

I invested a lot of time in ripping my CD collection so it would be a shame if I lost my music files due to a hard disk crash. I therefore use a very simple backup method, largely copied from the Raspberrypi.org website to ensure that my files are safe. First make sure that there’s enough harddisk space available with df -h. Next do:

tar -cvf backup.tar.gz ~/media/usb-drive

This creates a file ‘backup.tar.gz’ that contains files in /media/usb-drive, the mounting point of my USB drive and places it in the same map. Next I use (again) Filezilla to move the backup file to my desktop computer. Alternatively the ripped files on the PC they were ripped on can serve as a backup.

Debug problems with the Logitech Media Server

I didn’t encounter much problems with the LMS but if you do take a look into the log file of the server. This can be done opening a terminal on your PC and login into the Rasperry Pi with:

ssh pi@<your_network_ip_address_of_the_server>
cat /var/log/squeezeboxserver/server.log

The sudo ssh command prompts for the password of the Raspberry Pi. Now look for anything suspicious in the log, copy it and do an internet search with your preferred search engine. Chances are someone already encountered the same problem.

Categories
programming

Humble start of Bash scripting (part 2)

As a follow up on my Bash scripting efforts that I started this year I wrote a script that resizes a photo to a specified width in pixels. The script should work both on Linux and OSX (tested on OSX, will test on Linux later). For this script to work ImageMagick needs to be installed. The script tests if an argument is specified (the original photo of course), if ImageMagick has been installed and if the file output.jpg exists. If output.jpg exists the user gets the option to overwrite the existing file or exit the script. Finally the user needs to specify the width in pixels of the output.jpg.

If you want to use this script, copy the code below and paste it into an editor like vim, vi or Geany. Save it e.g under the name resize and make this file executable by typing.

chmod 755 resize

Now if the photo is in the same folder as the script just type.

./resize yourphoto.jpg

Cheers.

The script

#!/bin/bash
# written by Eric Buijs 12 january 2019

if [ $# -eq 0 ]
	then
		echo You need to specify a file.
		echo e.g: resize photo.jpg
		exit 1
fi

if [ ! $(which convert) ]
	then
		echo This script requires Imagemagick!
		echo You can download it at http://www.imagemagick.org/
		exit 1
fi

if [ -e output.jpg ]
	then
	echo output.jpg already exists.
	read -p "Do you want to overwrite it? (Y/N) " answer
	echo $answer
	if [ $answer = "N" ]
		then
		exit 1
	fi
fi

read -p "What is the desired width in px: " width
convert $1 -resize $width output.jpg
Categories
programming

Humble start with Bash scripting

To kick off the year I started to learn Bash scripting, something I wanted to do a very long time. I humbly began with tutorials on the web like this one and I’m rewriting scripts from Smokey01, a Puppy Linux user. As an exercise I simply rewrote this script to work on OSX. If you want to use it you need to install exiftool. I installed exiftool with Homebrew and typed brew install exiftool but there’s also a dmg file available. If you don’t use Homebrew you do have to change the check if exiftool is installed.

Now for the script. It reads a jpeg file that must contain geo-coordinates. After some checks for parameter and exiftool installed it reads the geo-coordinates and stores them in the variable coord. This variable is then added to a Google search query and the result displayed in the browser.

Save the script e.g. with the name place and run with place /path/to/photo.jpg to display the location where photo.jpg was taken.

The script

1 #!/bin/bash
2 # Originally written by smokey01 28 May 2017
3 # Rewritten for OSX by Eric Buijs 9 Jan 2019
4 if [ $# -eq 0 ]
5   then
6     echo You need to specify a file.
7     echo EG: place photo.jpg
8     exit 1
9 fi
10 
11 if [ ! -d /usr/local/Cellar/exiftool ]
12   then
13     echo "This script requires exiftool!"
14     exit 1
15 fi
16 
17 coords=`exiftool -n -p '$GPSLatitude,$GPSLongitude' $@`
18 read -e -p "Do you want to see the location in your Browser? " choice
19 [[ "$choice" == [Yy]* ]] &amp;&amp; open https://www.google.com/search?q=$coords || exit 1
Categories
Linux PC

Give your old PC a new life

When I came home the other day my neighbours were loading electronics on their bicycles (I live in the Netherlands you know) to dispose of them. Among all the stuff was a desktop computer that looked in pretty good shape. It was a Packard Bell iMedia S1800. I informed why they would dispose of the PC and they told me that according to their daughter it had become unusable. They are very nice people so I asked them if I could have the PC. They agreed to it and I took the desktop with me.

Back home I took another look at the computer and it was even nicer than I expected. It didn’t have a scratch and when I opened it it looked clean. That night I booted the PC and quickly found out it had Windows 10 running. The PC was slow as molasses and it was very noisy. I felt I had already found the cause of the daughter complaining, Windows 10. I had no intention to run Windows so I took out my Puppy Linux disk (Xenial Pup 7.5) and rebooted the PC.

The difference couldn’t have been greater. Puppy Linux booted fast and ran even faster. I got the idea to make this a general purpose workstation that, if goes well, can replace my iMac. How much I love Puppy Linux I don’t think it’s suitable for my purpose. Besides all the usual tasks I use my iMac for light 3D CAD work (for 3D printing), web design and video editing. I also like to have access to a broad software repository because I like to test new software and to replace the workflow I have on the Mac. In this department Puppy Linux can be lacking due to the Puppy Package Manager which differs from the mainstream package managers.

I therefore decided to give Ubuntu MATE 18.04 LTS (Bionic Beaver) a spin. My son already runs Ubuntu so I’m familiar with it and the MATE desktop is relatively lightweight (Gnome 2). Installation from a USB drive went flawless (overwriting W10 in the process). The desktop looks very clean and the software suite is great. I can add software through the new Software Boutique and if it isn’t there I have access to the Ubuntu repository (through apt). For a full review of MATE 18.04, read this.

So here I am. A nice Packard Bell is sitting on my desk instead of having become e-waste. If you read this don’t throw away your old PC because Windows 10 made the experience a nightmare. Install Ubuntu MATE or any other Linux distro you like and enjoy. In the mean time you’ll be doing the environment a favour. Cheers.