Script to get Pictures from Google

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
Tadeu64
Posts: 4
Joined: 2013-01-06 22:16:48

Script to get Pictures from Google

Post by Tadeu64 »

Hi. I was looking for a script to get only the cover for my movies and other files (no more information needed) but could not find one that was suitable. Remarkably, I found that just copying the title from AMC and searching in Google pictures worked like a charm!

So, I decided to create a script just for that: get the file name and look for images in google.

This script shows various options that can be viewed by the "View" buttom in the PickList

I hope it is usefull to other people.

Here it goes:

GooglePics.ifs

Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=Tadeu Cunha
Title=Google Picture Import
Description=Get picture from google.com images
Site=http://www.google.com
Language=EN
Version=1.00 - 01.06.2013
Requires=3.5.0
Comments=See code comments. Thanks to the authors of IMDB.ifs and IAFD.ifs
License=GPL
GetInfo=1
RequiresMovies=1

[Options]
AutoSelect=0|1|0=Always show movie selection dialog|1=Auto-select movie if there is only one
GetOnlyFirstPicture=0|0|0=Show available pictures|1=Get Only the first picture found

[Parameters]

***************************************************)

program GooglePics;

// no mail; comments only in web

uses
  StringUtils1;
var
  MovieName: string;
const
  BaseURL  = 'http://www.google.com/search?safe=off&tbo=d&source=lnms&tbm=isch&sa=X&q=';
  MaxItems = 50;

// ---
function RemoveBrackets(wholetext: string) : string;
var
  str1: String;
  i: Integer;
begin
  str1 := Trim(TextBefore(wholetext, '[', ''));
  if str1 <> '' then
  begin
    if Pos(']', RemainingText) > 0 then
      wholetext := str1+' '+Trim(TextAfter(RemainingText, ']'));  // + end of text or ''
  end;
  result := Trim(wholetext);
end;
// ---
function RemovePar(wholetext: string) : string;
var
  str1: String;
  i: Integer;
begin
  str1 := Trim(TextBefore(wholetext, '(', ''));
  if str1 <> '' then
  begin
    if Pos(')', RemainingText) > 0 then
      wholetext := str1+' '+Trim(TextAfter(RemainingText, ')'));  // + end of text or ''
  end;
  result := Trim(wholetext);
end;

// ---
procedure AnalyzePage(Address: string);
var
  LineCnt: Integer;
  PageText,strRef, strImg: string;
begin
  // Read the whole page
	PageText := GetPage(Address);
  
  // Looks for the first images
  LineCnt:= MaxItems;
  PickTreeClear;

  if CheckVersion(4,1,2) = True then 
    PickTreeTitle(MovieName);

  while LineCnt > 0 do
  begin
    // Looks for tag imgrefurl
    if pos('imgrefurl=', PageText) = 0 then
    begin
      if LineCnt = MaxItems then
      begin
        ShowError('Error: imgrefurl tag not found! Probably something changed at Google :(');
        exit;
      end;
      break;
    end;
    
    // Get the img reference
    strRef := TextBetween(PageText,'imgrefurl=', '&');
    PageText := RemainingText;
    
    // Get the img url
    if pos('imgurl=', PageText) = 0 then
    begin
      if LineCnt = MaxItems then
      begin
        ShowError('Error: imgurl tag not found! Probably something changed at Google :(');
        exit;
      end;
      break;
    end;  
    strImg := TextBetween(PageText,'imgurl=', '&');
    PageText := RemainingText;
    
    if (GetOption('GetOnlyFirstPicture') = 1) then
    begin
      // That's it, we have the picture!
      GetPicture (strImg);
      exit;
    end
    
    // Add this option to the tree
    PickTreeAdd(strRef, strImg);
    LineCnt := LineCnt - 1;
  end
  
  // User choose the image, get it!
  if PickTreeExec(strImg) then
    GetPicture (strImg);
end;
//------------------------------------------------------------------------------

begin
  //SetField(fieldChecked, '');

  MovieName := GetField(fieldOriginalTitle);
  if MovieName = '' then MovieName := GetField(fieldTranslatedTitle);
  if (GetOption('AutoSelect') = 0) or (MovieName = '') then
	if Input('Google Picture Import', 'Input title:', MovieName) = False then exit;
  MovieName := RemovePar(RemoveBrackets(MovieName));
  AnalyzePage(BaseURL + UrlEncode(MovieName));
end.
FIXED: Checking version before using PicTreeTitle, that only works since version 4.1.2 (Thks, SoulSnake !)
Last edited by Tadeu64 on 2013-01-11 03:46:41, edited 1 time in total.
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Thanks ;)
Tetsujin
Posts: 13
Joined: 2012-12-09 03:04:40

Script error in "GOOGLEPICS"

Post by Tetsujin »

Script error in "GOOGLEPICS":unknown identifier:PICKTREETITLE at line 54.
[url]http://dl.dropbox.com/u/6574173/ScriptError.jpg[/url]
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

The function PickTreeTitle only exists since version 4.1.2.

You can replace line

Code: Select all

  PickTreeTitle(MovieName);
by

Code: Select all

  if CheckVersion(4,1,2) = True then
    PickTreeTitle(MovieName);
or upgrade AMC to version 4.1.2.

Soulsnake.
Tetsujin
Posts: 13
Joined: 2012-12-09 03:04:40

Post by Tetsujin »

Upgrade to latest version worked fine..
Thanks
fulvio53s03
Posts: 744
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

Very useful & nice script! :grinking:
Should it be possible to limitate searched image dimension (or to show dimensions in picklist) and/or using only one language page's origin?
(i.e.: only medium images coming from Italian language Sites)

Thanks in advance
:)
fogrob
Posts: 7
Joined: 2007-12-27 08:27:24

Google Picture Import does not work ---Please help me

Post by fogrob »

Unfortunately, the script does not work, every time I do a search on an image I get an error message "Error: imgrefurl tag not found! Probably something changed at Google :(".
Please help me because I should. Thank you in advance for your help.
:??: :??: :cry:
otreux
Posts: 194
Joined: 2008-10-22 16:55:46

Re: Script to get Pictures from Google

Post by otreux »

is possible update the script? thanks :)
Post Reply