#!/bin/sh

# Optimize rhythmbox database for faster speed
# Copyright 2006 Joel Bryan T. Juliano <joelbryan.juliano@gmail.com>

counter=0
rounds=2

rhythmbox_database_dir="$HOME/.gnome2/rhythmbox"

while [ $counter -ne $rounds ]
do

cp "$rhythmbox_database_dir/rhythmdb.xml" "$rhythmbox_database_dir/rhythmdb_backup.xml"
cp "$rhythmbox_database_dir/playlists.xml" "$rhythmbox_database_dir/playlists_backup.xml"
cat "$rhythmbox_database_dir/rhythmdb.xml" | sed -e '/^[ \t]*$/d;s,^[ \t]*,,;s,>[ \t]*<,><,g;s,[ \t]*$,,' > "$rhythmbox_database_dir/rhythmdb_temp.xml"
cat "$rhythmbox_database_dir/playlists.xml" | sed -e '/^[ \t]*$/d;s,^[ \t]*,,;s,>[ \t]*<,><,g;s,[ \t]*$,,' > "$rhythmbox_database_dir/playlists_temp.xml"
cat "$rhythmbox_database_dir/rhythmdb_temp.xml" | tr '\012' ' ' > "$rhythmbox_database_dir/rhythmdb.xml"
cat "$rhythmbox_database_dir/playlists_temp.xml" | tr '\012' ' ' > "$rhythmbox_database_dir/playlists.xml"

rm -rf "$rhythmbox_database_dir/rhythmdb_temp.xml" "$rhythmbox_database_dir/playlists_temp.xml"

counter=$(( $counter + 1 ))

done
