Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@dkovacevic15 dkovacevic15 commented Feb 10, 2017

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

@joaofgf

This comment has been minimized.

Copy link

@joaofgf joaofgf commented Nov 4, 2017

doesn't work.

@vitebo

This comment has been minimized.

Copy link

@vitebo 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