#!c:/perl/bin # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # Application: riopack.pl : auto-mix your mp3 files onto your rio # # Version: 0.0.1 (Feb 1999) # # Description: # This perl script will create a random mix of MP3 files and then auto-download # them to the rio via a command line rio application (not included) # # NOTE: this script was developed, tested and works great on my NT box with perl 5.004 # your mileage may vary. If you tweak the script to make it work on *nix, please # email me a copy for my own archives. Thanks! # # Author: steve mcnabb (s.mcnabb@sympatico.ca) # # Requirements: # * some _legal_ mp3 files to download to your rio (remember kids...piracy is illegal) # * 3'rd party command line application to actually talk to the rio...if you # don't have one of these, try looking at http://www.world.co.uk/sba/ # * a Diamond Rio portable music player (duh) # # Configuration: # 1) set "mp3 root" to be the root directory of wherever you keep your mp3s # 2) set "riobridge" to point to your command line app for copying to the rio # 3) you may need to tweak the "init_rio" and "dump_riofiles" to reflect your situation # and/or the way your command line app works.. # # Please DO NOT send the author requests to fix busted scripts - if it doesn't work for you, # edit it. If it still doesn't work, edit it again. :) # # Future Plans: well, if someone figures out how to address the external flash memory cards # with a command line app, I'll add support for it to this script, and re-release it. # # Props: the Snowblind Alliance for cracking the rio protocol - cool hack guys. # use DirHandle; $MP3ROOT = 'e:/mp3/'; #where are your mp3s? $THRESHOLD = '29'; #if rio isn't full but below threshold, but the next file is too big, keep looking $RIOBRIDGE = 'rio'; #the command line app that copies stuff to your rio dodir($MP3ROOT); @KEYS = keys %FILES; for( keys %FILES) { $SIZES{$FILES{$_}} = $_ } for($i = 1; $i<=$#KEYS; ++$i) {pick_song();} #######SUBROUTINES sub dodir() #recursively dig for files { my $dir = shift; my $dirhandle = new DirHandle($dir); if($dirhandle) { while($file = $dirhandle->read) { next if ($file =~ /^\.{1,2}$/); my $fullpath = $dir . "/" . $file; if (-d $fullpath) { dodir($fullpath)} else { my @STAT = stat $fullpath; my $filesize = $STAT[7]; my $kbfilesize = sprintf("%.2f",$filesize / 1024); my $mbfilesize = sprintf("%.2f",$kbfilesize /1024); $FILES{$fullpath} = $mbfilesize; } } } } sub pick_song #randomly select a track to add to the rio { $SONG = sprintf("%0d",rand($#KEYS-1)); if(!$SEEN{$SONG}) { $SEEN{$SONG} =1; if($TOTALSIZE + $FILES{$KEYS[$SONG]} >= 32) { if($TOTALSIZE <= $THRESHOLD) { $REMAINING = 32 - $TOTALSIZE; @SMALLFILES = grep { $_ <= $REMAINING } keys %SIZES; $SMALLFILE = rand($#SMALLFILES-1); $SMFILESIZE = $SMALLFILES[$SMALLFILE]; $SMFILENAME = $SIZES{$SMFILESIZE}; push @DUMP, $KEYS[$SONG-1]; } dump_riofiles() } else { $TOTALSIZE += $FILES{$KEYS[$SONG]}; push @DUMP, $KEYS[$SONG-1] } } else { pick_song() } } sub dump_riofiles { print "dumping $TOTALSIZE Mb to rio...\n"; init_rio(); for(@DUMP) { print "copying $_\n"; `$RIOBRIDGE -u "$_"` } print "\a\a done.\n"; `net stop giveio`; #turn off give io device `net start parport`; #turn the parallel port device back on exit; } sub init_rio #make sure the giveio service is running so we can copy { `net stop parport`; #stop paralell port device `net start giveio`; #start give io device (needed by my NT command line rio app) #initialize rio mem `$RIOBRIDGE -i`; }