#!/bin/bash # Copyright (c) 2005 Tim Hardy, www.timhardy.net # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ABOUT # The Creative Zen Nano mp3player lists tracks in alphabetic order within the folders on the device. The supplied windows software creates pseudo-playlists by renaming files so that each begins with a three digit number, 000, 001, 002 etc that causes them to line up in order within the directory. # USAGE # Under linux, run nanoplaylist within a directory of freshly ripped mp3s to do the same thing #create list of files by modification time #this assumes that you have not modified the mp3s since you ripped them and that your software has ripped them sequentially, first track first. The list generated will start with the its own filename as the first item followed by the tracks in reverse order, starting with the last one ls -t > listbytime #remove filename from list and create reverseplaylist sed -n '1d ; p' listbytime > reverseplaylist #define TRACKCOUNT to hold a count tracks TRACKCOUNT=`wc -l reverseplaylist | sed -n "s/\([0-9]*\).*/\1/p"` #create counter to hold current track number TRACK=0 #iterate through each track working backwards through our reverseplaylist renaming as we go for i in `seq $TRACKCOUNT -1 1`; do let TRACK=TRACK+1 #uncomment the next two lines for verbose output #echo renaming track $TRACK #sed -n "$i"p reverseplaylist #rename using two preceeding zeros if number is less than ten, one if more if [ $TRACK -lt 10 ]; then mv "`sed -n "$i"p reverseplaylist`" 00"$TRACK"_"`sed -n "$i"p reverseplaylist`" else mv "`sed -n "$i"p reverseplaylist`" 0"$TRACK"_"`sed -n "$i"p reverseplaylist`"; fi done #remove tmp files to tidy rm listbytime rm reverseplaylist