Page 1 of 5 123 ... LastLast
Results 1 to 10 of 46

Thread: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

  1. #1
    Join Date
    May 2006
    Location
    On your couch
    Beans
    60
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Wink HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    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:



    Now then...

    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:
    1. 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
    2. 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).
    3. 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).
    4. THE KEY: Once you've made the edits, you need to restart nautilus with the following command:
    Code:
    nautilus -q
    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


    DETAILS:

    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 ):

    Code:
    cd /NAVIGATE/TO/YOUR/MUSIC/DIRECTORY
    ls > music.txt
    That should make a nice text file, seperated by linebreaks (\n) for the next step.

    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):

    Code:
    php icons.php > /home/aashay/.nautilus/metafiles/YOURMETAFILE.xml
    Again, since my Directory is called /media/fat/My Music, my file was called file:%2F%2F%2Fmedia%2Ffat%2FMy%2520Music.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:

    Code:
    <file name="THE FOLDER WHOSE ICON YOU ARE MODIFYING" timestamp="UNIXTIMESTAMP" custom_icon="ICON NAME SUCH AS FOLDER.JPG"/>
    Again, use some common sense and replace all the appropriate stuff

    So here is my code:
    Code:
    <?php
    
    /*
        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));
    fclose($handle);
    
    $lines = explode ("\n", $contents);
    
    
    
    echo "<?xml version=\"1.0\"?>\n<directory>";
    foreach ($lines as $value)
    {
        if ($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
    
    echo "</directory>\n";
    clearstatcache(); //not really sure if we need this
    exit ();
    
     ?>
    Finally make sure to restart nautilus with:

    Code:
    nautilus -q
    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!
    -----------------------------
    -Aashay Desai (NinjitsuStylee)

  2. #2
    Join Date
    Nov 2006
    Beans
    57

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    hey
    i tried to follow your post, but couldn't make it..
    is there any way you could (please) clearify the commands a total noobie should make in order to make my music folder much much nicer?..
    i recently moved my music folder to a new USB external drive - and unfortunately everytime i plug it out and then in again the icons are resetted to the default one - and all of my work in changing them to the album covers is ruined..

    hopefully you could help
    chikko.

  3. #3
    Join Date
    May 2005
    Location
    Yoshi Island
    Beans
    514
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    two things, you forgot to do;
    Code:
    chmod 755 icons.php
    to make it executable and;
    Code:
    sudo apt-get install php5-cli
    is that package required


    Also can you make it so that its case insensitive like folder.jpg =! Folder.jpg, because other wise I have to go change alot of my Folder.jpg to folder.jpg.....just asking because I am lazy.....otherwise everything works perfectly.

  4. #4
    Join Date
    Jan 2005
    Beans
    Hidden!

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Can this be cleaned up a little? Im having a time following it. Also does this work On subfolders?

    Im actually surprised it took this long to get responses and me to see this thread.

    EDIT: Yeah. Im sorry. This is really messy and I cant follow half of this.

    • Where does the php code go? "music.txt" or "/home/user/.nautilus/metafiles/YOURMETAFILE.xml"


    I think this could be a awesome How-To it just needs some work on the order and locations of things.
    Last edited by MetalMusicAddict; February 8th, 2007 at 11:44 PM.

  5. #5
    Join Date
    May 2005
    Location
    Yoshi Island
    Beans
    514
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    ok this is how I first did it.
    open terminal, install the necessary php if you do not have it
    Code:
    sudo apt-get install php5-cli
    gedit icons.php
    and pasted the following into gedit;
    Code:
    <?php
    
    /*
        Used in conjunction with nautilus metafile for music folder Folder.jpg replacement!
    */
    
     $time = mktime();
    $dir = "/home/redemma/Multimedia/Music/Hardcore, Metal & Screamo/"; //this is the music directory you wanna change
    
    $filename = $dir . "music.txt";
    
    $handle = fopen($filename, "r");
    $contents = fread($handle, filesize($filename));
    fclose($handle);
    
    $lines = explode ("\n", $contents);
    
    
    
    echo "<?xml version=\"1.0\"?>\n<directory>";
    foreach ($lines as $value)
    {
        if ($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"; //changed Folder.jpg to 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\"/>"; //again changed Folder.jpg to folder.jpg
                            
                }
            }//end if statment: file_exists
    
        }
    }  //end foreach
    
    echo "</directory>\n";
    clearstatcache(); //not really sure if we need this
    exit ();
    
     ?>
    note the difference in our folders, and I use folder.jpg instead of Folder.jpg. so make the appropriate changes, save and exit, ** I have put bold comments to areas of the script I have edited **

    Code:
    chmod 755 icons.php
    Now cd to your music directory, and then create a list of folders, so I did this;
    Code:
    cd ./Multimedia/Music/Hardcore\,\ Metal\ \&\ Screamo/
    ls > music.txt
    this should create the music.txt in your music folder for me its just where I keep all my metal and hardcore cds. now the final step is to run icons.php so from here; or from home, thats what I did; just make sure you use your metafile, and not exactly what I do in the second line. if your run from your music folder make sure you put the full path to icons.php!

    Code:
    cd ~/
    php icons.php > /home/redemma/.nautilus/metafiles/file\:%2F%2F%2Fhome%2Fredemma%2FMusic%2FHardcore%252C%2520Metal%2520%2526%2520Screamo.xml
    nautilus -q
    go to the directory and viola!
    Last edited by spockrock; February 9th, 2007 at 12:18 AM.

  6. #6
    Join Date
    Jan 2005
    Beans
    Hidden!

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Ok. I got it working. I need to make it work with subfolders somehow. I have my music organized "Artist/Album/file.mp3". So if theres nothing to /Artist I get no picture.

    Is there a way to make subdirs also get scanned? So it picks up the image in "Artist/Album/cover.jpg"?
    Last edited by MetalMusicAddict; February 9th, 2007 at 01:24 AM.

  7. #7
    Join Date
    Aug 2005
    Location
    Tamworth, Australia
    Beans
    119
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Quote Originally Posted by MetalMusicAddict View Post
    Ok. I got it working. I need to make it work with subfolders somehow. I have my music organized "Artist/Album/file.mp3". So if theres nothing to /Artist I get no picture.

    Is there a way to make subdirs also get scanned? So it picks up the image in "Artist/Album/cover.jpg"?
    There is a way to do it, but it involves making a function and doing recursive calling to that function if it detects a directory. Something like:

    if (is_dir($value)){ cd_to_dir_and_call_function_again; }

    might be needed. I'll work on this when I get home, and post my results (if I get any)


    EDIT: also, this could be a slight problem. I have my music directories arranged similar to yours, and this is what I see when doing a list of them recursivley:

    Korn
    -- Life is Peachy
    -- -- folder.jpg
    -- -- (rest of songs)
    -- Follow The Leader
    -- -- folder.jpg
    -- -- (rest of songs)
    -- Take A Look In The Mirror
    -- -- folder.jpg
    -- (rest of songs)

    so which folder.jpg do we use on the /Korn folder?

    I think if we can get this script to be recursive, so that it would pick up into the .xml file the sub dirs like the three I list above, then all that needs doing is put an artist image into the /Artist dir, and go from there. Does that sound like a plan?
    Last edited by Ahriman; February 9th, 2007 at 08:22 AM. Reason: new thought
    :: Do Not Click Here ::

    Code poet [My paradise is war]

  8. #8
    Join Date
    Aug 2005
    Location
    Tamworth, Australia
    Beans
    119
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Below is my updated code. This version takes out the need for the first step (cd /YOUR/MUSIC/PATH | ls > music.txt) as it searches for all directories and finds the ones that contain a "folder.jpg" file inside. All that you need to do it change the $dir path as instructed in the first few lines.

    This is only a change to the PHP code; all other steps remain the same.

    It appears to create a proper xml listing, but for some reason I cannot get nautilus to show the folder icons correctly. I'm sure it's my setup, as the original instructions didn't work for me as well. Either way, let me know if there are any problems with the below code.

    Also note: this assumes that the file name is "folder.jpg" I was unable to get it to differentiate between "Folder" and "folder". PHP sees both as the same o.O

    PHP Code:
    <?php
    /*
        Used in conjunction with nautilus metafile for music folder folder.jpg replacement!
    */

    $delim strstr(PHP_OS"WIN") ? "\\" "/";
    $time mktime();
    $dir "/media/music"// YOUR MUSIC PATH GOES HERE ... NO TRAILING SLASH 

    echo "<?xml version=\"1.0\"?>\n<directory>\n";

    function 
    retrieveTree($path)  {
        global 
    $delim;
        global 
    $time;

        if (
    $dir=@opendir($path)) {
            while ((
    $element=readdir($dir))!== false) {
                if (
    is_dir($path.$delim.$element) && $element!= "." && $element!= "..") {

                        
    $newval str_replace(" ""%20"$element); //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 

                        
    $dirname $path.$delim.$newval;
                        
                        
    $newdir str_replace("/""%2F"$dirname);
                        
                        if(
    file_exists($dirname.$delim.'folder.jpg') && (filesize($dirname.$delim.'folder.jpg') < 1048576)){
                            echo 
    "<file name=\"$newdir\" timestamp=\"$time\" custom_icon=\"folder.jpg\"/>\n";
                        }

                        
    $array[$element] = retrieveTree($dirname);
                }
            }
            unset(
    $parent);
            
    closedir($dir);
        }
        return (isset(
    $array) ? $array false);
    }
    retrieveTree($dir);
    echo 
    "</directory>";

    ?>
    :: Do Not Click Here ::

    Code poet [My paradise is war]

  9. #9
    Join Date
    Jan 2005
    Beans
    Hidden!

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Thanx for the effort. The new code didnt work for me. I hope we can get this sorted out. I think this is a great feature for music lovers if we can work it out.

    Maybe this could even be made into a little app? I know a python programmer. Something simple like defining the root dir of your music and it does the rest?

  10. #10
    Join Date
    Aug 2005
    Location
    Tamworth, Australia
    Beans
    119
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    I looked through my code and fixed the problems, however, there is something that I have found that makes my contribution abit pointless in the end.

    I fixed up the output so that nautilus will actually find and use the folder.jpg files from the directories that are in the folder you define (in my example it is /media/music/). However, when I define in that .xml file a sub-dir, it doesn't work.

    I think that in order to have the album covers on sub directories, the script needs to be run on each and every artist in your music collection, and for those with massive collections .... thats a loooooong time.

    I'll keep trying to refine the code so that it will let nautilus use the folder.jpg's with sub directories. I post my current code below in case anyone smarter than me see's the problem

    PHP Code:
    <?php
    /*
        Used in conjunction with nautilus metafile for music folder folder.jpg replacement!
    */

    $delim strstr(PHP_OS"WIN") ? "\\" "/";
    $time mktime();
    $musicpath "/media/music"// YOUR MUSIC PATH GOES HERE ... NO TRAILING SLASH 
    $dirstripcnt strlen($musicpath)+1;
    echo 
    "<?xml version=\"1.0\"?>\n<directory>\n";

    function 
    retrieveTree($path)  {
        global 
    $delim;
        global 
    $time;
        global 
    $dirstripcnt;

        if (
    $dir=@opendir($path)) {
            while ((
    $element=readdir($dir))!== false) {
                if (
    is_dir($path.$delim.$element) && $element!= "." && $element!= "..") {

                        
    $newval str_replace(" ""%20"$element); //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 

                        
    $dirname $path.$delim.$newval;
                        
                        
    $newdir substr($dirname,$dirstripcnt);
                        
                        if(
    file_exists($dirname.$delim.'folder.jpg') && (filesize($dirname.$delim.'folder.jpg') < 1048576)){
                        
                            echo 
    "<file name=\"$newdir\" timestamp=\"$time\" custom_icon=\"folder.jpg\"/>\n";
                        }

                        
    $array[$element] = retrieveTree($dirname);
                }
            }
            unset(
    $parent);
            
    closedir($dir);
        }
        return (isset(
    $array) ? $array false);
    }
    retrieveTree($musicpath);
    echo 
    "</directory>";

    ?>
    The XML file that this creates looks like this:

    Code:
    <?xml version="1.0"?>
    <directory>
    <file name="Butterfingers" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Vast" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Zeromancer" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Silverchair" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Miscellaneous" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Kittie" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Korpiklaani" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Godsmack" timestamp="1171060487" custom_icon="folder.jpg"/>
    <file name="Prodigy/Miscellaneous" timestamp="1171060487" custom_icon="folder.jpg"/>
    </directory>
    In the above, only the last entry (Prodigy/Miscellaneous) does not have the image displayed.
    Last edited by Ahriman; February 9th, 2007 at 11:47 PM.
    :: Do Not Click Here ::

    Code poet [My paradise is war]

Page 1 of 5 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •