SWMBO needed to build an .asx playlist (controller) on w32. Her existing tools were a grand PITA. So, this oneoff, which is probably non-novel. Nonetheless FWIW, in the hope that someone will find it useful.. and in even higher hopes that the wise Brethern will apply a CLUESTICK to any gaffs
UPDATE:Based on comments from jdporter, I've discovered that this will NOT find .mp3's with their system attribute set (why would they have that set? I dunno!) but does find them once they're modified attrib -s *.mp3.
And thanks will be given for further comments, corrections, problems!
Cheers... and bash on!#!C:/perl/bin -w # buildasx.pl # Build a (Windows) .asx playlist of .mp3s (Caveat: PRESUMED encoded a +t 128Kbps bitrate) # .mp3 ONLY: see TODO # subdir selected must not be more than 4 deep # ww 2007-05-07 # TODO ############################################################### +##################### # timing calculation is imprecise (seconds are approx) , but so far, a +ppears unimportant # Add support for .wav etc. # add UI to let user select dir and asx filename, defaulting to CWD an +d CWD's name (replacing hardcoded name at 20) # and maybe, replace regex for ident of dir with something better # END TODO as of 2007-05-07 ###################################################################### +##################### ##### Get the output of W32's dir cmd to @list $input = qx{dir} || print STDERR "Couldn't do qx{dir} \/n: $!"; @list = split (/\n/, $input); ##### Open output file (title.asx) and print headers open (ASX, ">title.asx") || die "Can't open title.asx for write: $!"; print ASX '<Asx Version = "3.0" >' . "\n" . '<Param Name = "Name" Valu +e = "title" />' . "\n" . '<Param Name = "AllowShuffle" Value = "yes" +/>' . "\n\n"; #### Now, use info from the dir at line 15 and capture those elements +needed for .asx for $list(@list) { if ($list =~ / ([A-X]: # BEGIN ($dir) CAPTURE: Drive l +etter \\[\s,A-Z,a-z,-,_,0-9]* # first child \\[\s,A-Z,a-z,-,_,0-9]* # second child \\[\s,A-Z,a-z,-,_,0-9]* # third child \\[\s,A-Z,a-z,-,_,0-9]*) # fourth child, END CAPTURE, EN +D of conditional test /x ) { # extended, END of conditional +test $dir = $1; next; } if ($list =~ / (\d{2}\/\d{2}\/\d{4} # CAPTURE_1 (create_date) \s+ # space(s) \d{2}:\d{2}[ap]) # create_time END_CAPTURE \s+ # space(s) (\d+,\d{3},\d{3}) # CAPTURE_2 (file_size) END_CAPTURE \s+ # space(s) ([A-Z,a-z,0-9] # CAPTURE_3: (file_name) first char of na +me [^.]* # anything not a literal period \. # literal (name-type separator) mp3) # title END_CAPTURE /xi ) { # extended, CaseInsens, END of conditiona +l test $file_name = $3; $file_size = $2; $create_date = $1; #### Convert filesize to (rough) duration in seconds and thence to min +utes:seconds:(kluded)decimals : if ($file_size) { $file_size =~ s/,//g; # remove commas, al +tho using "dir /-C" would save us this cleanup $sec_dec = $file_size/16000; # in seconds though + something 16,042..16,080 is more nearly precise $min_dec = ($sec_dec/60); # minutes and decim +al minutes $mins = int ( $min_dec); # drop the decimal +fraction if (length($mins) == 1) { # and prepend a zer +o if mins < 10 $mins = "0" . $mins; } $secs = $sec_dec % 60; # seconds NOT preci +se if (length($secs) == 1) { # and prepend a zer +o if secs < 10 $secs = "0" . $secs; } $duration = "00:$mins" . ":" . "$secs" . ".999"; # not e +xpecting any selection to exceed 59 min 59.999 sec # the " +.999" is a kludge to offset possible modulus truncation } else { $duration = "xx:xx:xx.000"; } #### now print specific entry: print ASX "\n<Entry> \n"; print ASX "<Title > $file_name </Title>\n"; print ASX '<Duration value = "' . "$duration" . '" />' . "\n\n" +. '<Param Name = "Name" Value = "' . "$file_name" . '" />' . "\n\n +" . '<Param Name = "MediaType" Value = "audio" />' . "\n\n" . '<Param Name = "MediaAttribute" Value = "0" />' . "\n\n" . '<Param Name = "Bitrate" Value = "128768" />' . "\n\n" . '<Param Name = "DigitallySecure" Value = "0" />' . "\n\n" . '<Param Name = "PlayCount" Value = "1" />' . "\n\n" . '<Param Name = "SourceURL" Value = "' . "$dir\\$file_name" . '" +/>' . "\n\n" . '<Param Name = "CreationDate" Value = "' . "$create_date" . '" / +>' . "\n\n" . '<Ref href = "' . "$dir\\$file_name" . '" />' . "\n" . '</Entry>' . "\n\n"; } # END OF conditional_a +ction } # END OF for #### Print close tag for .asx and close file print ASX '</Asx>'; close ASX; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: buildasx.pl (W32 Windows playlist builder)
by jdporter (Paladin) on May 07, 2007 at 21:26 UTC | |
|
Re: buildasx.pl (W32 Windows playlist builder)
by blazar (Canon) on May 07, 2007 at 20:24 UTC | |
|
Re: buildasx.pl (W32 Windows playlist builder)
by ww (Archbishop) on May 07, 2007 at 22:32 UTC | |
by blazar (Canon) on May 07, 2007 at 22:39 UTC | |
by ww (Archbishop) on May 10, 2007 at 17:59 UTC | |
|
Re: buildasx.pl (W32 Windows playlist builder)
by girarde (Hermit) on May 29, 2007 at 16:52 UTC |