3 ## usage: w32codec_dl.pl (codec.conf location)
5 # this script will use MS's codec dl interface as used by MS Media Player
6 # to attempt to locate the codecs listed in codecs.conf. It will download
7 # them to a directory "codecs/" below the current dir.
8 # you will need the libwww-perl stuff and the utility "cabextract"
9 # which may be found at http://www.kyz.uklinux.net/cabextract.php3
11 # By Tom Lees, 2002. I hereby place this script into the public domain.
13 #use LWP::Debug qw(+);
16 $ua = LWP
::UserAgent
->new;
17 $ua->agent ("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");
19 # Parse the etc/codecs.conf file
21 open CCONF
, "<$cconf";
33 next CC
if (m/^[ \t]*\;/);
37 if (m/^videocodec (.*)/)
41 elsif (m/^[ \t]+driver (.*)/)
43 if ($1 eq "dshow" || $1 eq "vfw")
52 elsif (m/^[ \t]+fourcc (.*)/ && $mscodec == 1)
59 if ($cclist =~ m/\"(....)\"[, ]*(.*)/)
64 elsif ($cclist =~ m/[, ]*(....)[, ]*(.*)/)
74 if (!($cc =~ m/^[ \t]+/))
78 } while (length ($cclist) > 0);
84 open CODEC_CABS
, ">codecs.locations.info";
92 if (!find_codec
($cc))
98 print "MS didn't find $cc\n";
109 my $guid = sprintf ("%08X", unpack ("V", $fourcc))."-0000-0010-8000-00AA00389B71";
111 my $req = HTTP
::Request
->new (POST
=> "http://activex.microsoft.com/objects/ocget.dll");
112 $req->header ('Accept', '*/*');
113 $req->content_type ('application/x-www-form-urlencoded');
114 $req->content ("CLSID=%7B${guid}%7D\n");
115 #$req->content ('CLSID={'.${guid}.'}');
117 my $res = $ua->request ($req);
119 if ($res->is_success) {
120 print "Lookup returned success... weird!\n";
124 if ($res->code == 302)
126 my $loc = $res->headers->header ("Location");
127 if (!$got_codecs{"$loc"})
129 print CODEC_CABS
"$loc\n";
130 $got_codecs{"$loc"} = 1;
135 # print "Already have $loc\n";
141 # print "Lookup failed (Microsoft probably doesn't know this codec)\n";
151 my $req = HTTP
::Request
->new (GET
=> $url);
152 $req->header ("Accept", "*/*");
153 my $res = $ua->request ($req);
155 if ($res->is_success)
157 open TMP
, ">tmp.cab" or die "Unable to open tmp.cab";
158 print TMP
$res->content;
161 system "cabextract tmp.cab";
166 print "No such file!\n";