* convert to FB_HTMLCREF if there are malformed characters
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Sun, 10 Mar 2013 09:54:24 +0000 (09:54 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Sun, 10 Mar 2013 09:54:24 +0000 (09:54 +0000)
git-svn-id: https://lab.mitty.jp/svn/lab/trunk@203 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

misc/save.pl

index 6b673a8..5c5a1db 100755 (executable)
@@ -13,7 +13,6 @@ my $target = shift @ARGV || die "$0: URL or file-of-url-list [coding]\n";
 my $coding = shift @ARGV || 'utf8';
 
 my $ua  = LWP::UserAgent->new;
-my $enc = find_encoding($coding);
 
 my @URLs;
 if ($target !~ /^http/ && -f $target) {
@@ -33,7 +32,13 @@ foreach my $url (@URLs) {
         my $filename = $res->filename;
         my $decoder = Encode::Guess->guess($filename);
         if (ref($decoder)) {
-            $filename = $enc->encode($decoder->decode($filename));
+            print $decoder->name;
+            $filename = encode(
+                $coding,
+                $decoder->decode($filename),
+                Encode::FB_HTMLCREF
+            );
+            print ": $filename\n";
         }
         
         my $suffix = 1;