tundal45@wordpress:~$

>puts "Hello, World!"

Posts Tagged ‘reckless programming

Zune Bug

leave a comment »

I know that I am a/an |insert-your-favorite_insult| for owning Microsoft Zune but all I needed was a significantly big MP3 Player that can store all my music and have a decent interface so that I can play what I want while I work out. It may not be anywhere close to the apple wheel but that stuff becomes irrelevant when you are running on a treadmill, panting like a dog and desperately trying not to fall off.

Anyways, I was unhappy that Zune’s Sync did not transfer all my songs. I realized this because I had moved all my Floyd songs and ‘Time’ (one of my favorites) was nowhere to be found. I thought that since it was a Microsoft product, it was looking at crazy DRM rules and trying to only move music that it deemed was “Zuneworthy“.

The option that remained was to manually move all the music I wanted into my collection and then Sync them that way. The problem was that my music is organized into folders by artist names. So I wrote a script (code at the end of the post) that looked under each sub-directory under my root music folder and moved the mp3 files to another folder so that I can have a “sub-folderless” copy of my music from which I can select all my music and add to Zune Collection and Sync them manually. I was smart enough to ignore the case on the .mp3 filetype because some of my music has .MP3. That and ignoring case is usually a good idea except for few case-sensitive instances. However, I still could not find my beloved song “Time” in the collection. I also noticed that the total number of songs added to collection was lower than the total number of songs in my folder.

I was mad that such elaborate plan that included script writing did not scratch the initial itch. I went back to the folder to see what was so special about that mp3 file. Was it some permission issue? When I saw it, I was furious at Zune Software Developers. The file was named ‘Time.MP3’ and as soon as I changed the name to ‘Time.mp3’, Zune was able to recognize its presence. UGH!

I am not sure if I am being annoyed at a good practice but I think that case-sensitivity when it comes to filetype is stupid, especially if the OS that you develop is smart enough to recognize that a.mp3 and a.MP3 are both songs.

While I was not shocked at such a reckless programming error coming from Microsoft, I was mostly annoyed that my elaborate code writing was useless. Then I realized that I can re-use most of the structure of the previous code to identify the files ending with .MP3 and rename those to end with .mp3 (code for this below as well).

SCRIPT 1: The Move Script

#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use Time::Local;
use Time::LocalTime;
use Cwd;

my $input_dir = 'F:\\Music\\English\\';
my $output_dir = 'E:\\Music\\';

open (MOVED, ">>processed_artists.txt") or die("Could not open Log File".$!);
opendir (INPUT, $input_dir) or die("Could not open Input Directory".$!);

while (my $folder = readdir(INPUT)) {
   next if ($folder =~ m/^\./);
   next if ($folder =~ m/^(Jazz N Blues|Oldies|Others|Steve Vai|Techno)$/);

   chdir $input_dir;
   opendir (MUSIC, $folder) or die ("Could not open $folder.\n".$!);

   my $new_dir = $input_dir.$folder."\\";
   my $start_time = time;

   print "Current Artist: $folder\n";

   while (my $file = readdir(MUSIC)) {
      if ($file =~ m/\.mp3$/i) {
         chdir $new_dir;
         print "Moving $file to $output_dir ....";
         copy("$file", "$output_dir") or die ("Could not move $file.\n".$!);
         print "DONE!\n";
      }

      closedir(MUSIC);
      print "Processed ".$folder."\'s Music in ".(time - $start_time)." Seconds\n";
      print MOVED $folder."\n";
   }
}

close(MOVED);
closedir(INPUT);
exit 0;

SCRIPT 2: The Rename Script

#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use Time::Local;
use Time::LocalTime;
use Cwd;

my $input_dir = 'E:\\Music\\';
opendir (INPUT, $input_dir) or die("Could not open Input Directory".$!);
my $count = 0;
chdir $input_dir;
while (my $file = readdir(INPUT)) {
    next if ($file =~ m/^\./);

    if ($file =~ m/([^\.]*)\.MP3$/) {
	    my $new_name = $1.".mp3";
	    $count += 1;
	    rename($file, $new_name) || print "Don't have permission to rename $file: $!\n";
    }
}
print "There are $count files that were renamed.\n";
closedir(INPUT);
exit 0;

Advertisements

Written by tundal45

February 10, 2009 at 9:39 am