Created
March 14, 2011 15:49
-
-
Save tfausak/869351 to your computer and use it in GitHub Desktop.
Downloads all the wallpapers on Simple Desktops.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; | |
} | |
} | |
?> |
doesn't work.
@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
Can you run this and upload a version here? I can't seem to get the code to run properly