Skip to content

Instantly share code, notes, and snippets.

@flashwave
Created March 11, 2019 16:17
Show Gist options
  • Save flashwave/6d73dd3f2d195bec518b6655d6727d65 to your computer and use it in GitHub Desktop.
Save flashwave/6d73dd3f2d195bec518b6655d6727d65 to your computer and use it in GitHub Desktop.
script i made in 2014 that downloaded random catgirl images but is broken now because the references domain is dead

Catgirl Downloader

This is a thing I wrote out of complete boredom, basically it's a PHP CLI application (in other words you run this in a terminal/command prompt window) and it downloads catgirls to a folder called catgirls in the same folder as the script!

Good use of PHP, right?

<?php
/*
* PHP CLI Script that saves a bunch of catgirl images with no duplicates
* By Flashwave <http://flash.moe>
* Released under Whatever The Fuck Public License <http://wtfpl.org>
*
* Basically what this does is it runs a for loop the runs for the amount of time that you enter
* in the console that downloads images of manga cat girls and saves them in a folder called catgirls.
* A complete waste of time but that's ok.
* Also it checks if an image exists before saving so you don't end up with 5 million
* copies of the same image, aren't I nice...
*/
// Die if PHP Version isn't 5.4.0 or more
if(version_compare(phpversion(), '5.4.0', '<'))
die('Catgirl Downloader is not compatible with your version of PHP, please upgrade to, at least, 5.4.0.');
// Get amount of times to run the for loop from the console, default to 50 if fucking happens
$times = (isset($argv[1]) && is_numeric($argv[1]) && $argv[1] > 0) ? $argv[1] : 50;
// Random image server
$images = 'http://nyaa-me.herokuapp.com/random';
// Create directory
if(!file_exists('catgirls/'))
mkdir('catgirls', 0777);
// Some arrays to save shit in while stuff is going.
$hashes = array(); // sha1 hashes
$logging = 0; // Amount of times the script ran
print "Starting The Catgirling\r\n\r\n";
// Build hash table of files that already exist
foreach(glob("catgirls/*.*") as $kawaii) {
$hashes[sha1_file($kawaii)] = 1;
}
// The Catgirling
for($i = 0; $i < $times; $i++) {
$img = file_get_contents($images);
$img_hash = sha1($img);
$img_mime = getimagesizefromstring($img)['mime'];
$img_ext = substr(strstr($img_mime, '/'), 1);
$img_name = $img_hash . '.' . $img_ext;
++$logging;
if(array_key_exists($img_hash, $hashes)) {
print $logging . ": Image " . $img_name . " already exists.\r\n";
--$i;
} else {
file_put_contents('catgirls/' . $img_name, $img);
$hashes[$img_hash] = 1;
print $logging . ": Saved " . $img_name . " to the catgirls folder.\r\n";
}
}
print "\r\nCatgirl'd " . $logging . " times.\r\nScript made by Flashwave <http://flash.moe> 2014";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment