Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Bottomless supply of wallpaper; a simple little project
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
quag7
Apprentice
Apprentice


Joined: 12 Aug 2002
Posts: 288
Location: Marana, Arizona - USA

PostPosted: Fri Jul 07, 2006 2:51 pm    Post subject: Bottomless supply of wallpaper; a simple little project Reply with quote

I know that I can't be the only one to work in a place that doesn't have easily accessible windows; as such I tend to look at the same unchanging things throughout the day. This can drive me insane. I live in a city with no weather, as well, so that can get harsh after awhile.

Anyway.

One silly little thing I like to do is change my wallpaper frequently. But I really don't have the time or desire to hunt down cool wallpaper for my desktop; if I see something interesting, I grab it, but otherwise I'm stuck with things I've seen a million times before.

As many of you know, one limitless source of images is Usenet. A lot of this porn, obviously, but a surprising amount of isn't if you know where to look. That being said, and I'll warn you up front, pornography will occasionally slip through though on these newsgroups. It's fairly tame; not safe for work perhaps, but it won't get you thrown out of your house either if you patiently explain that you don't have absolute control over it.

Anyway, what I did was, I wrote a few scripts - one script rotates my wallpaper every hour on the hour. Another goes out to Usenet periodically and grabs all images with the criteria I specify, and another indexes the directory containing the images. I've had a fair amount of success by simply requiring that images be a certain size before downloading. Most of the time, garbage, spam, and pornography don't reach this threshold and for the most part the selection (over 8000 wallpaper now) has been surprisingly nice to look at.

Here's how I did it. It's a little hacky; these scripts could probably be improved.

First, emerge the nget package. nget is a command line application that can connect to a news server and download articles or binaries automatically.

Create a directory for incoming images, then put together a script like this (note the initial cd /home/quag7 was necessary because for some reason nget could not find its config file, .ngetrc, otherwise - not sure why):

Code:

#!/bin/sh

cd /home/quag7

nget -g alt.binaries.pictures.wallpaper -l 6000 -p /work/wallpaper-dynamic -r "/*jpg" -h""
nget -g alt.binaries.pictures.fantasy-sci-fi -l 6000 -p /work/wallpaper-dynamic -r "/*jpg"
nget -g alt.binaries.pictures.fine-art -l 6000 -p /work/wallpaper-dynamic -r "/*jpg"
nget -g alt.binaries.pictures.misc -l 6000 -p /work/wallpaper-dynamic -r "/*jpg"
nget -g alt.binaries.pictures.nature -l 6000 -p /work/wallpaper-dynamic -r "/*jpg"
nget -g alt.binaries.pictures.scenic -l 6000 -p /work/wallpaper-dynamic -r "/*jpg"
nget -g alt.binaries.pictures.wallpapers -l 6000 -p /work/wallpaper-dynamic -r "/*jpg"

cd /work/wallpaper-dynamic

rm -f *.txt
rm -f *idx*
rm -f *.doc
rm -f *.pdf
rm -f *.jpg.*
rm -f UNKNOWN*
rm -f ngettemp*
chmod u=rwx,g=rx,o=rx *
/scripts/quagmunge/quagmunge.php
/scripts/wallpaperindexer/wallpaperindexer.pl


-l 6000 = Only download articles greater than 6000 lines. This is a good number for my resolution (1920x1440). If you run at a more sane resolution, you may want to adjust this accordingly, but note that the lower the line count your specify, the more garbage you're going to wind up downloading since spammers generally are all about quantity of posts, not quality.

The script then deletes other detritus that gets downloaded (sometimes subjects have .jpg in them, for example, but don't actually contain images). Note that there are a lot more kinds of pattern matching you can specify; man nget for those. Also remember to fill out your .ngetrc file with your newsgroup login information.

For those of you who don't have Usenet access (sadly, less and less ISPs include it these days), I recommend Athenanews, which for my purposes has had decent image retention for an okay price.

Anyway.

The last two commands in the above script call other scripts. quagmunge is a script I wrote which batch renames files in a directory to a baseline naming scheme. It makes everything lowercase, replaces spaces with underscores, and removes any underscores which repeat more than twice. It also removes other characters which could cause problems like asterisks and so on. I presume a lot of people have a similar script. If you don't, you're going to have to tweak the indexing script to handle spaces in filenames, or else add a simple regex to remove spaces maybe at the end of this first script.

Initially I worked without the indexer; my wallpaper rotation script would simply parse a directory of files and load one randomly. As more and more wallpapers piled up, this got slower and slower until, on my machine, it took almost a minute to run. Creating an index of the filenames that can be parsed at once has reduced this to about five seconds. Here's how my script works (I don't pretend to be a Perl expert; most of these scripts were written as an excuse to learn the language, and it shows; they're a little hacky):

Code:

#!/usr/bin/perl

$wpdirectory = "/work/wallpaper-dynamic";

opendir WPDIR, $wpdirectory
  or die "\n(X) CAN'T OPEN THE DIRECTORY.\n";

print "\n(*) Opened $wpdirectory";

my @wpfiles = readdir(WPDIR)
  or die "\n(X) Couldn't grab filenames.\n";

print "\n(*) Grabbed Filenames.";

print "\n";

foreach my $wpfile (@wpfiles) {

  if ($wpfile =~ /.jpg/) {

    $count++;

    if ($count == 1) {
      $index = $wpfile;
      print "\n[ $count ] : $wpfile";
    }

    else {
      $index = $index . "|" . $wpfile;
      print "\n[ $count ] : $wpfile";
    }


  }

}

print "\n\n(*) $count entries total.";

open(FILEOUT, ">$wpdirectory/wpindex.txt")
  or die "\n(X) Couldn't write to $wpdirectory/wpindex.txt\n";

print "\n(*) Opened $wpdirectory/wpindex.txt";

print FILEOUT $index
  or die "\n(X) Could not write to $wpdirectory/wpindex.txt\n";

close FILEOUT;

print "\n(*) Success :)\n\n";


This opens the directory, reads the contents into an array, and then outputs the filenames separated by a pipe delimiter, into a text file. Simple enough.

The last script, then, is the wallpaper rotater, which I have set up on a cronjob:

Code:

#!/usr/bin/perl
use File::Copy;

$wpdirectory = "/work/wallpaper-dynamic";
$wpindex = "/work/wallpaper-dynamic/wpindex.txt";
$urldir = "/wwwswamp/";

print "\n";

open(FILEIN, "$wpindex")
  or die "\n(X) Could not open $wpindex";

print "\n(*) Opened index file.";

$wallpapers = <FILEIN>;

print "\n(*) Read filenames into memory.";

close(FILEIN);

@files = split /\|/,$wallpapers;

print "\n(*) [ $#files ] files.";

$runthisone = int rand $#files;

# Horribly ugly lazy hack, don't tell anyone.  Zero record is
# empty due to how string is constructed.

if ($runthisone == 0) {
 $runthisone = 1;
}

$newwallpaper = $files[$runthisone];

print "\n(*) Switching to wallpaper:\n\n[ $runthisone ] - $wpdirectory/$newwallpaper";

system("gconftool-2 --type string --set /desktop/gnome/background/picture_filename $wpdirectory/$newwallpaper");

system("gconftool-2 --type string --set /desktop/gnome/background/picture_options stretched");

print "\n\n";

system("echo \"[WALLPAPER]: $newwallpaper ( http://quagseven.dynamicip.com:2012/wwwswamp/latestwallpaper.jpg )\" >> /www/global/irc/qw-status.txt");

copy("$wpdirectory/$newwallpaper","$urldir/latestwallpaper.jpg")
  or die "\n(X) Cannot copy to URL location.";


This last part copies the present wallpaper to a static filename in a publicly accessible directory so if a cool one pops up and I want to share it, I don't have to look up the filename. That last bit with >> /www/global/irc/qw-status.txt simply sends a reminder to a text file read by my IRC bot, which then msgs me the contents of the file (you can skip this).

The above example is for Gnome. If you are running KDE, the command to change your wallpaper at the command line is something like:

Code:

/usr/kde/3.4/bin/dcop --user quag7 --all-sessions kdesktop KBackgroundIface setWallpaper wallpaperfilename.jpg 4


The "4" can also be other numbers - that indicates whether to stretch the wallpaper, resize it or whatever (I forget the specifics; been awhile since I ran kde).

This is a simple little hack, kind of useless actually, but I enjoy it enough that I figured I'd post it for anyone interested. In a day I can look at very high resolution photos of cities, mountains, people, animals, and so on. At any rate, I like it.
_________________
http://www.dataswamp.net
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum