The purpose of this thread is to give you a quick and easy method to make your music folders use the Folder.jpg file to display album covers instead of the default folder icon. Windows XP does this automatically for your folders if you have a Folder.jpg file in the folder.
Here is a screenshot:
This is actually not that great of a HOWTO, but it gives you some insight on how nautilus works
Here's a few things for you to learn:
Gnome will automatically restart nautilus for you. Note: When you go to your music folder to see the changes, it might eat up some of your CPU depending on how many folders you have....it has a lot of icons to display
- Nautilus stores metadata (xml files) in a folder called ~/.nautilus/metafiles and the specific file we will be looking for will be the file that is associated with your music folder. Also, the files' names are encoded using URI encoding so things are a bit goofy. For example, I have my music folder in a folder called /media/fat/My Music (yea yea, I know, spaces are bad in unix filesystems, sue me ). My .xml file is going to be called file:%2F%2F%2Fmedia%2Ffat%2FMy%2520Music.xml
- Basically this file needs to be edited appropriately to reflect whatever changes you want. Make sure that all the edits are done on line 2 (for some reason nautilus likes to jumble up all the file data in one line).
- I used a PHP script to do this, but you can use any type of script to make the edits (details on how I did this below).
- THE KEY: Once you've made the edits, you need to restart nautilus with the following command:
Ok, here's what I did. First I went to my music directory and made a text file of all of my folders using the following commands (things in capitals means use some common sense ):
That should make a nice text file, seperated by linebreaks (\n) for the next step.
ls > music.txt
The next step: Make your script. Since I am comfortable with PHP I used PHP and executed the file using the command line (make sure you have the appropriate packages to run php files from the commandline......php-cli or something):
Again, since my Directory is called /media/fat/My Music, my file was called file:%2F%2F%2Fmedia%2Ffat%2FMy%2520Music.xml
php icons.php > /home/aashay/.nautilus/metafiles/YOURMETAFILE.xml
(Note: If you are having trouble finding your metafile, make some changes by hand to your music directory, ie maybe replace one of the folders, or change the view of it.....then navigate to the .nautilus/metafile directory and organize it by dates modifed, you should see the appropriate file as being one of the most recent ones modified)
Finally, here is my PHP code. It's a bit disgusting and noob but that's because I catered it specifically to my own setup, so don't forget to tailor it to your own setup. Again, you can use any sort of script that loops through a list of your music folders and outputs the data in the following format:
Again, use some common sense and replace all the appropriate stuff
<file name="THE FOLDER WHOSE ICON YOU ARE MODIFYING" timestamp="UNIXTIMESTAMP" custom_icon="ICON NAME SUCH AS FOLDER.JPG"/>
So here is my code:
Finally make sure to restart nautilus with:
Used in conjunction with nautilus metafile for music folder Folder.jpg replacement!
$time = mktime();
$dir = "/media/fat/My Music/";
$filename = $dir . "music.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
$lines = explode ("\n", $contents);
echo "<?xml version=\"1.0\"?>\n<directory>";
foreach ($lines as $value)
//replace special characters.....this is kind of a dumb way to do things, I bet a more leet php coder would be able to find a better function to do this
$newval = str_replace(" ", "%20", $value); //replace spaces
$newval = str_replace(",", "%2C", $newval); //i have some commas in my album names
$newval = str_replace("&", "%26", $newval); //i noticed an ampersand (&) in certain album titles such as Outkast - Speakerboxxx & The Love Below
$filename = $dir . $value . "/Folder.jpg";
$time = mktime(); //Unix time!
if (file_exists($filename)) //we only want to do this if there is actually a Folder.jpg file in there
$size = filesize($filename);
if ($size && $size < 1048576) //if the Folder.jpg file is too big we might have problems, so lets limit it to 1 MB
echo "<file name=\"" . $newval . "\" timestamp=\"". $time . "\" custom_icon=\"Folder.jpg\"/>";
}//end if statment: file_exists
} //end foreach
clearstatcache(); //not really sure if we need this
Load up your music directory and you should be good to go! Again, sometimes it takes forever to load the directory (I do believe they are working on a fix that makes nautilus more efficient when it comes to icons).
If anyone wants more details or would like me to do more work for them along the lines of the php script and such, let me know and I'll make things more automagic when I have time. Otherwise, have fun!