Skip to content

Instantly share code, notes, and snippets.

@tfausak
Created March 14, 2011 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tfausak/869351 to your computer and use it in GitHub Desktop.
Save tfausak/869351 to your computer and use it in GitHub Desktop.
Downloads all the wallpapers on Simple Desktops.
#!/usr/bin/env php
<?php
for ($page = 1; true; $page += 1) {
# Get the page of desktops
$url = 'http://simpledesktops.com/browse/' . $page . '/';
$html = @file_get_contents($url);
# Bail if we hit a 404
if ($html === false) {
break;
}
# Go line-by-line
foreach (explode("\n", $html) as $line) {
# This is the desktop's title (name)
if (!preg_match('/title="(.*?)"/', $line, $matches)) {
continue;
}
$title = $matches[1];
# This is the desktop's full-resolution URL
if (!preg_match('/href="(.*?)"/', $line, $matches)) {
continue;
}
$url = $matches[1];
# If the URL doesn't match YYYY/MM/DD, it's not a desktop
if (!preg_match('/([0-9]{4})\/([0-9]{2})\/([0-9]{2})/', $url, $matches)) {
continue;
}
list(, $year, $month, $day) = $matches;
# Make a simple file name
$name = strtolower($title);
$name = preg_replace('/[^a-z]/', '-', $name);
$name = preg_replace('/-+/', '-', $name);
$name = preg_replace('/^-/', '', $name);
$name = preg_replace('/-$/', '', $name);
$name = $year . $month . $day . '-' . $name . '.png';
# Don't re-download existing assets
if (file_exists($name)) {
continue;
}
# Download and write the desktop
$image = file_get_contents($url);
file_put_contents($name, $image);
echo $name . "\n";
}
}
?>
@dkovacevic15
Copy link

Can you run this and upload a version here? I can't seem to get the code to run properly

@joaofgf
Copy link

joaofgf commented Nov 4, 2017

doesn't work.

@vitebo
Copy link

vitebo commented Jul 14, 2018

@joaofgf and @dkovacevic15
my fork it's working!

@tfausak
can you upgrade please? thank you.
https://gist.github.com/vitebo/abfc05afed1044bc1f7004629f96764b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment