annotate TOOLS/w32codec_dl.pl @ 33114:5ad451a5ebec

Remove useless warning message. Instead, add debug message and return whether conversion was successful or not and use the return code to issue an appropriate error message.
author ib
date Mon, 04 Apr 2011 12:40:20 +0000
parents 32725ca88fed
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
1 #!/usr/bin/perl
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
2
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
3 ## usage: w32codec_dl.pl (codec.conf location)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
4
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
5 # this script will use MS's codec dl interface as used by MS Media Player
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
6 # to attempt to locate the codecs listed in codecs.conf. It will download
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
7 # them to a directory "codecs/" below the current dir.
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
8 # you will need the libwww-perl stuff and the utility "cabextract"
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
9 # which may be found at http://www.kyz.uklinux.net/cabextract.php3
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
10
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
11 # By Tom Lees, 2002. I hereby place this script into the public domain.
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
12
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
13 #use LWP::Debug qw(+);
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
14 use LWP::UserAgent;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
15
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
16 $ua = LWP::UserAgent->new;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
17 $ua->agent ("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)");
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
18
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
19 # Parse the etc/codecs.conf file
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
20 my $cconf = $ARGV[0];
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
21 open CCONF, "<$cconf";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
22
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
23 my $codec = "(none)";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
24 my $mscodec = 0;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
25
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
26 my $cc, @ccl;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
27
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
28 mkdir "codecs";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
29 chdir "codecs";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
30
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
31 CC: while (<CCONF>)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
32 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
33 next CC if (m/^[ \t]*\;/);
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
34 s/\;.*//g;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
35 s/#.*//g;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
36
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
37 if (m/^videocodec (.*)/)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
38 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
39 $codec = $1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
40 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
41 elsif (m/^[ \t]+driver (.*)/)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
42 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
43 if ($1 eq "dshow" || $1 eq "vfw")
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
44 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
45 $mscodec = 1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
46 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
47 else
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
48 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
49 $mscodec = 0;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
50 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
51 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
52 elsif (m/^[ \t]+fourcc (.*)/ && $mscodec == 1)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
53 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
54 $cclist = $1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
55 chomp $cclist;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
56 #@ccl = ();
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
57 do
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
58 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
59 if ($cclist =~ m/\"(....)\"[, ]*(.*)/)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
60 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
61 $cc = $1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
62 $cclist = $2;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
63 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
64 elsif ($cclist =~ m/[, ]*(....)[, ]*(.*)/)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
65 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
66 $cc = $1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
67 $cclist = $2;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
68 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
69 else
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
70 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
71 $cc = $cclist;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
72 $cclist = "";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
73 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
74 if (!($cc =~ m/^[ \t]+/))
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
75 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
76 push @ccl, ($cc);
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
77 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
78 } while (length ($cclist) > 0);
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
79 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
80 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
81 close CCONF;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
82
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
83 # Find the codecs
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
84 open CODEC_CABS, ">codecs.locations.info";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
85 %fcc_try = ();
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
86 while ($#ccl > 0)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
87 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
88 $cc = pop (@ccl);
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
89 if (!$fcc_try{"$cc"})
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
90 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
91 $fcc_try{"$cc"} = 1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
92 if (!find_codec ($cc))
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
93 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
94 print "$cc found\n";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
95 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
96 else
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
97 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
98 print "MS didn't find $cc\n";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
99 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
100 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
101 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
102 close CODEC_CABS;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
103
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
104 %got_codecs = ();
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
105 sub find_codec
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
106 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
107 my ($fourcc) = @_;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
108
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
109 my $guid = sprintf ("%08X", unpack ("V", $fourcc))."-0000-0010-8000-00AA00389B71";
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
110
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
111 my $req = HTTP::Request->new (POST => "http://activex.microsoft.com/objects/ocget.dll");
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
112 $req->header ('Accept', '*/*');
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
113 $req->content_type ('application/x-www-form-urlencoded');
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
114 $req->content ("CLSID=%7B${guid}%7D\n");
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
115 #$req->content ('CLSID={'.${guid}.'}');
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
116
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
117 my $res = $ua->request ($req);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
118
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
119 if ($res->is_success) {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
120 print "Lookup returned success... weird!\n";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
121 return 1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
122 } else {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
123 # Codec location
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
124 if ($res->code == 302)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
125 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
126 my $loc = $res->headers->header ("Location");
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
127 if (!$got_codecs{"$loc"})
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
128 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
129 print CODEC_CABS "$loc\n";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
130 $got_codecs{"$loc"} = 1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
131 get_codec ($loc);
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
132 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
133 # else
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
134 # {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
135 # print "Already have $loc\n";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
136 # }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
137 return 0;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
138 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
139 else
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
140 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
141 # print "Lookup failed (Microsoft probably doesn't know this codec)\n";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
142 return 1;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
143 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
144 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
145 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
146
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
147 sub get_codec
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
148 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
149 my ($url) = @_;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
150
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
151 my $req = HTTP::Request->new (GET => $url);
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
152 $req->header ("Accept", "*/*");
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
153 my $res = $ua->request ($req);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
154
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
155 if ($res->is_success)
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
156 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
157 open TMP, ">tmp.cab" or die "Unable to open tmp.cab";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
158 print TMP $res->content;
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
159 close TMP;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 6195
diff changeset
160
6195
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
161 system "cabextract tmp.cab";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
162 unlink "tmp.cab";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
163 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
164 else
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
165 {
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
166 print "No such file!\n";
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
167 }
39805251ef61 Downloads w32codecs from M$, script by Tom Lees <tal26 at cam.ac.uk>
atmos4
parents:
diff changeset
168 }