Created
April 23, 2011 10:40
-
-
Save mmalecki/938537 to your computer and use it in GitHub Desktop.
4chan thread's images downloader (downloads each image from given thread, invocation like: php 4ctd.php thread_url dir_to_save_images)
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
<?php | |
$url = $argv[1]; | |
$prefix = (isset($argv[2])) ? $argv[2] : ''; | |
$fprefix = (isset($argv[3])) ? $argv[3] : ''; | |
$f = file_get_contents($url) or die('URL invalid'); | |
if (!is_dir($prefix)) | |
mkdir($prefix); | |
$img = array(); | |
preg_match_all('|http://images.4chan.org/[a-z]+/src/([0-9]+\..{0,3})|', $f, $img); | |
$img[0] = array_unique($img[0]); | |
$img[1] = array_unique($img[1]); | |
echo 'Found ' . count($img[0]) . " images.\n"; | |
foreach ($img[0] as $key => $url) { | |
$path = $prefix . '/' . $fprefix . $img[1][$key]; | |
if (!file_exists($path)) { | |
echo "Geting {$img[1][$key]}..."; | |
echo ($f = @file_get_contents($url)) ? ' Success.' : 'Failure.', "\n"; | |
file_put_contents($path, $f); | |
} | |
else | |
echo "Ommiting {$img[1][$key]} as it exists.\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment