The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   Applications (http://hintsforums.macworld.com/forumdisplay.php?f=5)
-   -   Creating CDs/DVDs for vehicles - must be a better way (http://hintsforums.macworld.com/showthread.php?t=104288)

onceagain 08-11-2009 08:46 PM

Creating CDs/DVDs for vehicles - must be a better way
 
I've spent a lot of time on this - including time experimenting, and time spend reading forums and looking for info. Nowhere, anywhere, can I seem to find help for what I am looking to do - which really doesn't strike me as anything special. In my view, its among the most basic of things that someone working with music on a Mac might want to do.....so I'm really surprised it seems to be so damned hard.

Bottom line:
I want to make DVDs of music for my Jeep's 6-disc MP3 disc changer. It plays CDs and DVDs. I've successfully made both, using a variety of methods. However, because the MORONS at Daimler Chrysler, in their infinite lack of wisdom, did not put a RANDOM PLAY button on their stupid 6-disc changer (the single disc player has one), the results are less than satisfactory. I get tired of listening to the songs in the same order all the time.

Summary of what I want to do:
I want an EASY (i.e. fairly hassle free) way to make MP3 DVDs that lets me put selected songs on the disc in a random order, structured arbitrarily into folders, to keep under the 255 file files/folder limit imposed by the 6-disc changer in the Jeep.

Summary of things I do NOT want to do:
Use an iPod connected to the 6-disc changer. Sort songs by folder based on Artist, Album, Genre, leader guitarist's favourite color, choice of drug, or anything else.

The closest I have come:
Create a playlist in iTunes of anything I am interested in having on the disc - in this case, a bunch of hard rock stuff. Then, create a smart playlist, using that playlist as a source, to randomly choose 1000 (for example) songs (this puts me just under the 8.5GB limit of a DL DVD). Use itunes to burn a DVD (doesn't seem to be any way to save as disc image) using that playlist. Then, read that DVD back, manually placing the songs into folders on an arbitrary basis. For example, create 4 folders, put 250 songs in each folder (songs 1-250, 251-500, 501-750, 751-1000). Then burn that folder structure BACK to a DVD using Toast. This gets me a single DVD with songs of interest in a random order (of course, they're locked into that random order). It's a pain in the ass, and costs me 2 DL DVDs for every useful one I make.

Second closest I have come:
Using Toast, make an MP3 disc - use the media browser to read the iTunes Library, accessing the playlist of 1000 randomly chosen songs. Unfortunately, for some really stupid reason, Toast ALPHABETIZES the songs, rather than leaving them in the order indicated by the playlist (the iTunes method prepends the song title with the number, 1 to 1000, to keep them in the proper order). I really don't want to be so much of a dork as to listen to songs in alphabetical order - that's not much of an improvement over listening to them by artist or album. Anyway - the next step is to make 4 folders on the disk, sort the songs in the folders, and then burn it. If it were not for the whole alphabetizing thing, this method would be an improvement over the above method, in that it only uses one disc in the process, but it's still a huge pain in the ass that requires manual intervention on my part. Given how many discs I want to create (it is a 6 disc changer after all), it's not real practical to make 20 - 30 discs this way.

Where I am at now:
Based off what I've seen so far, if I want to get what I want, I will have to write a PERL program to parse the itunes library XML file, access the playlist I made, and use that to create the folder file structure of songs (for example 10 folders, 100 songs into each folder) and copy each song into the folder structure. Then I can burn that folder structure with toast. The disadvantage here of course is my time to create and debug this program, and having to make a copy of all the stuff to go on the disc.

So, there it is. I'm hoping someone can save me from myself (: I've had this 6-disc changer for over 2 years now and have yet to get any use out of it because of this huge headache. Just the process of converting all my AAC stuff (500GB or so) to MP3 was a big pain (the player doesn't play AAC) - now I'm running into this issue. I'm hoping to get some use out of my 6 disc changer - one day. Please help (:

acme.mail.order 08-12-2009 12:58 AM

Quote:

Originally Posted by onceagain (Post 546581)
Summary of things I do NOT want to do:
Use an iPod connected to the 6-disc changer.

Any particular reason? Seems this would solve all your issues in one go, in addition to being portable and passenger-friendly.

onceagain 08-12-2009 01:10 AM

Quote:

Originally Posted by acme.mail.order (Post 546603)
Any particular reason? Seems this would solve all your issues in one go, in addition to being portable and passenger-friendly.

A bunch of reasons actually - but off topic, so no need to go into them here (:

onceagain 08-12-2009 04:42 AM

Quote:

Originally Posted by onceagain (Post 546581)
Where I am at now:
Based off what I've seen so far, if I want to get what I want, I will have to write a PERL program to parse the itunes library XML file...

Actually, I'd rather use Java. What I would end up doing, if i have to go down this route, is get the info from the iTunes XML file into a PostgreSQL database, and then once it was in there, I could write code against that to build a file structure with copies of tracks, which could then be burned with Toast. So, if there is no better way (i.e. existing software to do what I want), if anyone knows of an existing mechanism for getting the XML into a PostgreSQL database, so I don't have to do that from scratch, please feel free to clue me in. Thanks (:

blubbernaut 08-12-2009 05:49 AM

I know how you feel - although in regards to mp3 CDs not DVDs.

My workaround: Sort by song length in iTunes, then burn.

Unfortunately Toast seems to have no way of sorting properly - and my car stereo will only play mp3s not AAC or mp4 - a lot of my library is AAC, so I have to copy them out of iTunes, convert them to mp3, then burn in Toast, and subsequently get the alphabetical problem.

hayne 08-12-2009 06:07 AM

There are lots of existing scripts for manipulating iTunes data - so have a look around. E.g. google for:
iTunes scripts
or
iTunes AppleScripts

onceagain 08-12-2009 01:39 PM

Quote:

Originally Posted by hayne (Post 546625)
There are lots of existing scripts for manipulating iTunes data - so have a look around. E.g. google for:
iTunes scripts
or
iTunes AppleScripts

Well, like I said in the OP - already done lots of googling and I have not found anything that meets my needs. If you have a specific site/page/solution in mind, please feel free to bring it forward.


Quote:

Originally Posted by blubbernaut (Post 546623)
I know how you feel - although in regards to mp3 CDs not DVDs.

Process is the same, just the media is different. (:

Quote:

Unfortunately Toast seems to have no way of sorting properly - and my car stereo will only play mp3s not AAC or mp4 - a lot of my library is AAC, so I have to copy them out of iTunes, convert them to mp3
Yeah, I had the same issue - and my phone doesn't play AAC either. So, I converted my library enmasse from whatever into MP3, within iTunes, and then deleted all the AAC files. Seemed like a much better solution than converting on an "as needed" basis all the time.

Quote:

, then burn in Toast, and subsequently get the alphabetical problem.
I'm not a very smart guy - but it's amazing that the smart guys at Roxio have not figured this stuff out - and that the smart guys at Apple haven't figured out that people want to make disc images rather than burn real discs, etc. In the meantime, we get loaded up with crap and useless features of all kinds that I have a hard time that people really want or use. Of course, the kings of dumbness are the people who designed the 6-disc changer in my Jeep - with no random play button. Capable of 6000+ songs, and no random play?? Idiots. Just idiots.

EatsWithFingers 08-12-2009 07:01 PM

Quote:

Originally Posted by onceagain (Post 546581)
The closest I have come:
Create a playlist in iTunes of anything I am interested in having on the disc - in this case, a bunch of hard rock stuff. Then, create a smart playlist, using that playlist as a source, to randomly choose 1000 (for example) songs (this puts me just under the 8.5GB limit of a DL DVD). Use itunes to burn a DVD (doesn't seem to be any way to save as disc image) using that playlist. Then, read that DVD back, manually placing the songs into folders on an arbitrary basis. For example, create 4 folders, put 250 songs in each folder (songs 1-250, 251-500, 501-750, 751-1000). Then burn that folder structure BACK to a DVD using Toast. This gets me a single DVD with songs of interest in a random order (of course, they're locked into that random order). It's a pain in the ass, and costs me 2 DL DVDs for every useful one I make.

You can skip creating the first DVD: create a folder to store all the tracks you want, then select all the tracks in your playlist and drag them into the folder. That will copy all the tracks into the folder. Simples :p.

Or, you could make multiple 250-track playlists, and drag the contents of each into separate sub-folders. Might be easier than splitting the 1000 tracks manually in Finder.


On a side note, does Toast support playlist files? That is, can you use one to prevent the alphabetical ordering problem? Though I'm not sure how easy it is to create a m3u file from an iTunes playlist....

onceagain 08-12-2009 09:24 PM

Quote:

Originally Posted by EatsWithFingers (Post 546723)
You can skip creating the first DVD: create a folder to store all the tracks you want, then select all the tracks in your playlist and drag them into the folder. That will copy all the tracks into the folder. Simples

Hey, I didn't know you could do that. That's a good tip - thanks (:

However....the downside is that if you do it that way, you end up with a folder of tracks, in alphabetical order. You lose the playlist ordering (prefixing track file names with 000-XXX) like you get if you burn the disc. Soo, good to know iTunes has that "drag out the tracks" functionality, but it's not functional for the purpose I am gunning for here.

Quote:

On a side note, does Toast support playlist files? That is, can you use one to prevent the alphabetical ordering problem? Though I'm not sure how easy it is to create a m3u file from an iTunes playlist....
Well, it supports playlists - the Toast Media Browser will access a playlist (which results in the problem I describe a few posts ago) - I'm not sure if you mean something different when you say "playlist file". If so, please do explain (:

Thanks!

anika123 08-13-2009 10:35 AM

Here is what I would do.

Collect a folder of tunes that will fit on a DVD using the itunes drag method From an itunes playlist.
Run this command in terminal from the folder directory.

Quote:

find . -type f | sed -e 's#^.#//music#g' > allfiles.m3u
This will create a playlist called allfiles.msu that you can burn with Toast.

Admittedly, This is not really random as it will group all tracks of the same number together. Someone else can probably use sed or awk to sort these more random. Also, oddly if you drag tracks from an itunes playlist it adds the track numbers where as if you just drag them from the library you only get the tracks names.

This brings me to another point. What is wrong with a play list that is sorted alphabetically? You still get random song order that way.

Update: Whoops, the above command is for playlist on my Sansa and assumes music is in /music. To get this to work with toast change '//music' to the path to your music/burn folder where you copied your tunes to.

EatsWithFingers 08-13-2009 11:38 AM

What you need is a script that will randomly obfuscate file names - in much the same way as what happens when tracks are transferred to an iPod/iPhone. For example, files have four-character alphanumeric names (e.g. x5aw.mp3). Then, the tracks would be in alphabetical order based on their new names, but random based on their original names.

I'll see what I can come up with in shellscript, although other people may well post something first!

EDIT: Here we go:

Code:

SOURCE="originals";
DEST="obfuscated";
for i in "$SOURCE/*" ; do
  j="${i##*/}" ;
  k=`openssl rand 32 | openssl md5`;
  mv "$i" "$DEST/${k:24:8}.${j#*.}" ;
done

(where "originals" is the name of the folder with your tracks copied from iTunes, and "obfuscated" is an empty folder where the obfuscated files will go).

This renames every file in the source folder to a random string of hexadecimal characters and moves the file to the destination folder. It preserves file extensions so can be used with folders containing multiple file types (e.g. mp3 and m4a). [b]Note:[/n] it does not check for duplicate file names in the destination folder (it can be done, but would take longer to code).

For example, "originals/01 Penny Lane.mp3" becomes "obfuscated/a6f19aab.mp3"

onceagain 08-13-2009 12:11 PM

Quote:

Originally Posted by EatsWithFingers (Post 546811)
What you need is a script that will randomly obfuscate file names - in much the same way as what happens when tracks are transferred to an iPod/iPhone. For example, files have four-character alphanumeric names (e.g. x5aw.mp3). Then, the tracks would be in alphabetical order based on their new names, but random based on their original names.

Well, the huge disadvantage to that is when the player in the Jeep displays the file name, it will be meaningless, instead of telling me what the song really is (:

EatsWithFingers 08-13-2009 12:14 PM

Just seen your latest post, after editing my previous one. The Jeep not reading the ID3 tags is not good. The search for a solution continues....


(...new car? :D )

onceagain 08-13-2009 12:18 PM

Quote:

Originally Posted by anika123 (Post 546799)
Here is what I would do.

Collect a folder of tunes that will fit on a DVD using the itunes drag method From an itunes playlist.
Run this command in terminal from the folder directory.....

Admittedly, This is not really random as it will group all tracks of the same number together. Someone else can probably use sed or awk to sort these more random. Also, oddly if you drag tracks from an itunes playlist it adds the track numbers where as if you just drag them from the library you only get the tracks names.

Well, that does give me an idea. What I COULD do is use the "drag method" indicated a few posts ago to create the folder of goodies. Then, run a small program (that I would have to write) that opens up the folder of goodies, reads in the file names into a data structure, and then assigns a (non duplicating) random number 1..max elements to the file names, and prepends that to the file name. That would give me file names that run 0000whatever to 1000whatever - and then move those files into the data structure I want (250x4 folders, 100x10 folders, or whatever). Toast will burn in this numerical order - which is really a random order. I think I like this idea (:

Quote:

This brings me to another point. What is wrong with a play list that is sorted alphabetically?
Nothing, if you want to listen to them that way. FWIW, I didn't leave my CDs sorted in alphabetical order when I had a CD rack in my house - and my last name starts with a W - so I've never been a big fan of alphabetical order (:

Quote:

You still get random song order that way.
Only from a certain point of view. The may SEEM random - and they're certainly more random than sorting by artist, but it still allows you to guess what might come up next, as opposed to really having no idea - which is what I am looking for. For example, it does lead to groupings:

Ain't Even Done With the Night John Mellencamp
Ain't It A Shame - Demo, 1989 Nirvana
Ain't It Fun Guns N' Roses
Ain't No Fun (Waiting Round to Be a Millionaire) AC/DC
Ain't Talkin' 'Bout Love Van Halen

So for 5 songs in a row, I'd be listening to what something AIN'T about - in a manner of speaking.

Your comment got me on the right mode of thinking though. I think I might have a solution to work up. Thanks (:

onceagain 08-13-2009 12:20 PM

Quote:

Originally Posted by EatsWithFingers (Post 546818)
Just seen your latest post, after editing my previous one. The Jeep not reading the ID3 tags is not good. The search for a solution continues....

It reads....but sometimes I like to see the file name too. For example - yesterday, I was listening to a song that was supposed to be the Rolling Stones - but it sure didn't sound like it. I looked at the file name and made a mental note to check it when I get home to see what's what.

EatsWithFingers 08-13-2009 01:38 PM

Code:

SOURCE=originals;
DEST=obfuscated;
for i in "$SOURCE"/* ; do
  RNDIDX=${RANDOM:0:2} ;
  if test -e "$DEST/$RNDIDX.tmp" ; then
    echo "BOO ($RNDIDX)" ;
  else
    j="${i##*/}" ;
    f=${j#* } ;
    mv "$i" "$DEST/$RNDIDX $f" ;
    touch "$DEST/$RNDIDX.tmp" ;
    echo "$RNDIDX $f" ;
  fi ;
done

This removes the number at the start of each filename then adds a random number in the range 0-99, adds that number to the start of the filename, then moves the track into the destination directory. The move is only done if that random number hasn't been used yet. You can keep running the script until all tracks have been moved (max 100*). Just remember to delete the temporary files before burning the DVD.

* if you want 1000 tracks in the destination folder then change RNDIDX=${RANDOM:0:2} to RNDIDX=${RANDOM:0:3}

So:

$SOURCE/01 Penny Lane.mp3
$SOURCE/01 Revolution.mp3
$SOURCE/02 Fool on the Hill.mp3

could become:

$DEST/43 Penny Lane.mp3
$DEST/54 Fool on the Hill.mp3
$DEST/98 Revolution.mp3


EDIT: here's how it works:

For each file in the source directory, a random number in the range 0-99 is generated. If a temporary file corresponding to that random number is in the destination folder, we skip that file and move on to the next one. If no temporary file exists then this is a new random number and we move the file over, swapping everything up to the first space character (i.e. the track number in whatever album it is from) with the random number. If you don't want the existing track number to be removed then change f=${j#* } to f=$j . Then we create a temporary file indicating that the number has been used and carry on.

onceagain 08-13-2009 02:53 PM

Hey, thanks for putting that together! I wasn't expecting someone to do it for me (:

I ran your script. A couple of issues:

a). It doesn't delete the temp files (easily fixed) (:

b). It doesn't necessarily insert the correct number of songs into a directory. For example on my run it did 86 songs.

c). I think your pattern matching is going to fail on some songs, which have file names like "02-4 Song Name" - renaming them to "-4 Song Name" after the random number (also easily fixed).

I also need to "scale it up" to create multiple directories, insert songs in each, being sure to not repeat songs across the directories. But I can work on that, you guys have given me some great ideas. Thanks (:

EatsWithFingers 08-13-2009 04:01 PM

Quote:

Originally Posted by onceagain (Post 546853)
Hey, thanks for putting that together! I wasn't expecting someone to do it for me (:

No problem - I like writing little scripts like that!

Quote:

Originally Posted by onceagain (Post 546853)
I ran your script. A couple of issues:

a). It doesn't delete the temp files (easily fixed) (:

b). It doesn't necessarily insert the correct number of songs into a directory. For example on my run it did 86 songs.

c). I think your pattern matching is going to fail on some songs, which have file names like "02-4 Song Name" - renaming them to "-4 Song Name" after the random number (also easily fixed).

(a) and (b) are related. If the same random number is generated twice, then the current track will be skipped. In your case, that happened 14 times. By not deleting the temporary files, you can run the script again and it will try to generate a random number that is not in use for any remaining tracks. Deleting the temporary files between runs may cause the same random digits to be used more than once. A loop in the style of the one given below could be used to keep generating random numbers until a free one arises...

As for (c), it should work since "02-4 " will match with '* '. i.e. everything up to the first space will be replaced by the random number. However, it won't work on tracks with names like "01-Song Name". They'd get renamed to "XX Name" (where XX is the random number), since "01-Song " will match with '* '. But that's only a problem if iTunes isn't set to keep your library organised.

Quote:

Originally Posted by onceagain (Post 546853)
I also need to "scale it up" to create multiple directories, insert songs in each, being sure to not repeat songs across the directories. But I can work on that, you guys have given me some great ideas. Thanks (:

Glad to be of help. You could also add a check to limit the random number to something other than 100 or 1000 if you wanted. For example:
Code:

$MAXIDX=75 ;
RNDIDX=${RANDOM:0:2} ;
until (($RNDIDX < $MAXIDX)) ; do RNDIDX=${RANDOM:0:2} ; done ;

Oh, and do post the "scaled up" code when you're done. :)

onceagain 08-13-2009 10:21 PM

Quote:

Originally Posted by EatsWithFingers (Post 546863)
Oh, and do post the "scaled up" code when you're done. :)

I believe I have something that more or less does what I need - within the limitations we have been discussing. Using this program (which has not been "bulletproofed" by any means), the following process is now possible:

a). In iTunes, create a playlist of whatever you want to deal with.

b). Bring up that playlist, select all the tracks, and drag them to an empty directory, to create a copy of all the tracts of interest. I will refer to this as the "source" directory.

c). Run my program (note: as written, it must be in the same directory as the source directory).

d). Execute the output script it generates (movetracks.sh).

e). Fire up Toast, configure to create an MP3 audio disk. Drag the directories created by movetracks.sh onto Toast, and then burn.

Critical values (from plist):
-name of output file (scriptFile)
-file limit, number of songs per directory (fileLimit)
-source directory name (sourceDir)
-file extension to filter for (fileExtension)
-output directory prefix (dirPrefix)

PROGRAM SYNOPSIS:
-uses an init sub to read a plist in user's home directory to get critical values.
-read track names from source directory and put them in random order
-create/open an output file
-loop through the list of tracks
-create and write a UNIX make directory command to the output file (as needed)
-clean up the track name of the output (as needed)
-prepend a sequential number to each track name (ensure ordering)
-create and write a UNIX 'move file' command to the output file
-close the file and make it executable

You can look over the output file and see if it all looks good to you, before running it. When the output file is run, it will move files from the source directory into new directory structure, which contains X number of directories (based on the fileLimit value).

So, if you run it with a source directory containing 1000 songs, with a fileLimit=100, it will create 10 directories, with 100 songs each - for example.

Anyway - it seems to work. Seems reasonable for its purpose, but it's not bulletproofed or hardened or anything else - so it's quick and dirty. Be careful out there - and be sure to run it only on a copy of stuff from iTunes, not your master iTunes directory. This version is excessively complicated because it reads the critical values from a plist in the user's home preferences directory, but you could whack all
that and just hard code values in as perl variables if you want (like the defaults are
coded).

KNOWN ISSUES:
If an input file has backticks (`) in its name, problems ensue. So, any such files are SKIPPED and will not appear in the output script. Truthfully, such files should have their name changed in iTunes. On that note, as far as I can tell, the morons at Apple do not allow you to search (within iTunes) by file name, display file name in the "view" list, or do anything else with file name (or path name). WHY THE HELL NOT??? You can use useless crap, like beats per minute, but something USEFUL, like file name? Hell no. Idiots. Ok, Rant over (: I found the offending files from the command line, by doing the following from the directory above "iTunes Music" :

Code:

find . -name "*\`*.*" -print
Which returned:

./Du' Casco/CIRCUITO REGGAE 7/01 Du`Casco - Quem vai querer.mp3
./Sammy Hagar/Marching to Mars/09 The Yogi`s so High (Im Stoned).mp3

So, I can change those file names and not have to worry about backticks anymore (:

Code:

#!/usr/bin/perl
#**************************************************************************
# A program that generates a shell script to create a directory structure
# and populate it with music tracks in a randomized order. The resulting
# structure can easily be burned with Toast or other software to create a
# DVD/CD of randomized music that can be played in whatever. Files from
# the specified source directory are MOVED.
#**************************************************************************
# WARNING: This is a quick and dirty program, not bulletproofed. YMMV.
# WARNING: Do not use on master file library.
#**************************************************************************
# REQUIRES: A basic dictionary plist. See sub initProgram() for details.
#**************************************************************************
use Foundation ;      #access Cocoa framework via PerlObjCBridge
use File::Basename;
use List::Util 'shuffle';

#program initialization
my ($defaults) = " Using defaults.\n\n" ;
my ($initCode) = initProgram(); #read plist and define vars
if ($initCode==1) { print("\nERROR: plist not found!".$defaults); }
if ($initCode==2) { print("\nERROR: plist malformed!".$defaults); }

#variable initialization
my ($outputDir) = ""  ; #current directory to output to
my ($fileCounter) = 0 ; #number of files processed - counter
my ($dirCounter)  = 0 ; #number of directories processed - counter

#Read track names into array and randomize the list
my (@tracks) = shuffle(<$sourceDir/*$fileExtension>);

if (scalar(@tracks)==0) {
  my($msg) = "\nERROR: source directory missing or empty. Tried: " .
              "\nSource Directory:".$sourceDir.
              "\nFile Extension: ".$fileExtension . "\n\n" ; 
  die($msg);
}#source directory problem

#open the file handle for the output script
open (SCRIPT, ">$scriptFile")||die("ERROR: Unable to open $scriptFile\n\n");
print (SCRIPT "#!/bin/sh\n");

#Loop through the track list, generating commands for creating directories
#or moving files as necessary, cleaning up the track names in the process
foreach $inputFile (@tracks) {
  #if a directory is needed, figure out a name and write a create cmd to the script file
  if (($fileCounter++ % $fileLimit) == 0) {
    $dirCounter++ ;
    if ($dirCounter < 10) { $outputDir = $dirPrefix."00".$dirCounter; }
    if (($dirCounter>9)&&($dirCounter < 100)) { $outputDir = $dirPrefix."0".$dirCounter; }
    if ($dirCounter>99) { $outputDir = $dirPrefix.$dirCounter ; }
    print(SCRIPT "rm -rf $outputDir ; mkdir $outputDir\n");
  }#if a directory is needed

  #Clean Up Track Names and setup output file name
  my ($base,$path,$type) = fileparse($inputFile);
  my ($trackNum)        = $fileCounter ;
  $base =~ s/^[0-9]* // ;          #strip leading track numbers
  $base =~ s/^[0-9]*\-[0-9]* // ;  #strip leading dashed track numbers

  if ($inputFile =~ m/\`/) {
    print("\nSKIPPED (backticks): $inputFile\n\n");
  } else {
    $outputFile = $outputDir."/".$trackNum." ".$base ;
    print(SCRIPT "mv \"$inputFile\" \"$outputFile\"\n");
  }#if backticks
}#foreach track

#close up the script file and make it executable
close(SCRIPT); chmod(0755,$scriptFile);

#could easily just run the script from here, then delete it
print("A script file has been generated to create the directory structure.\n");
print("Execute the file '".$scriptFile."' to move the files as necessary.\n\n");
exit(0);


#**************************************************************************
# PROGRAM INITIALIZATION
#**************************************************************************
# Read default values from a plist in the user's home directory. This file
# is assumed to have already been created, using the keys shown here. Right
# now, this file must be manually created with the plist editor. The key
# fileLimit is a number, while the others are all Strings.
#**************************************************************************
sub initProgram() {
my($path)  = "/Users/".getlogin()."/Library/Preferences/" ;
my($file)  = "trackmover.plist";
my($plist) = NSDictionary->dictionaryWithContentsOfFile_($path.$file);
my($returnCode)=0;

if (!$plist||!$$plist) {$returnCode=1;}#File Not Found
else {
  $scriptFile_o    = $plist->objectForKey_("scriptFile");
  $dirPrefix_o    = $plist->objectForKey_("dirPrefix");
  $fileExtension_o = $plist->objectForKey_("fileExtension");
  $sourceDir_o    = $plist->objectForKey_("sourceDir");
  $fileLimit_o    = $plist->objectForKey_("fileLimit");
 
  if ( (!$scriptFile_o||!$$scriptFile_o) ||
      (!$dirPrefix_o||!$$dirPrefix_o) ||
      (!$fileExtension_o||!$$fileExtension_o) ||
      (!$sourceDir_o||!$$sourceDir_o) ||
      (!$fileLimit_o||!$$fileLimit_o)) {
      $returnCode=2; #plist file is malformed
  }#one or more keys not found in the plist
}#convert plist into usable objects

#these are the global variables used in the main program
#at this point, they should all get set and be functional,
#if no errors have occured
if ($returnCode==0) {
  $scriptFile    = $scriptFile_o->UTF8String() ;
  $dirPrefix    = $dirPrefix_o->UTF8String() ;
  $fileExtension = $fileExtension_o->UTF8String() ;
  $sourceDir    = $sourceDir_o->UTF8String() ;
  $fileLimit    = $fileLimit_o->intValue() ;
} else { #use default values
  $scriptFile    = "default_movetracks.sh" ;
  $dirPrefix    = "default_" ;
  $fileExtension = ".mp3" ;
  $sourceDir    = "default_songs" ;
  $fileLimit    = "50" ;
}#use default values if there is a plist problem

return($returnCode);
}#END initProgram() ;


anika123 08-14-2009 08:16 AM

Can I get a quick pointer on how to create a plist file please. I would like to try this script.

onceagain 08-14-2009 01:12 PM

Quote:

Originally Posted by anika123 (Post 546947)
Can I get a quick pointer on how to create a plist file please. I would like to try this script.

Sure.

1). Open "/Developer/Applications/Utilities/Property List Editor"

2). In the window that comes up, click on the "Root" element and then hit the "Add Child" button 5 times, to add 5 items.

3). Now, go through and rename all of the items from "New item..." to one of the item names needed. These are: scriptFile, sourceDir, fileLimit, fileExtension, and dirPrefix.

4). Next, change the Type for fileLimit to Number (the rest stay as String).

5). Now, assign the values you want to use. In my case, I am using the following:

scriptFile - movetracks.sh
sourceDir - songs
fileLimit - 100
fileExtension - .mp3
dirPrefix - music_

6). Finally, save the file in ~/Library/Preferences/trackmover.plist

That's it.

If you do not happen to have the Developer tools installed, you will need to manually create a file, using any text editor, that looks something like this:

Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>fileLimit</key>
        <integer>100</integer>
        <key>scriptFile</key>
        <string>movetracks.sh</string>
        <key>dirPrefix</key>
        <string>music_</string>
        <key>fileExtension</key>
        <string>.mp3</string>
        <key>sourceDir</key>
        <string>songs</string>
</dict>
</plist>

A plist that has the values I am using requires your source directory (the one with all the tracks) to be named "songs" and will generate a directory structure that looks like "music_001 music_002 music_003....music_010" (assuming 1000 songs as input).

Also, regrarding point "d" in my previous post. You do NOT need to have the program in the same directory as the source directory, you only need to be in that directory when you run the program from the command line. Alternatively, you could specify a full path in the plist file, then you could be anywhere. If you specify a full path for the output directory prefix, then it would be even more flexible.

FWIW, I installed this program in /usr/bin/local/trackmover.pl and made a link (ln -s) to /usr/bin/local/trackmover - so now I can run execute it by running "trackmover" from the command prompt, from anywhere.

tw 08-14-2009 07:10 PM

sorry for coming to this discussion late, but that seems like an UGLY mess of code. why not simply do this: set up your playlist in iTunes (using the shuffle option as needed to get a randomized selection), write an applescript that runs through the shuffled playlist and does the following:
  • creates a burn folder on the desktop
  • creates a folder for each 100 tracks in the burn folder
  • creates 100 folders in each 100-track folder (with sequential names for the folders, so they'll stay in order)
  • writes an alias for each track into each folder
no need to mess with changing file names or anything like that, no need for extra disks or lots of file copying... give me a few minutes and I'll work up a draft.

onceagain 08-14-2009 07:34 PM

Quote:

Originally Posted by tw (Post 547052)
sorry for coming to this discussion late, but that seems like an UGLY mess of code.

Thanks.

Quote:

why not simply do this: set up your playlist in iTunes (using the shuffle option as needed to get a randomized selection), write an applescript that runs through the shuffled playlist and does the following....
Because I don't know applescript.....and I avoid vendor-specific solutions whenever possible anyway.

Quote:

[list][*]creates a burn folder on the desktop[*]creates a folder for each 100 tracks in the burn folder[*]creates 100 folders in each 100-track folder (with sequential names for the folders, so they'll stay in order)[*]writes an alias for each track into each folder
Sounds like you're talking about burning a disc with sub-sub directories - which the player in my Jeep doesn't recognize (I know, because I've tried).

tw 08-14-2009 07:53 PM

Quote:

Originally Posted by onceagain (Post 547056)
Because I don't know applescript.....and I avoid vendor-specific solutions whenever possible anyway.

suit yourself. :)

anika123 08-14-2009 08:04 PM

umm, I would like to see the "draft". :)

tw 08-14-2009 08:45 PM

Quote:

Originally Posted by anika123 (Post 547059)
umm, I would like to see the "draft". :)

eh, I was going to post it anyway. :-) this version doesn't use the sub-sub folders (since those seem to be objectionable), and it doesn't change the file name (just appends an index on the front of the alias file - might cause some problems if the file name is too long, since that might erase the file extensions on the DVD - but one thing at a time)
Code:

property burnFolderPath : (path to desktop as text) & "Burn Me"

tell application "iTunes"
        set {theNames, theFilePaths} to {name, location} of (every file track of playlist "new")
end tell
tell application "Finder"
        try
                set burnFolder to make new folder at desktop with properties {name:"Burn Me.fpbf"}
                set extension hidden of burnFolder to true
        on error
                set burnFolder to folder ((desktop as text) & "Burn Me")
                delete (every item of burnFolder)
        end try
        set idxFile to 0
        set idxFolder to 1
        repeat with i from 1 to count theFilePaths
                if (i - 1) mod 100 is equal to 0 then
                        set folderName to ("F_" & characters -3 thru -1 of ("000" & idxFolder)) as text
                        set theFolder to make new folder at burnFolder with properties {name:folderName}
                        set idxFolder to idxFolder + 1
                end if
                set filePath to item i of theFilePaths
                set ext to name extension of file (filePath as text)
                set cleanedName to my cleanName(item i of theNames)
                set fileName to ("f" & (characters -3 thru -1 of ("000" & i)) & "_" & cleanedName) as text
                set newAlias to make new alias file at theFolder to filePath
                set name of newAlias to fileName
        end repeat
end tell

to cleanName(txt)
        repeat with delim in {":", "/", "\\"}
                set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, delim}
                set temp to text items of txt
                set AppleScript's text item delimiters to "_"
                set txt to temp as text
                set AppleScript's text item delimiters to tid
        end repeat
        return txt
end cleanName


onceagain 08-14-2009 09:11 PM

Looks nice - you've got the idea anyway.

Unfortunately, if you burn that folder "burn me" with Toast, all you get are the aliases, rather than the real files that will play in the Jeep (Toast warn about the .mp3 extensions, by the way).

tw 08-14-2009 09:29 PM

errr... the reason it's called a 'burn folder' is that you can just click the burn button in the folder itself, and the system will do it for you. no toast needed (unless you're hungry). admittedly, I've never tried to use a burn folder to burn a DVD, but there's kinks in every plan.

onceagain 08-14-2009 10:29 PM

Quote:

Originally Posted by tw (Post 547075)
errr... the reason it's called a 'burn folder' is that you can just click the burn button in the folder itself, and the system will do it for you. no toast needed (unless you're hungry). admittedly, I've never tried to use a burn folder to burn a DVD, but there's kinks in every plan.

I see. I've never used anything other than Toast for burning discs (other than the one time I used iTunes, as described in post #1). In any case, after running your script, I don't see anything that could be described as a "burn button" - just 12 subdirectories of various names.

tw 08-14-2009 10:41 PM

ah, yeah... I got tricky and it snarked on me. use these lines instead, at the obvious places:
Code:

property burnFolderPath : (path to desktop as text) & "Burn Me.fpbf"

set burnFolder to make new folder at desktop with properties {name:"Burn Me.fpbf"}


onceagain 08-15-2009 03:07 AM

Yep. That looks like a solution. I didn't actually burn it, but it was asking me for a disc, and said I needed 8GB or so. I'm assuming that if I followed through it it, it would make something that would actually work in the Jeep.

On a related note - I never heard of a burn folder before. Now, having had them pointed out to me, I can see an option for it as plain as day in the Finder's File menu. Go figure.

tw 08-15-2009 01:18 PM

Quote:

Originally Posted by onceagain (Post 547087)
On a related note - I never heard of a burn folder before. Now, having had them pointed out to me, I can see an option for it as plain as day in the Finder's File menu. Go figure.

yeah, it's weird. they introduced those all the way back in the first version of Tiger, I think, and then everyone promptly forgot about them (maybe because there were so many other options). but for quick, basic burning needs they are pretty useful.

onceagain 08-15-2009 05:15 PM

Quote:

Originally Posted by tw (Post 547108)
yeah, it's weird. they introduced those all the way back in the first version of Tiger, I think, and then everyone promptly forgot about them (maybe because there were so many other options). but for quick, basic burning needs they are pretty useful.

For the first 2 years of owning my Jeep, I would periodically find a new button or knob that I never noticed before.


All times are GMT -5. The time now is 12:01 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.