bump
bump
AMD 64 3000+, 2G RAM, ASUS K8N , XFX GS7800, Linux Mint 9 , WinXP(dual boot/seperate HD)
Stalker's Law: As an online discussion grows longer, the probability of a comparison involving how much the United States sucks approaches one.
You would get just one thumbnail (I also used similar schemes to group several volumes of the same album into one (when they all had different covers). But one could adapt this script to make it recognize such things, refactor a thumbnail and put output it as 'folder.jpg' (or folder.png to prevent interference with windows, as Windows only checks for JPG (and perhaps GIF, but certainly not PNG)).
Anyhow, I haven't taken the time yet to take a look at the script, but I feel I now have quite a steady base in Python to take a look at the litle bug I reported (and perhaps even take a look at your request, but I can't promise it will be soon).
For your problem I'd rather write a whole other script to combine different covers into one (my idea would be to extend the functionality of windows a bit: not limited to 4 covers, but certainly restrictable; ability to include or exclude certain files (e.g. allow 'folder01.jpg' but not 'disc.jpg' or 'back.jpg' and with other files the possibility to choose between an automatic-exclude, automatic-include). But hey, that's just me philosophizing I can promise you won't see such script from me before 2008.
OK. FInish reading this post and then see post below for a version that adds a "No Cover Art" icon to artist folders which contain no albums with cover art for consistency since it looks strange with dinky folder icons and colourful album art mixed in (it doesn't do it for the album folders inside though because since they'd all look like folders they'd already be consistent)
I actually just had a go at this. It does Icons for both the albums and the artist folder. I don't really use bash much but I couldn't stand the thought of writing this kind of user script in PHP so here it is in bash. [Preview image attached to this post]
It's really basic and I only wrote it for my personal use. It won't destroy anything (only ever deleting the folder it created in /tmp), but I'd suggest backing up your ~/.nautilus/metafiles folder as it overwrites any files already existing for your music and artist folders (so any information for those folders like emblems or zoom memory will be overwritten).
It uses a tiny bit of perl to take advantage of Gnome VFS (because I couldn't figure out nautilus's way of escaping characters (it's not the same as normal URI escaping) so what better way than to tap into VFS directly) so make sure you have the libgnome2-vfs-perl package (Not sure if it's default or not but I'd be suprised if someone didn't already have this). You also need the imagemagick package. Because it uses VFS this means that it works on any folder nautilus can display, so basically every language you could possibly be using (which is the main reason I found myself writing this. the escaping in the howto totally ignored non-latin and even non-basic latin characters).
So, if anyone wants to rewrite this script better, just steal the two lines of perl I used and get rid of any %0A (new line characters) VFS tries to add to the end of URIs as nautilus doesn't like those. It would probably be better if I had used perlmagick instead of the crippled command line tool but perl just looks like an even more evil version of C (well now I realise bash is evil...perl, not so much).
You basically run the script, passing it the path to your music folder without the ending slash. Here's how it works:
For anyone who happens to read this but didn't follow IT ONLY WORKS IF YOU HAVE THE FOLDER STRUCTURE "Artist/albums/".0. deletes any previous "/tmp/coverart_" folder
1. makes a list of every directory in your music folder and does a find inside them for folders which contain cover art meaning albums just sitting there in the music folder won't be recognised, they have to be inside another folder which the script will assume is an artist folder (defaults to cover.jpg, can change this near the top of the script, you'll see the comments)
2. creates hidden .icon.jpg thumbnails of your cover art in your album folders
3. generates the metafile for the artist folder in nautilus and saves it in /tmp, this holds a list of all album folders in it and the name of the icon file (.icon.jpg)
4. creates a ".icon.index" file in the artist directory which holds the paths for all the icon files in its sub-directories. In step 1 the script will skip directories with the .icon.index file inside them so if you need to redo a single folder just delete this file inside the artist folder to get the script to redo the folder. To redo all of them...well just do "for f in `find /<MUSICFOLDER HERE> -name .icon.index`; do rm "$f"; done" or something.
5. reads this file back in, counts how many there are and uses imagemagick to combine them into icons for the artist folder. If there are 4 or more it creates an icon of 4 tiled. If there are 2 or 3 it splits them vertically into strips starting from the left. And if there's one...well technically it does the same thing but since there's one it divides by 1 and you get the usual single image. Stores the full imagemagick command in .cmd files in the /tmp/coverart_ folder for debugging purposes.
6. generates and adds the xml file tag (i.e. the artist folder icons) to a file in /tmp for the artist folder
7. moves the metafile responsible for album icons to your ~/.nautilus/metafiles/ directory.
8. does steps 2 - 7 for every directory in your music folder.
9. moves the metafile for the artist icons into your ~/.nautilus/metafiles/
Here it is. Save it into a file and go nuts. Don't cringe too much, and I can't see how this script could go wrong but test it on something not your music folder first. It's pretty straight forward with the basic settings near the top so go wildCode:So if your folder looks like: /home/myuser/Music Folder/Artist Names you would run: /path/to/script/icongen "/home/myuser/Music Folder" or: /path/to/script/icongen ~/Music\ Folder i.e. the usual bash escaping
THis is only tested with English, Chinese, Japanese and Korean. But the characters in those languages are pretty wild so I wouldn't worry too much.Code:The code is in the next post
Last edited by Horizon; June 22nd, 2009 at 07:00 AM.
Attached to the footprints in spring, to the Japanese song she taught me,
vaguely, I was influenced by her happiness.
New version which adds a "No Cover Art" icon for artist folders with no albums with cover art so the music folder looks more consistent.
The old one wiped your old music folder configuration when you did as I suggested and deleted the .icon.index file for it to redo a folder (it appeared to work but then you'd get a music folder with only that one icon the next time nautilus restarted).That's fixed in this version (it uses the index file placed in the music folder which is what I meant to do in the first pace but forgot ).
With this one it has to redo the metafile for the root music folder every time it is run even if you're only redoing a single folder so don't think it is hanging or something, it is converting every folder name into a valid nautilus URI. Here it is for anyone who wants to try it or just take a look, it is quite a nest:
Code:#!/bin/bash ORIGIFS=$IFS IFS=`echo -en "\n\b"` UTIME=$(date "+%s") #unix time TAB=" " LINEBREAK=" " ########GENERAL SETTINGS TMPDIR="/tmp/coverart_" #temporary folder used to store xml file and error log BLANKIMG="$TMPDIR/blank.jpg" LOGFILE="$TMPDIR/error.log" #error log file touch $LOGFILE OUTPUTDIR=~/.nautilus/metafiles/ #target directory for the resulting xml file COVERFILE="cover.jpg" #cover image filename ICONFILE=".icon.jpg" #folder icon file INDEXFILE=".icon.index" GENERAL_ICONSIZE=256 #standard dimension of all icons generated ICONSPACING=0 FILEHEADER="<?xml version=\"1.0\"?>$LINEBREAK <directory>$LINEBREAK" FILEFOOTER=" </directory>\n" LINESTART=" <file" LINEEND="/>" CODE_HANDLE="$FILEHEADER" #handle where generated album xml is stored CODE="$CODE_HANDLE" #the generated album xml CODE_HANDLE_="$FILEHEADER" #handle where generated artist xml is stored CODE_="$CODE_HANDLE_" #the generated artist xml SUCCESS=0 OUTPUT_DIV="------------------------------------------------" ###### #Make temporary directory rm -R $TMPDIR mkdir $TMPDIR convert -background black -fill white -pointsize 45 -size 256x256 -gravity Center caption:'No Cover Art' "$BLANKIMG" #Sanitise directory Path TMPVAR=$* FULLPATH="$TMPVAR/" #full path to root directory ######ROOT MUSIC FOLDER CODE INITIALISATION######### TMPVAR_1=${FULLPATH%%/} MUSICPATH="$TMPVAR_1" TMPVAR_1=$(echo "$MUSICPATH" | perl -e 'use Gnome2::VFS; $path = <STDIN>; $uri = Gnome2::VFS -> make_uri_from_input($path); $escaped_uri = Gnome2::VFS -> escape_slashes($uri); print $escaped_uri;') CLEANURI_="$TMPVAR_1" #full path to root in URI format #Create temporary files TMPXML_="$TMPDIR/$UTIME${MUSICPATH##\/*\/}.xml" touch "$TMPXML_" INDEXPATH_="$MUSICPATH/$INDEXFILE" ####################### #Loop through ARTISTLIST=$(find $FULLPATH* -maxdepth 0 -type d) for ARTISTPATH in $ARTISTLIST do if [ ! -e "$ARTISTPATH/.icon.index" ] #if index file doesn't exist then UTIME_=$(date "+%s") #unix time CODE_HANDLE="$FILEHEADER" TMPVAR_1=${ARTISTPATH%%/} CLEANPATH="$TMPVAR_1" TMPVAR_1=$(echo "$CLEANPATH" | perl -e 'use Gnome2::VFS; $path = <STDIN>; $uri = Gnome2::VFS -> make_uri_from_input($path); $escaped_uri = Gnome2::VFS -> escape_slashes($uri); print $escaped_uri;') CLEANURI="$TMPVAR_1" #full path to root in URI format #Create temporary files TMPXML="$TMPDIR/$UTIME_${CLEANPATH##\/*\/}.xml" TMPCMD="$TMPDIR/$UTIME_${CLEANPATH##\/*\/}.cmd" if [ -e "$CLEANPATH/.icon.index" ]; then rm "$CLEANPATH/$INDEXFILE"; fi #touch "$CLEANPATH/.icon.index" #Get list of image paths IMGLIST=$(find $CLEANPATH -maxdepth 2 -mindepth 2 -name "$COVERFILE") INDEXPATH="$CLEANPATH/$INDEXFILE" if [ "$IMGLIST" != "" ] then touch "$TMPXML" touch "$TMPCMD" chmod +x "$TMPCMD" #Generate XML and icon images for cover in $IMGLIST do #echo $cover TMPVAR_0=${cover%%"/$COVERFILE"} ICONPATH="${cover//$COVERFILE/$ICONFILE}" #path to new icon file #convert $IMGSETTINGS $cover $ICONPATH convert -thumbnail $GENERAL_ICONSIZEx$GENERAL_ICONSIZE ${cover// /\ } ${ICONPATH// /\ } TMPVAR_1=${TMPVAR_0##'/'*'/'} TMPVAR_2=${TMPVAR_1##'/'*} TMPVAR_3=$(echo "$TMPVAR_2" | perl -e 'use URI::Escape; $path = <STDIN>; $escaped_uri = uri_escape($path); print $escaped_uri;') TMPVAR_4=${TMPVAR_3%%%0A} SHORTURI="$TMPVAR_4" #uri to album directory from the root directory TMPVAR_5="$LINESTART name=\"$SHORTURI\" timestamp=\"$UTIME_\" custom_icon=\"$ICONFILE\"$LINEEND$LINEBREAK" if [ -e $ICONPATH ] #check if the icon was created successfully then CODE_HANDLE="$CODE_HANDLE$TMPVAR_5" else QUITMSG="$QUITMSG[$UTIME_] - ERROR:Failed to create $ICONFILE file. - [$CLEANPATH] \n" fi echo "$ICONPATH" >> "$INDEXPATH" #add icon path to icon index file done ICONPATH_="$CLEANPATH/$ICONFILE" #build artist icon path INDEXCONTENT=$(cat $INDEXPATH) #extract index file contents into variable IMGNUM=$(echo "$INDEXCONTENT" | wc -l) #count index entries #while [ "$IMGNUM" -gt 4 ]; do INDEXCONTENT=${INDEXCONTENT%"$LINEBREAK"*}; let IMGNUM--; done if [ "$IMGNUM" -lt 4 ] #if less than for tile horizontally then IMGCMD="convert -size ${GENERAL_ICONSIZE}x${GENERAL_ICONSIZE} xc:none \\ " let "ICONSIZE=$GENERAL_ICONSIZE/$IMGNUM" #figure out how to divide images ICONSIZE=$(printf %.0f $ICONSIZE) ICONPOS=-$ICONSIZE for path in $INDEXCONTENT do path=${path//\'/\\\'} if [ "$IMGNUM" -eq 1 ] #calculate icon position then ICONPOS=0 else let "ICONPOS=$ICONPOS+$ICONSIZE" #update overlay position fi #path=${path//' '/'\ '} IMGCMD="$IMGCMD-draw \"image over $ICONPOS,0 $ICONSIZE,$GENERAL_ICONSIZE '$path'\" \\ " done else #else let montage command handle it IMGCMD="montage " while [ "$IMGNUM" -gt 4 ]; do INDEXCONTENT=${INDEXCONTENT%"$LINEBREAK"*}; let IMGNUM--; done for path in $INDEXCONTENT do IMGCMD="$IMGCMD\"$path\" " done let "ICONSIZE=$GENERAL_ICONSIZE/($IMGNUM/2)" IMGCMD="$IMGCMD-geometry ${ICONSIZE}x${ICONSIZE}+${ICONSPACING}+${ICONSPACING} " fi #ICONPATH_=${ICONPATH_//\'/\\\'} IMGCMD="$IMGCMD\"$ICONPATH_\"" echo -en "$IMGCMD" >> $TMPCMD $($TMPCMD) #execute generated .cmd file IMGCMD="" CODE="$CODE_HANDLE$FILEFOOTER" #append footer xml for final code string echo -en "$CODE" >> "$TMPXML" #write the code to the temporary xml file XMLFILE="$CLEANURI.xml" #prepare the metafile filename CODE_HANDLE="" cp "$TMPXML" "$OUTPUTDIR$XMLFILE" #move temporary xml to metafile directory if [ "$QUITMSG" == "" ] then echo -en "\033[0;36mSUCCESS! Metafile created for: $ARTISTPATH\033[0m\n\bdebug:\tURI: $CLEANURI\n$OUTPUT_DIV\n" else ERRORMSG="$ERRORMSG$QUITMSG" QUITMSG="" fi else ICONPATH_="$CLEANPATH/.icon.jpg" #build artist icon path to blank image cp "$BLANKIMG" "$CLEANPATH" mv "$CLEANPATH/blank.jpg" "$ICONPATH_" fi echo "$ICONPATH_" >> "$INDEXPATH_" #add icon path to icon index file fi #end of if index file doesn't exist done #generate metafile entry for artist directory INDEXCONTENT=$(cat $INDEXPATH_) #extract index file contents into variable for path in $INDEXCONTENT do TMPVAR_0=${path%%"/$ICONFILE"} TMPVAR_1=${TMPVAR_0##'/'*'/'} TMPVAR_2=${TMPVAR_1##'/'*} TMPVAR_3=$(echo "$TMPVAR_2" | perl -e 'use URI::Escape; $path = <STDIN>; $escaped_uri = uri_escape($path); print $escaped_uri;') TMPVAR_4=${TMPVAR_3%%%0A} SHORTURI="$TMPVAR_4" #uri to artist directory from the root directory TMPVAR_5="$LINESTART name=\"$SHORTURI\" timestamp=\"$UTIME_\" custom_icon=\"$ICONFILE\"$LINEEND$LINEBREAK" if [ -e $path ] #check if the icon was created successfully then CODE_HANDLE_="$CODE_HANDLE_$TMPVAR_5" else QUITMSG="$QUITMSG[$UTIME_] - ERROR:Failed to create $ICONFILE file. - [$MUSICPATH] \n" fi done if [ "$CODEHANDLE_" != "$FILEHEADER" ] then CODE_="$CODE_HANDLE_$FILEFOOTER" #append footer xml for final code string echo -en "$CODE_" >> "$TMPXML_" #write the code to the temporary xml file XMLFILE_="$CLEANURI_.xml" #prepare the metafile filename CODE_HANDLE_="" cp "$TMPXML_" "$OUTPUTDIR$XMLFILE_" #move temporary xml to metafile directory fi if [ "$ERRORMSG" != "" ] then echo -en "$ERRORMSG" echo -en "$ERRORMSG" >> "$LOGFILE" ERRORMSG="" fi IFS=$ORIGIFS
Last edited by Horizon; November 1st, 2007 at 02:57 AM.
Attached to the footprints in spring, to the Japanese song she taught me,
vaguely, I was influenced by her happiness.
To be honest, I think this script suits me best, I want to be able to apply folder icons for my video folders etc as well regardless of folder structure.
My only issue, as someone else said was the '!'s stop it working if in the folder name, is there a workaround for this?
One other thing I found was that nautilus -q would close all my windows and would have to issue a 'nautilus' command from the terminal to fire things up again, 'killall nautilus' is more consistent in its behaviour and opens the window again after closing to refresh. I found the most convenient thing to do was ad this command via Nautilus Actions Configuration, allowing me to right click anywhere in the folder and refresh.
Thanks guys for what you've come up with so far
This is a very interesting thread. Does this code you've posted search for any .jpeg or do you have to create an image for each folder? Could this be used for pictures folders as well?
I'm looking for a feature like in windows where you can see which pics are in which folder just by looking at the icon.
Also, it would be nice, since apparently some work has been put into this script, to update the first post on the thread with the newest working code.
Thanks for everything!
Wow, it's been a long time since I've even visited this thread. Just yesterday I was thinking about my music collection and how I managed to get all them folder.jpg files working. I had completely forgotten that I was the one who started the ubuntuforums thread about it! xD
Long story short, I suck at maintaining my own threads.
Lothas does bring up a good point: a good handful of people have posted scripts for this issue, and it would be nice to include them in the original post. However, for the sake of sanity, I'd like to only include the ones that people have had the most luck with.
Would you guys mind "voting" on which ones have worked best?
My original PHP script was not meant to be a silver bullet, rather it was just a quick hackup to automate changing the XML. I'm glad people have found this thread useful.
And just in case you're curious, I've since moved on to Python myself
So that's it...a handful of votes on which scripts are most effective, and I'll update the original thread with links.
Boy I love open-source
-----------------------------
-Aashay Desai (NinjitsuStylee)
does the script run manually for new album added ???
You need to run the script when you want to update folderart, basically it's ideal if you've got a large collection that you want to update all at once, otherwise I find myself doing it manually more often than not.
Could someone give me a bit of a hand though, I'm using the script fifo posted: custom_icon.py.
Probably due to my inept use of the linux terminal (only a recent convert, I'm too used to DOS terminology), but I do struggle to get the script to work on the one folder consistently.
For example if I'm in my videos folder with all my videos in their own respective folders containing the avi and folder.jpg and I run the script as follows:it doesn't always alter all the folder images, if I use the -R switch, it'll add art to the subfolders of each folder but won't change the image of the main folders directly within the videos folder.Code:custom_icon.py ./*
However, if I run:it will change the images of the folders within videos no problem...but also changes the images of any other folders in my home directory (i.e. ~/Music/<ALL FOLDERS HERE and ~/Documents/<ALL FOLDERS HERE)Code:custom_icon.py ../*
Probably as clear as mud, but basically I want the script to work for all my folders and subdirectories in the videos folder, not all my other folders, but can't get this behaviour.
Also is there a way the script could be altered to refresh nautilus and open up the windows I'm currently viewing?
EDIT:
Ok, sorted out the problem with my terminal use it appears....still not sure on the correct switches, but I've just used Nautilus Actions Configuration to add a right-click option with
Path: custom_icon.py
Parameters: -R %d
Now all I want to do is refresh nautilus and have it open up again in the folder I've been working in
Last edited by dysphasi; December 14th, 2007 at 12:52 PM.
Bookmarks