http://ftp.x.org/contrib/applications/xscreensaver-3.26.tar.gz
[xscreensaver] / hacks / webcollage
index 880dfb933f6125a3d9494783765932e19616a830..a630e9938663fa6b20d0ab04b649cc79d768beea 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/local/bin/perl5 -w
 #
-# webcollage, Copyright (c) 1999 by Jamie Zawinski <jwz@jwz.org>
+# webcollage, Copyright (c) 1999, 2000 by Jamie Zawinski <jwz@jwz.org>
 # This program decorates the screen with random images from the web.
 # One satisfied customer described it as "a nonstop pop culture brainbath."
 #
@@ -27,7 +27,7 @@ require POSIX;
 use Fcntl ':flock'; # import LOCK_* constants
 
 
-my $version = q{ $Revision: 1.44 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
+my $version = q{ $Revision: 1.60 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
 my $copyright = "WebCollage $version, Copyright (c) 1999" .
     " Jamie Zawinski <jwz\@jwz.org>\n" .
     "            http://www.jwz.org/xscreensaver/\n";
@@ -56,6 +56,8 @@ my $image_randomizer_2 = "http://www.hotbot.com/?clickSrc=search" .
                          "&MT=";
 my $image_randomizer_3 = "http://www.altavista.com/cgi-bin/query?pg=q" .
                          "&text=yes&kl=XX&stype=stext&q=";
+my $image_randomizer_4 = "http://search.news.yahoo.com/search/news_photos?" .
+                         "&z=&n=100&o=o&2=&3=&p=";
 
 # I guess Photopoint got wise to me, because now they are doing error
 # checking on the user ("u=") and album ("a=") parameters.  Oh well.
@@ -94,7 +96,10 @@ my $delay = 0;
 my $wordlist = "/usr/dict/words";
 
 if (!-r $wordlist) {
-    $wordlist = "/usr/share/lib/dict/words";    # irix
+    $wordlist = "/usr/share/dict/words";       # BSD
+}
+if (!-r $wordlist) {
+    $wordlist = "/usr/share/lib/dict/words";    # Irix
 }
 die "$wordlist doesn't exist!\n" unless (-r $wordlist);
 
@@ -608,7 +613,8 @@ sub pick_from_image_randomizer {
 
     my $search_url = ($which == 0 ? $image_randomizer_1 :
                       $which == 1 ? $image_randomizer_2 :
-                      $image_randomizer_3) .
+                      $which == 2 ? $image_randomizer_3 :
+                      $image_randomizer_4) .
         $words;
 
     # Pick a random search-result page instead of always taking the first.
@@ -659,8 +665,10 @@ sub pick_from_image_randomizer {
 
     $_ = $body;
 
-    s/Result [Pp]ages:.*$//s;            # trim off page footer
-    s/^.*?IMAGE RESULTS//s;              # trim off page header
+#    s/Result [Pp]ages:.*$//s;            # trim off page footer
+#    s/^.*?IMAGE RESULTS//s;              # trim off page header
+
+    s/Have you tried these resources.*//s;  # let's try it again
 
     s/[\r\n\t ]+/ /g;
 
@@ -680,25 +688,44 @@ sub pick_from_image_randomizer {
 
         next unless ($u =~ m@^http://@i);  # skip non-http and relative urls.
 
-        next if ($u =~ m@[/.]altavista\.com@i);  # skip altavista builtins
-        next if ($u =~ m@[/.]av\.com@i);
-        next if ($u =~ m@[/.]virage\.com@i);
-        next if ($u =~ m@[/.]photoloft\.com@i);
-        next if ($u =~ m@[/.]shopping\.com@i);
-        next if ($u =~ m@[/.]thetrip\.com@i);
-        next if ($u =~ m@[/.]cmgi\.com@i);
-        next if ($u =~ m@[/.]intelihealth\.com@i);
-        next if ($u =~ m@[/.]wildweb\.com@i);
-        next if ($u =~ m@[/.]digital\.com@i);
-        next if ($u =~ m@[/.]doubleclick\.net@i);
+        next if ($u =~ m@[/.]altavista\.com\b@i);     # skip altavista builtins
+        next if ($u =~ m@[/.]altavista\.[a-z]{2}\b@i); # altavista.fr, etc
+        next if ($u =~ m@[/.]av\.com\b@i);
+        next if ($u =~ m@[/.]virage\.com\b@i);
+        next if ($u =~ m@[/.]photoloft\.com\b@i);
+        next if ($u =~ m@[/.]shopping\.com\b@i);
+        next if ($u =~ m@[/.]thetrip\.com\b@i);
+        next if ($u =~ m@[/.]cmgi\.com\b@i);
+        next if ($u =~ m@[/.]intelihealth\.com\b@i);
+        next if ($u =~ m@[/.]wildweb\.com\b@i);
+        next if ($u =~ m@[/.]digital\.com\b@i);
+        next if ($u =~ m@[/.]doubleclick\.net\b@i);
+        next if ($u =~ m@[/.]freeim\.org\b@i);
+        next if ($u =~ m@[/.]clicktomarket\.com\b@i);  # you cretins
+        next if ($u =~ m@[/.]teragram\.com\b@i);
+
+        # must lose this one for altavista, even though it loses images of
+        # every single customer of akamai.  Oh well, those people have lots
+        # of money, and so their images are probably boring anyway.
+        next if ($u =~ m@[/.]akamai\.net@i);
 
         if ($which == 0 && $u =~ m@[/.]corbis\.com@) {
-            $skipped = 1;
+           $skipped = 1;
             if ( $verbose > 3 ) {
                 print STDERR "$progname: skipping corbis URL: $u\n";
             }
             next;
 
+        } elsif ($which == 3 &&
+                 ($u =~ m@^http://[^/]+$@ ||             # no slashes
+                  $u =~ m@/$@ ||                         # ends in /
+                  ! ($u =~ m@dailynews\.yahoo\.com@))) {  # not dailynews
+#            $skipped = 1;
+            if ( $verbose > 3 ) {
+                print STDERR "$progname: skipping non-AP URL: $u\n";
+            }
+            next;
+
         } elsif ( $rejected_urls{$u} ) {
             if ( $verbose > 3 ) {
                 my $L = $rejected_urls{$u};
@@ -748,7 +775,9 @@ sub pick_from_image_randomizer {
     if ($img) {
         return ($base2, $img,
                 ($which == 0 ? "imagevista" :
-                 $which == 1 ? "hotbot" : "altavista") .
+                 $which == 1 ? "hotbot" :
+                 $which == 2 ? "altavista" :
+                 "ap") .
                 "/$search_count");
     } else {
         return ();
@@ -787,8 +816,8 @@ my $count_4 = 0;
 
 sub pick_image {
     my ( $timeout ) = @_;
-
     my $r = int(rand(100));
+
     my ($base, $img, $source, $total, $count);
 
     if ($r < 20) {
@@ -801,6 +830,11 @@ sub pick_image {
         $total = ++$total_1;
         $count = ++$count_1 if $img;
 
+     } elsif ($r < 65) {
+         ($base, $img, $source) = pick_from_image_randomizer ($timeout, 3);
+         $total = ++$total_4;
+         $count = ++$count_4 if $img;
+
 #    } elsif ($r < 70) {
 #        ($base, $img, $source) = pick_from_photo_randomizer ($timeout);
 #        $total = ++$total_4;
@@ -1023,7 +1057,14 @@ sub image_to_pnm {
 
     $cmd2 = "exec $cmd";        # yes, this really is necessary.  if we don't
                                 # do this, the process doesn't die properly.
-    if ($verbose == 0) {
+    if ($verbose <= 1) {
+        #
+        # We get a "giftopnm: got a 'Application Extension' extension"
+        # warning any time it's an animgif.
+        #
+        # Note that "giftopnm: EOF / read error on image data" is not
+        # always a fatal error -- sometimes the image looks fine anyway.
+        #
         $cmd2 .= " 2>/dev/null";
     }
 
@@ -1177,7 +1218,7 @@ sub x_output {
         } elsif ((@_ = jpeg_size ($body))) {
             ($iw, $ih) = @_;
             $cmd = "djpeg |";
-        } elsif ($body =~ "^P\d\n(\d+) (\d+)\n") {
+        } elsif ($body =~ m/^P\d\n(\d+) (\d+)\n/) {
             $iw = $1;
             $ih = $2;
             $cmd = "";