Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

WMA / WMV files

by David Caughell (Monk)
on Mar 26, 2004 at 00:01 UTC ( [id://339913]=perlquestion: print w/replies, xml ) Need Help??

David Caughell has asked for the wisdom of the Perl Monks concerning the following question:

It's been my observation that windows doesn't differentiate between mp3 and wma files. If you tell it to sort a window by file type, it literally sorts those two file types alphabetically as though they were a single type.

I'm almost pretty positive that wma / wmv files can run little programs on your computer that do things like open web browsers. They are also likely to able to cause audio / video files to malfunction when they are played.

To me, this is just about the dirtiest thing that microsoft has ever done, because (if it's true) they've damaged the integrity of their operating system (disabling sort by type for these files).

Coming to the point... Is there any way to write a program that will spot wma files that have been named as mp3 files, and rename / delete / isolate them into a special folder? I don't know much about the file format, or even how you would find out what the file format is.

If this is possible, it would most definitely be a Cool Use For Perl.

--Dave

Replies are listed 'Best First'.
Re: WMA / WMV files
by The Mad Hatter (Priest) on Mar 26, 2004 at 00:58 UTC
    Given a list of files (generated via File::Find or something), you could try opening each one with Audio::WMA and see if you can read any info from them. If you can, then do something with it, otherwise leave it alone. I'm almost sure this wouldn't be failsafe. In fact, it might be more accurate to do it the other way, trying to detect if the file is an MP3 (see the many MP3 modules) and then separate them.

    Update Using File::MimeInfo might be the best solution in determining the filetype.

Re: WMA / WMV files
by hawtin (Prior) on Mar 26, 2004 at 04:18 UTC

    The listing when you sort by "file type" groups together files that map to file types of the same name. Look in "Tools"-> "Folder Options"-> "File Types". If you want to make the two extensions behave differently you can do so in that dialog.

    If you want to move all the "wma" files somewhere you could write a File::Find script to do it, or you could use the Windows Explorer search button to look for the files "*.wma"

    I don't think that even Windows goes round gratuitously renaming your files (mind you it wouldn't surprise me greatly if it did)

Re: WMA / WMV files
by flyingmoose (Priest) on Mar 26, 2004 at 02:53 UTC
    First off, I am *not* a Microsoft fan, nor an apologist. I will however, explain a bit on this.
    Coming to the point... Is there any way to write a program that will spot wma files that have been named as mp3 files, and rename / delete / isolate them into a special folder? I don't know much about the file format, or even how you would find out what the file format is.

    It may be a function of an media player such as Windows Media Player to open a file regardless of extension and divine what it is, then play it appropriately. So I understand your concern. What I would recommend doing here is changing to a different media player, such as WinAmp, where an mp3 is still an mp3. There also are/were similar Windows problems with email, where mime type can or will be ignored in favor of the file extension (or vice versa), allowing seemingly non-executable payloads to be dangerous and/or automatically loaded.

    As to the Perl nature of your question, I'd attack this in a low level sort of way, could you try to read the ID3 tag using a Perl module and see if that fails? Still, I don't think you really need to do this. This is just one of many security problems in Windows, and I have not yet seen any exploit using WMA's to launch arbitrary code -- and if you switch media players, you'll be much safer. Not as safer as running Linux, but safer.

Re: WMA / WMV files
by zentara (Archbishop) on Mar 26, 2004 at 16:09 UTC
    this is just about the dirtiest thing that microsoft has ever done, because (if it's true) they've damaged the integrity of their operating system

    Bwaha ha ha. What "integrity" are you referring to?


    I'm not really a human, but I play one on earth. flash japh
Re: WMA / WMV files
by Anonymous Monk on Mar 27, 2004 at 02:37 UTC
    Working, tested code:
    #!/usr/bin/perl -w use strict; use File::Find; use File::Copy; # WMA/WMV file signature; See: # http://filext.com/detaillist.php?extdetail=WMA # http://filext.com/detaillist.php?extdetail=WMV my $sig = "\x30\x26\xB2\x75\x8E\x66\xCF\x11" . "\xA6\xD9\x00\xAA\x00\x62\xCE\x6C"; my @drives = map {$_.':/'} qw( c e ); # Work-around for Win32 bug in File::Find. chdir $_ foreach @drives; my @fakes; find( sub { # Skip known NTFS-locked directories. $File::Find::prune = 1, return if /^System Volume Information$/; return unless m{\.wm[av]$}i and -f $_; open IN, $_ or return; binmode IN; read(IN, my $f16, 16); close IN; push @fakes, $File::Find::name if $f16 ne $sig; }, @drives ); foreach (@fakes) { print "Fake: $_\n"; move($_, "$_-fake") or warn "Rename failed: '$_'\n"; }
      Oops, I was not signed on when I posted that!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://339913]
Approved by flyingmoose
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-19 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found