Archive

Posts Tagged ‘banshee’

Recovering a Corrupted Banshee Database

February 27th, 2011 11 comments

A couple of nights ago, I left Banshee running overnight, filling my phone with music to listen to the next day at work. Sometime during that process, the media player crashed in a big way, and my entire system ground to a halt. When I woke up the next morning, my computer was frozen solid, with no keyboard or mouse input accepted, and the system clock hadn’t advanced since 11:16pm the previous night. I did a hard reboot, hoping that all would be well when it came back up.

Boy was I wrong.

The Problem

It seems that when Banshee went down, it took my library database file with it. Now, whenever I launch the application, I get a lovely dialog box that looks something like this:


Launching the application from the command line provides more details:

jonf@THE-LINUX-EXPERIMENT: ~/.config/banshee-1$ banshee-1
[Info  11:20:32.175] Running Banshee 1.9.0: [source-tarball (linux-gnu, x86_64) @ 2010-12-09 13:07:07 EST]
[Warn  11:20:32.451] Service `Banshee.Database.BansheeDbConnection’ not started: The database disk image is malformed
database disk image is malformed
[Warn  11:20:32.453] Caught an exception – Mono.Data.Sqlite.SqliteException: The database disk image is malformed

Apparently, the SQLite database that forms the backend of Banshee is severely corrupted, and the application can’t open it for reading. Based on the command line output, I figured that Banshee uses SQLite3 for its database, and after a little bit of research, I found out that it stores the database file at ~/.config/banshee-1/banshee.db. After installing the SQLite3 package from my repositories with the command sudo apt-get install sqlite3, I was able to connect to the database without issue. A little bit of reading over at sqlite.org showed me how to do an integrity check on the database, which came back with some nasty results:

jonf@THE-LINUX-EXPERIMENT:~/.config/banshee-1$ sqlite3 -interactive banshee.db
SQLite version 3.6.22
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite> PRAGMA integrity_check;
*** in database main ***
Main freelist: 2291 of 2292 pages missing from overflow list starting at 18928
On tree page 28 cell 4: Child page depth differs
On tree page 28 cell 6: 2nd reference to page 15475
On tree page 28 cell 6: Child page depth differs

On tree page 16807 cell 25: Child page depth differs
On tree page 16807 cell 26: 2nd reference to page 18171
On tree page 16807 cell 26: Child page depth differs

Each line of this output refers to a broken or corrupted index, with a total of 99 errors reported. Yikes.

The Solution

Before attempting to fix the problem, I made a backup of the broken database, just in case some data could be resurrected from it. To do this, I made sure that Banshee wasn’t running, and then made a copy of the database file with the command cp ~/.config/banshee-1/banshee.db ~/.config/banshee-1/banshee.db.old.

Since the integrity check showed a number of broken or corrupted indices, I thought perhaps I would be able to recover the database by rebuilding all of its indices. A quick scan of the SQLite documentation turned up the REINDEX function. Again, I connected to the database through the command-line interpreter, and gave it a shot:

jonf@THE-LINUX-EXPERIMENT:~/.config/banshee-1$ sqlite3 -interactive banshee.db
SQLite version 3.6.22
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite> REINDEX;
Error: database disk image is malformed

That clearly didn’t work.

My next thought was to drop and re-create all of the indices in the database, in hopes that I could rebuild them. I used the graphical tool sqliteman (available from your repositories with the command sudo apt-get install sqliteman) to dump the database schema out to a text file and then scrolled through the file looking for each index. I managed to drop all but four of them, but got the image malformed error whenever I tried to drop the remaining four or recreate any of the ones that were successfully dropped.

Out of ideas, I resorted to attempting to recover what data I could from the mangled file. Using sqliteman, I created a dump of my library data to go along with the schema dump that I had created earlier. The good thing about this dump is that it contains all of the data with none of the indices. Next, I opened up a terminal and navigated to the temporary directory where I had saved the database dump. Using the sqlite3 command line interpreter, I built an image of the old database from the dump:

jonf@THE-LINUX-EXPERIMENT:~/Desktop/banshee$ sqlite3 -interactive banshee.db
SQLite version 3.6.22
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite> .read dump.sql

Finally, I copied the newly created database into the banshee data directory with the command cp ~/Desktop/banshee/banshee.db  ~/.config/banshee-1/banshee.db.

The next time I started the application, all of my data was restored.

Prevention

I’ve put a lot of work into collecting and maintaining all of the music in my Banshee library. In order to avoid losing all of that work, I’ve decided to write a short script that takes a backup image of the library database every so often, and puts it in a safe place on my hard drive. Once I get that put together, I’ll throw it up on here for so that everybody can use it.




On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.

How to Compile Banshee 1.9.0 on Ubuntu 10.04

December 9th, 2010 1 comment

Regular readers of this site will know that I’m no fan of Rhythmbox. When I recently installed Ubuntu 10.04 on my desktop PC, I decided to give Gnome’s default media player a few days to win back my affection. Unfortunately, while Novell’s Banshee project appears to be moving ahead with lots of great new features, Rythmbox still suffers from the issues that I outlined in my now infamous lambasting of it, nearly 8 months ago. To be fair, the pre-installed version of Rythmbox is only 0.12.8 on Ubuntu 10.04 (the same one that I reviewed previously), while the project has forged ahead to version 0.13.2.

Regardless, I prefer to listen to my music with Banshee, and I’m itching to try the latest version. On November 10th, the project released Banshee 1.9.0, and it looks positively excellent. I decided to give it a go, and downloaded the source tarball from the project’s website. Following are the steps that were necessary to install it:

  1. Head over to a terminal and install intltool, libgtk2.0-dev, libgtk2.0-cil-dev, libmono-dev, mono-gmcs, libmono-addins-cil-dev, monodoc-base, boo, libboo-cil-dev, libmono-addins-gui-cil-dev, libndesk-dbus-glib1.0-cil-dev, libgdata-dev, libgdata-cil-dev, libtag1-dev, libtaglib-cil-dev, sqlite3, libsqlite3-dev, libgconf2.0-cil-dev, libmtp-dev, libmono-zeroconf1.0-cil, libmono-zeroconf1.0-cil-dev, libwebkit-dev, libwebkit-cil-dev, and libsoup-gnome2.4-dev with the following command:

    sudo apt-get install intltool libgtk2.0-dev libgtk2.0-cil-dev libmono-dev mono-gmcs libmono-addins-cil-dev libmono-addins-gui-cil-dev monodoc-base boo libboo-cil-dev libndesk-dbus-glib1.0-cil-dev libgdata-dev libgdata-cil-dev libtag1-dev libtaglib-cil-dev sqlite3 libsqlite3-dev libgconf2.0-cil-dev libmtp-dev libmono-zeroconf1.0-cil libmono-zeroconf1.0-cil-dev libwebkit-dev libwebkit-cil-dev libsoup-gnome2.4-dev

  2. Next, you’ll need GStreamer and a few of its base plugins package: libgstreamer0.10-dev and libgstreamer-plugins-base0.10-dev

    sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

  3. If you want to play music encoded in non-free formats like mp3, you’ll also need a few restricted GStreamer libraries like gstreamer-plugins-good, gstreamer-plugins-bad, gstreamer-plugins-bad-multiverse, gstreamer-plugins-ugly, and gstreamer-plugins-ugly-multiverse.

    sudo apt-get install gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-bad-multiverse gstreamer-plugins-ugly gstreamer-plugins-ugly-multiverse

  4. Since I don’t have an iPod or similar Apple device, I’ve configured my installation to disable Apple device support. If you have an iPod, you can lose the –disable-apple-device and –disable-ipod flags after the configure command, but you’ll also need to add a couple of extra libraries to your system. To compile and install Banshee, navigate to the folder where you unzipped the tarball, and type the following in your terminal:

    ./configure –disable-appledevice –disable-ipod
    sudo make
    sudo make install

Banshee should now be installed. From your terminal, type

banshee-1

as a sanity check. Once the application launches, select Help > About and ensure that the version number is 1.9.0. If so, you should be good to go.

I’ll try to post a full review of this latest version of Banshee within a couple of days. In the mean time, happy listening!




On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.

Samsung Captivate SGH-i896 Meets Linux

November 7th, 2010 2 comments

Yesterday, I picked up the newly launched (in Canada) Samsung Captivate. So far, I’m extremely impressed with the device. The super amoled display is gorgeous, the touch screen is responsive, and the UI is stunning to look at and use. Coming from a Blackberry Curve 8310, this phone is like a digital orgasm.

Once I finished gushing over how awesome this phone is, I decided to try and get it to interact with my Linux Mint 9 Isadora install. For now, I just want to be able to transfer images and music to and from the device, although later on, I’d like to get a development environment set up and try my hand at writing some apps.

My first try at getting the phone to play nicely with Linux was not successful. It took me a little bit of fooling around before I could figure it out, but here goes:

  • On the phone, navigate to Settings > Applications > USB Settings and make sure that ‘Ask on Connection’ is selected
  • Plug your phone into the a USB port, and when prompted, select ‘Mass Storage’ from the dialog that appears on the phone
  • At this point, if you open up your Computer in Nautilus, you should see an icon that says something like SAMSUNG SGH-I896, but you won’t be able to interact with it in any way
  • On the phone, grab the notification bar at the top of the home screen and drag it down
  • In the notifications area, tap USB Connected, and when prompted, select Mount from the dialog
  • Back in Nautilus, the icon under Computer should now say something like SAMSUNG SGH-I896: 14GB Filesystem, and you should be able to read and write to the card

With these steps complete, I was able to interact with the phone through the file system and from within Banshee and FSpot. I’m not sure why the phone won’t allow Linux to mount its storage devices by default when in Mass Storage mode, but this little work around seems to make it behave correctly.

Drop me a line in the comments if you have any Linux/Android compatibility questions, and I’ll do my best to help you out.




On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.

Trying Mint – I likes what I sees.

January 16th, 2010 8 comments

While my initial plan for January was to stick with Windows 7 and perhaps try out Fedora 12, a bad DVD interrupted the Fedora install progress. Out of sheer convenience, I’d planned on running Linux Mint in a VM and had pulled the ISO earlier in the week. “Aha!” I thought. “I’ll install this instead of Fedora and see what’s what.”

My initial impressions are that Mint is perhaps the first Linux distribution that I’d enjoy using on a day-to-day basis. With only a few minor tweaks (activating multiple monitors and using optical out for sound), I have a completely functional desktop environment. Compiz is totally integrated into the experience, degrades gracefully if needed, and is used to enhance the UI rather than provide unneeded eye candy.

Taking a page out of Jon’s book, I also installed Banshee for media playback. What a difference from previous media player experiences – my BlackBerry was automatically detected, synced with my library and folders were built properly in the MediaCard/BlackBerry/music directory. Now, all I need is some better music and I’ll be set!




I am currently running various *BSD variants for this Experiment.
I currently run a mix of Windows, OS X and Linux systems for both work and personal use.
For Linux, I prefer Ubuntu LTS releases without Unity and still keep Windows 7 around for gaming.
Check out my profile for more information.

Filling a Zune from Linux

January 1st, 2010 2 comments

Thinking that I was up for a challenge, I decided to spend the day figuring out how to put the music in my Banshee library onto a Microsoft Zune. Since my library contains a good number of FLAC files that I’ve ripped in from my CD collection, my solution called for a caching system that converts the FLAC files to mp3s and stores them so that the playlist can be changed without having to re-convert the FLAC files into something that the Zune can play on every sync. My weapons of choice for the project were a Windows XP instance running inside of Sun Virtual Box, and 126 lines of perl script.

The Steps:

  1. Create a WinXP VM that has the Zune software installed and can see two shared folders on my Linux machine:
    1. My normal Music folder, which contain my entire collection
    2. The cache folders, which contain all of the FLAC files in my collection, but converted to mp3 so that the Zune can play them
  2. Open the Banshee database, located at ~/.config/banshee-1/banshee.db
  3. Select all of the FLAC files in the playlist that we’d like to put on the Zune
  4. For each, check if it has been converted and cached
    1. If so, simply add the path to the cached copy of the track to an m3u file in the cache folder
    2. If not, convert the track, and then add the path to the cached copy of the track to an m3u file in the cache folder
  5. Select all of the mp3 files in the playlist that we’d like to put on the Zune
  6. Put those in a separate m3u file that is located in the Music folder.
  7. Boot up the Zune software on the VM. It should autoscan it’s monitored folders, find the m3u playlists, and put them in its library
  8. Sync the playlists with the Zune by dragging and dropping them to the device icon in the lower left corner of the screen

As previously mentioned, steps 2 through 6 were accomplished by way of a perl script that I can run as often as I like:

#/usr/local/bin/perl

#Requirements: libdbd-sqlite3-perl, flac, lame

#We need database support
use DBI;

#Database path – change this to reflect your user environment
my $dbpath = “dbi:SQLite:dbname=/home/jon/.config/banshee-1/banshee.db”;

#Playlist name – change this to reflect the playlist that you want to export
my $plistname = “Favorites”;

#Cache Path – the path to the directory where you’ve been caching converted FLAC files
my $cachepath = “/home/jon/Storage/mp3Cache/”;

#Music Path – the path to the folder where your music collection is actually stored
my $musicpath = “/home/jon/Music/”;

#Connect to the database – no username/password
my $dbh = DBI->connect($dbpath,””,””,{RaiseError => 1, AutoCommit => 0});

if(!$dbh) {
print “Could not connect to database $dbpath”,”\n”,”Exiting”;
exit;
}

#Pull the list of FLAC files for conversion and caching
my $flac = $dbh->selectall_arrayref(“SELECT sme.TrackID, ct.Title, car.Name AS ‘Artist’, ca.Title AS ‘Album’, ct.Uri, ct.Duration AS ‘Length’ FROM corealbums AS ca, coreartists AS car, coresmartplaylistentries AS sme INNER JOIN coretracks AS ct ON sme.TrackID = ct.TrackID WHERE sme.SmartPlaylistID = (SELECT `SmartPlaylistID` FROM `coresmartplaylists` WHERE `Name` = ‘$plistname’) AND ca.AlbumID = ct.AlbumID AND car.ArtistID = ct.ArtistID AND ct.MimeType LIKE ‘%flac’”);

#open the m3u file to write the cached items to
open my $m3u, ‘>’, $cachepath.$plistname.’_cached.m3u’ or die “Error trying to open cache m3u playlist for overwrite. Do you have write permissions in $cachepath ?”;
print $m3u “#EXTM3U\r\n\r\n”;    #note windows \r\n here

#add /music to $cachepath so that files are in a subdirectory, away from the m3u file
$cachepath = $cachepath.”music/”;
if( ! -e $cachepath ) {
`mkdir “$cachepath”`;
}

#loop through the files and check if they need to be cached
foreach my $i (@$flac) {
my ($trackid, $title, $artist, $album, $uri, $length) = @$i;

#correct the uri by removing the file:// prefix and reverting the uri escaping
$uri = substr $uri, 7;
$uri =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;

#fix time into seconds
$length = int($length/1000);

#check if the flac file has already been converted and cached at cachepath
#if not, convert it and put it at cachepath.
my $path = $cachepath . $artist . ‘/’ . $album . ‘/’ . $title . ‘.mp3′;
if( ! -e $path ) {
#file dne, convert it
print “\nTrack: $title by $artist has not yet been cached, converting…”,”\n”;

#make sure that the file actually exists before attempting to convert it
if( ! -e $uri ) {
print “WARNING: Track $title by $artist does not exist at $uri”,”\n”;
} else {

#ensure that cache album/artist directories exist
my $partpath = $cachepath.$artist;
if( ! -d $partpath ) {
`mkdir “$partpath”`;
}
$partpath = $partpath.’/’.$album;
if( ! -d $partpath ) {
`mkdir “$partpath”`;l
}

#do the conversion – we’re chaining flac and lame here, reading in the flac file from $uri, and putting the resulting mp3 at $path
`flac -cd “$uri” | lame -h – “$path”`;
}
}

#add the track to the m3u file – note that these entries are relative to the location of the m3u file in the root of $cachepath
#the paths use a backslash and a \r\n newline so that they work correctly on windows
print $m3u “#EXTINF:$length,$artist – $title\r\n”;
print $m3u ‘\\music\\’.$artist.’\\’.$album.’\\’.$title.’.mp3′,”\r\n\r\n”;
}

#close the m3u file in the cachepath directory
close $m3u;

#TODO: scan the m3u file and delete any files that aren’t in it from the cache directory

#Pull the list of MP3 files and dump them into an m3u file
my $flac = $dbh->selectall_arrayref(“SELECT sme.TrackID, ct.Title, car.Name AS ‘Artist’, ca.Title AS ‘Album’, ct.Uri, ct.Duration AS ‘Length’ FROM corealbums AS ca, coreartists AS car, coresmartplaylistentries AS sme INNER JOIN coretracks AS ct ON sme.TrackID = ct.TrackID WHERE sme.SmartPlaylistID = (SELECT `SmartPlaylistID` FROM `coresmartplaylists` WHERE `Name` = ‘$plistname’) AND ca.AlbumID = ct.AlbumID AND car.ArtistID = ct.ArtistID AND ct.MimeType LIKE ‘%mp3′”);

#open the m3u file to write the cached items to
open my $m3u, ‘>’, $musicpath.$plistname.’.m3u’ or die “Error trying to open music folder m3u playlist for overwrite. Do you have write permissions in $musicpath ?”;
print $m3u “#EXTM3U\r\n\r\n”;    #note windows \r\n here

#loop through the files and check if they need to be cached
foreach my $i (@$flac) {
my ($trackid, $title, $artist, $album, $uri, $length) = @$i;

#correct the uri to become a windows file path
$uri = substr $uri, 7;            #remove file:// prefix
$uri =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;    #correct uri encoding
$uri =~ s/$musicpath//g;            #remove musicpath prefix
$uri =~ s/\//\\/g;                #change forward slashes to backslashes
$uri = ‘\\’.$uri;                #add the leading backslash

#fix time into seconds
$length = int($length/1000);

#add the track to the m3u file – note that these entries are relative to the location of the m3u file in the root of $cachepath
#the paths use a backslash and a \r\n newline so that they work correctly on windows
print $m3u “#EXTINF:$length,$artist – $title\r\n”;
print $m3u $uri,”\r\n\r\n”;
}

#close the m3u file and the database connection
close $m3u;
$dbh->disconnect;

Sorry for the horrible formatting.

The only snag that I hit during the entire process was really my fault – I have a tendency to overcomplicate things, and did so on this project by initially writing the script to output a *.zpl file instead of a *.m3u file. That didn’t work at all, and I ended up simplifying the script greatly by just outputting an *.m3u file and hoping for the best.

On the off chance that the Zune jukebox software refuses to properly update its playlists after you change the *.m3u files, first try deleting them from the application, and then restarting it. If that doesn’t work, you can write a Windows batch script with code similar to the following:

del /q “C:\Documents and Settings\Jonathan\My Documents\My Music\Zune\Playlists\*”
xcopy “\\Vboxsvr\mp3cache\Favorites_cached.m3u” “C:\Documents and Settings\Jonathan\My Documents\My Music\Zune\Playlists”
xcopy “\\Vboxsvr\music\Favorites.m3u” “C:\Documents and Settings\Jonathan\My Documents\My Music\Zune\Playlists”

This script deletes all files from the Zune playlists directory, and then copies each of the *.m3u files that we created with the above perl script directly into the Zune playlists directory. This should force the application to get it’s act together.

Overall, I’m happy with this patchwork job. It allows me to use the Zune on Linux, which is great because the Zune really is a beautiful piece of hardware. Now if only the libmtp guys could get it working natively, without a WinXP VM…

This piece was mirrored at Index out of Bounds




On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.

Going Linux, Once and for All

December 23rd, 2009 7 comments

With the linux experiment coming to an end, and my Vista PC requiring a reinstall, I decided to take the leap and go all linux all the time. To that end, I’ve installed Kubuntu on my desktop PC.

I would like to be able to report that the Kubuntu install experience was better than the Debian one, or even on par with a Windows install. Unfortunately, that just isn’t the case.

My machine contains three 500GB hard drives. One is used as the system drive, while an integrated hardware RAID controller binds the other two together as a RAID1 array. Under Windows, this setup worked perfectly. Under Kubuntu, it crashed the graphical installer, and threw the text-based installer into fits of rage.

With plenty of help from the #kubuntu IRC channel on freenode, I managed to complete the Kubuntu install by running it with the two RAID drives disconnected from the motherboard. After finishing the install, I shut down, reconnected the RAID drives, and booted back up. At this point, the RAID drives were visible from Dolphin, but appeared as two discrete drives.

It was explained to me via this article that the hardware RAID support that I had always enjoyed under windows was in fact a ‘fake RAID,’ and is not supported on Linux. Instead, I need to reformat the two drives, and then link them together with a software RAID. More on that process in a later post, once I figure out how to actually do it.

At this point, I have my desktop back up and running, reasonably customized, and looking good. After trying KDE’s default Amarok media player and failing to figure out how to properly import an m3u playlist, I opted to use Gnome’s Banshee player for the time being instead. It is a predictable yet stable iTunes clone that has proved more than capable of handling my library for the time being. I will probably look into Amarok and a few other media players in the future. On that note, if you’re having trouble playing your MP3 files on Linux, check out this post on the ubuntu forums for information about a few of the necessary GStreamer plugins.

For now, my main tasks include setting up my RAID array, getting my ergonomic bluetooth wireless mouse working, and working out folder and printer sharing on our local Windows network. In addition, I would like to set up a Windows XP image inside of Sun’s Virtual Box so that I can continue to use Microsoft Visual Studio, the only Windows application that I’ve yet to find a Linux replacement for.

This is just the beginning of the next chapter of my own personal Linux experiment; stay tuned for more excitement.

This post first appeared at Index out of Bounds.




On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.