#!/bin/sh # # Description: # This script copies files in songlist to the specified directory. # Files are named using sequential number like, 0000.mp3, 0001.mp3, 0002.mp3, ... 9999.mp3 # # Files are placed into sequentially numbered directories (100 files per directory). # # directory/D00/F0012.mp3 # directory/D01/F0112.mp3 # directory/D09/F0900.mp3 # directory/D10/F1002.mp3 # # Usage: # fill_fake_ipod.sh songlist-file directory # # # 'songlist-file' is the filename of the songlist. It should have been # exported from iTunes (plain text format) # # 'directory' is where to copy the files from the songlist to. # # Files will be given simple names, like: 0001.mp3 # # # if [ $# -ne 2 ]; then echo Usage: fill_fake_ipod.sh songlist directory exit fi # # First find total number of record in songlist # cat "$1" | tr \\r \\n | wc -l | awk '{ print $1 }' > /tmp/fill_fake_ipod$$.txt COUNT=`cat /tmp/fill_fake_ipod$$.txt` rm -f /tmp/fill_fake_ipod$$.txt # # now do the copy # cat "$1" | tr \\r \\n | perl -e ' sub copy_file { local($src, $dest_dir) = @_; local($dst, $pos, $dv, $tmp); if( $count % 100 == 0 ) { $dv = ($count + 0) / 100 ; $subdir = sprintf("D%02d", $dv); system("mkdir", "$dest_dir/$subdir"); # system("echo", "mkdir", "$dest_dir/$subdir"); } $pos = rindex($src, "."); if( $pos >= 0 ) { $ext = substr($src, $pos); $fname = sprintf("F%04d%s", $count, $ext); $dst = "$dest_dir/$subdir/$fname"; system("cp", $src, $dst); # system("echo", "cp", $src, "$dst"); $tmp = $count + 1; print "Copied $tmp out of $total $src $dst\n"; $count = $count + 1; } else { print "NO EXTENSION: $src\n"; } } $destination = $ARGV[0]; $total = $ARGV[1] - 1; $count = 0; while($line = ) { chop $line; $pos1 = rindex($line, "Macintosh HD:Users"); if( $pos1 != -1 ) { $filename = substr($line, $pos1); $pos2 = index($filename, ":"); if( $pos2 != -1 ) { $filename = substr($filename, $pos2); $filename =~ tr/:/\//; if( -e $filename ) { ©_file($filename, $destination); } else { print "NOT EXIST: $filename\n"; } } } } print $count, " files copied.\n"; ' "$2" $COUNT