Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Downloads all images from 4chan thread
<?php
ini_set('max_execution_time', 0);
set_error_handler(function() { echo ''; });
function dwnloadURL($url, $path) {
$newfname = $path;
$file = fopen ($url, 'rb');
if ($file) {
$newf = fopen ($newfname, 'wb');
if ($newf) {
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
}
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
}
function download4chThreadImg($board,$thread_id) {
$raw_thread_json = file_get_contents("https://a.4cdn.org/".$board."/thread/".$thread_id.".json");
$thread_json = json_decode($raw_thread_json,true);
for($i = 0;$i < count($thread_json["posts"]);$i++) {
dwnloadURL("https://i.4cdn.org/".$board."/".$thread_json["posts"][$i]["tim"].$thread_json["posts"][$i]["ext"],"E:/yaoi/".$thread_json["posts"][$i]["tim"].$thread_json["posts"][$i]["ext"]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.