Jump to content

PGID - Php Google Image Downloader


pbmann

Recommended Posts

I am an artist who has used a script called PGID in my work over the past year or so. It is a wonderful script that automatically downloads google images. I use the images to create photomosaics with over 40,000 tiles. The code was original written by Roberto Butti.

 

For the past few months when I attempt to run the script I get the fallowing error:

 

imgurl="+(b.b.indexOf("://")<0?"http://":"")+b.b+" FAILED

 

I assume that something changed in the way google is linking to images, but have been unable to figure it out. I have a basic understanding of PHP, but have not been able to figure out what I need to do to update the code. Can anyone point me in the right direction?

 

Thanks!

#!/usr/bin/php
<?php
$PROGRAMNAME="PGID";
$VERSION="0.99.1";
$DEBUG=0;
$DIR_BASE=getcwd();
$FILE_HTML="temp.html";
$NPERPAG=20;
$MAXDOWNLOAD=60;

$SURL="http://images.google.com/images?q=";
function WRITE_DEBUG($str) {
  global $DEBUG;
  if ($DEBUG==1) {
    echo "DEBUG :$str\n";
  }
}

function ScriviFile($NomeFile, $str) {
  WRITE_DEBUG("--$NomeFile--");
  $file = fopen($NomeFile, 'w');
  fwrite($file, $str); 
  fclose($file);
}


function WgetFile($URL, $dir, $radice) {
  $nomefile=$dir."/".$radice.basename($URL);
  if (@copy($URL, $nomefile)) {
          echo " DONE\n";
  } else {
          echo " FAILED\n";
  }
}

// BEGIN ______________________________
WRITE_DEBUG($DIR_BASE);
if ($argc == 1) {
  echo $PROGRAMNAME." v. ".$VERSION."\n";
echo "Usage : ".$argv[0]." <keyword>\n";
die();
}
WRITE_DEBUG("ok : processing : ".$argv[1]);
$keyword=$argv[1];
// IMPOSTO LA DIRECTORY DI SALVATAGGIO
$dir_save=$DIR_BASE."/".$keyword."/";
if (file_exists($dir_save)) {
        WRITE_DEBUG("DIR ALREADY EXIST : $dir_save");
} else {
        WRITE_DEBUG("Creating dir $dir_save");
        mkdir($dir_save);
}
$finito=false;
$start=0;
$quante=0;
while (!$finito) { //SCARICA PIUI? PAGINE DI RISULTATI
  $scontent = file_get_contents($SURL.$keyword."&start=".$start);
  $start=$start+$NPERPAG;
  ScriviFile($DIR_BASE."/".$FILE_HTML, $scontent);
  if ($scontent) {
    WRITE_DEBUG($scontent."\n");
  } else {
    echo "ERRORE\n";
  }
  $PATTERN ="((imgurl=[^\&]*)+)"; 
  $pos=0;
  $i=0;
  while ($len=ereg($PATTERN, $scontent, $ritorno)) {
    $i++;
    $quante++;
    if ($i>$NPERPAG) {
      die();
    }
    $pos=strpos($scontent, "imgurl=");
    //echo $pos."\n";
    echo $ritorno[1]."";
    $pos=$pos+$len;
    //echo $pos."\n";
    $scontent=substr($scontent,$pos);
    $url = substr($ritorno[1], 7);
    WgetFile($url,$dir_save, substr("000".$quante, strlen($quante))."_" );
    //ScriviFile($DIR_BASE."/".$i.$FILE_HTML, $scontenta);
    //$scontent=$scontenta;
  }
  if ($i<$NPERPAG) {
    $finito=true;
  }
  if ($start==$MAXDOWNLOAD) {
    $finito=true;
  }
}
echo "DONE\n";

?>

 

Link to comment
https://forums.phpfreaks.com/topic/76662-pgid-php-google-image-downloader/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.