#!/usr/bin/perl -w
#
-# webcollage, Copyright © 1999-2013 by Jamie Zawinski <jwz@jwz.org>
+# webcollage, Copyright © 1999-2014 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."
#
my $progname = $0; $progname =~ s@.*/@@g;
-my $version = q{ $Revision: 1.162 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
-my $copyright = "WebCollage $version, Copyright (c) 1999-2013" .
+my ($version) = ('$Revision: 1.167 $' =~ m/\s(\d[.\d]+)\s/s);
+my $copyright = "WebCollage $version, Copyright (c) 1999-2014" .
" Jamie Zawinski <jwz\@jwz.org>\n" .
" http://www.jwz.org/webcollage/\n";
6, "bingimgs", \&pick_from_bing_images,
6, "bingnums", \&pick_from_bing_image_numbers,
- 19, "flickr_recent", \&pick_from_flickr_recent,
- 15, "flickr_random", \&pick_from_flickr_random,
- 20, "instagram", \&pick_from_instagram,
- 6, "livejournal", \&pick_from_livejournal_images,
- 4, "yahoorand", \&pick_from_yahoo_random_link,
+ 21, "flickr_recent", \&pick_from_flickr_recent,
+ 16, "flickr_random", \&pick_from_flickr_random,
+ 23, "instagram", \&pick_from_instagram,
+ 4, "livejournal", \&pick_from_livejournal_images,
+
+ # No longer exists, as of Apr 2014
+ # 4, "yahoorand", \&pick_from_yahoo_random_link,
# Twitter destroyed their whole API in 2013.
# 0, "twitpic", \&pick_from_twitpic_images,
"yandex.ru" => 1,
"imgur.com" => 1,
"yfrog.com" => 1,
+ "cdninstagram.com" => 1,
"yimg.com" => 1, # This is where dailynews.yahoo.com stores
"eimg.com" => 1, # its images, so pick_from_yahoo_news_text()
}
\f
-############################################################################
+#############################################################################
+##
+## Pick images from random pages returned by the Yahoo Random Link
+##
+#############################################################################
+#
+## yahoorand
+#my $yahoo_random_link = "http://random.yahoo.com/fast/ryl";
#
-# Pick images from random pages returned by the Yahoo Random Link
#
-############################################################################
-
-# yahoorand
-my $yahoo_random_link = "http://random.yahoo.com/fast/ryl";
-
-
# Picks a random page; picks a random image on that page;
# returns two URLs: the page containing the image, and the image.
# Returns () if nothing found this time.
#
-sub pick_from_yahoo_random_link($) {
- my ($timeout) = @_;
-
- print STDERR "\n\n" if ($verbose_load);
- LOG ($verbose_load, "URL: $yahoo_random_link");
-
- $last_search = $yahoo_random_link; # for warnings
-
- $suppress_audit = 1;
-
- my ( $base, $body ) = get_document ($yahoo_random_link, undef, $timeout);
- if (!$base || !$body) {
- $body = undef;
- return;
- }
-
- LOG ($verbose_load, "redirected to: $base");
-
- my $img = pick_image_from_body ($base, $body);
- $body = undef;
-
- if ($img) {
- return ($base, $img);
- } else {
- return ();
- }
-}
+#sub pick_from_yahoo_random_link($) {
+# my ($timeout) = @_;
+#
+# print STDERR "\n\n" if ($verbose_load);
+# LOG ($verbose_load, "URL: $yahoo_random_link");
+#
+# $last_search = $yahoo_random_link; # for warnings
+#
+# $suppress_audit = 1;
+#
+# my ( $base, $body ) = get_document ($yahoo_random_link, undef, $timeout);
+# if (!$base || !$body) {
+# $body = undef;
+# return;
+# }
+#
+# LOG ($verbose_load, "redirected to: $base");
+#
+# my $img = pick_image_from_body ($base, $body);
+# $body = undef;
+#
+# if ($img) {
+# return ($base, $img);
+# } else {
+# return ();
+# }
+#}
\f
############################################################################
#
############################################################################
-my $bing_images_url = "http://www.bing.com/images/async" .
- "?CW=0" .
- "&CH=0" .
- "&q=";
+my $bing_images_url = "http://www.bing.com/images/async?q=";
# bingimgs
$page = html_unquote ($page);
$thumb = html_unquote ($thumb);
- next unless ($thumb =~ m@^http://farm\d*\.static\.?flickr\.com/@);
+ next unless ($thumb =~ m@^https?://[^/.]+\d*\.static\.?flickr\.com/@);
my $base = "http://www.flickr.com/";
$page =~ s@^/@$base@;
\f
############################################################################
#
-# Pick random images from Instagram, via gramfeed.com's key.
+# Pick random images from Instagram.
#
############################################################################
-my $instagram_url_base = "https://api.instagram.com/v1/media/popular" .
- "?client_id=b59fbe4563944b6c88cced13495c0f49";
+my $instagram_url_base = "https://api.instagram.com/v1/media/popular";
# instagram_random
sub pick_from_instagram($) {
my $timeout = shift;
- $last_search = $instagram_url_base;
+ # Liberated access tokens.
+ # jsdo.it search for: instagram client_id
+ # Google search for: instagram "&client_id=" site:jsfiddle.net
+ my @tokens = ('b59fbe4563944b6c88cced13495c0f49', # gramfeed.com
+ 'fa26679250df49c48a33fbcf30aae989', # instac.at
+ 'd9494686198d4dfeb954979a3e270e5e', # iconosquare.com
+ '793ef48bb18e4197b61afce2d799b81c', # jsdo.it
+ '67b8a3e0073449bba70600d0fc68e6cb', # jsdo.it
+ '26a098e0df4d4b9ea8b4ce6c505b7742', # jsdo.it
+ '2437cbcd906a4c10940f990d283d3cd5', # jsdo.it
+ '191c7d7d5312464cbd92134f36ffdab5', # jsdo.it
+ 'acfec809437b4340b2c38f66503af774', # jsdo.it
+ 'e9f77604a3a24beba949c12d18130988', # jsdo.it
+ '2cd7bcf68ae346529770073d311575b3', # jsdo.it
+ '830c600fe8d742e2ab3f3b94f9bb22b7', # jsdo.it
+ '55865a0397ad41e5997dd95ef4df8da1', # jsdo.it
+ '192a5742f3644ea8bed1d25e439286a8', # jsdo.it
+ '38ed1477e7a44595861b8842cdb8ba23', # jsdo.it
+ 'e52f79f645f54488ad0cc47f6f55ade6', # jsfiddle.net
+ );
+
+ my $tok = $tokens[int(rand($#tokens+1))];
+ $last_search = $instagram_url_base . "?client_id=" . $tok;
print STDERR "\n\n" if ($verbose_load);
LOG ($verbose_load, "URL: $last_search");
sub which($) {
my ($prog) = @_;
foreach (split (/:/, $ENV{PATH})) {
- if (-x "$_/$prog") {
- return $prog;
+ my $path = "$_/$prog";
+ if (-x $path) {
+ return $path;
}
}
return undef;
#
##############################################################################
-my $image_ppm = sprintf ("%s/webcollage-%08x.ppm",
- ($ENV{TMPDIR} ? $ENV{TMPDIR} : "/tmp"),
- rand(0xFFFFFFFF));
-my $image_tmp1 = sprintf ("%s/webcollage-1-%08x.ppm",
- ($ENV{TMPDIR} ? $ENV{TMPDIR} : "/tmp"),
- rand(0xFFFFFFFF));
-my $image_tmp2 = sprintf ("%s/webcollage-2-%08x.ppm",
- ($ENV{TMPDIR} ? $ENV{TMPDIR} : "/tmp"),
- rand(0xFFFFFFFF));
+my ($image_ppm, $image_tmp1, $image_tmp2);
+{
+ my $seed = rand(0xFFFFFFFF);
+ $image_ppm = sprintf ("%s/webcollage-%08x",
+ ($ENV{TMPDIR} ? $ENV{TMPDIR} : "/tmp"),
+ $seed);
+ $image_tmp1 = $image_ppm . '-1.ppm';
+ $image_tmp2 = $image_ppm . '-2.ppm';
+ $image_ppm .= '.ppm';
+}
+
my $filter_cmd = undef;
my $post_filter_cmd = undef;
sub x_or_pbm_output($) {
my ($window_id) = @_;
+ # Adjust the PATH for OS X 10.10.
+ #
+ $_ = $0;
+ s:/[^/]*$::;
+ s/([^a-zA-Z0-9._\-+\/])/\\$1/g;
+ $ENV{PATH} = "$_:$ENV{PATH}";
+
# Check for our helper program, to see whether we need to use PPM pipelines.
#
$_ = "webcollage-helper";
- if (defined ($webcollage_helper) || which ($_)) {
- $webcollage_helper = $_ unless (defined($webcollage_helper));
+
+ if (! defined ($webcollage_helper)) {
+ $webcollage_helper = which ($_);
+ }
+
+ if (defined ($webcollage_helper)) {
LOG ($verbose_pbm, "found \"$webcollage_helper\"");
$webcollage_helper .= " -v";
} else {
which ($_) || error "$_ not found on \$PATH.";
}
+ # If we're using webcollage-helper and not a filter, then the tmp files
+ # are JPEGs, not PPMs.
+ #
+ if (defined ($webcollage_helper) && !defined ($filter_cmd)) {
+ foreach ($image_ppm, $image_tmp1, $image_tmp2) {
+ s/\.ppm$/.jpg/s;
+ }
+ }
+
+
# find a root-window displayer program.
#
if (!$no_output_p) {
return 0;
}
+ if ($iw <= 0 || $ih <= 0 || $iw > 9999 || $ih > 9999) {
+ LOG (($verbose_pbm || $verbose_load),
+ "ludicrous image dimensions: $iw x $ih (" . length($body) .
+ "): $img");
+ $body = undef;
+ return 0;
+ }
+
open (my $out, '>', $image_tmp1) || error ("writing $image_tmp1: $!");
(print $out $body) || error ("writing $image_tmp1: $!");
close ($out) || error ("writing $image_tmp1: $!");