Page 1 of 1

[REL] [ENG] auto.tools.ifs is modified UpdateFields script

Posted: 2007-03-22 16:22:24
by HappyTalk
Hi me again. Last year I began customising Scorpions fantastic UpdateFields script adding things I needed as I went along. I've left the original functionality pretty much intact AFAIK and added new functions and minor mods to some of the exisiting ones. I totally Anglicised it as well as though I understand French (un peu) it got real confusing for me when altering the code and when using it. I figured it may be of use to others, so I spent time tidying it up and testing it and here it is.

Main changes:-
- Get picture by URL or Amazon (for each record or set all the same ( useful for series))
- Renumber all files
- Concat files: Written for MyFilms MediaPortal plugin's multiple filename support whereby you do m:\movie.01.avi;m:\movie.02.avi . Slightly awkward as you must manually delete excess files (ones with lower counts) afterwards. 2 modes: Simple concats all, Advanced: concats all sequential ones with similar titles so can work with lots at once (if in number order!)
- Append fields. Will append one field to another one. By using append you can effect MOVE by clearing destination, appending source then clearing source OR COPY by clearing dest then appending source so caters for all variations with just a few steps.
- Others were added that should be self explanatory.

OK here it is. As with my other scripts it requires my autoutils.pas file I append after the main script. (also req's ScorEpioNCommonScript that you should already have)

The 2 files you need may be downloaded from here:-
http://antp.be/temp/scripts/auto.tools.ifs &
http://antp.be/temp/scripts/AutoUtils.pas

--------------------
Here they are in regular text format:-

auto.tools.ifs

Code: Select all

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

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

[Infos]
Authors=HappyTalk/ScorEpioN
Title=Auto.Tools (ENG)
Description=Tools to manipulate fields
Site=http://
Language=EN
Version=2007.03.22
Requires=3.5
Comments=Script requires ScorEpioNCommonScript.pas and autoutils.pas|Modified by HappyTalk from original script by ScorEpioN|Translated into English + modified & added functions||ConcatFiles merges Source Field entries to ; seperated and sets Disks to|number of files in the field. |ConcatMode: Simple appends all selected in order. Advanced orders them|as may not be in order in Ant + can do multiple different groups. |Afterwards manually delete all entries with lower counts to clean up.||GetImage you may choose to input a URL OR give a name to issue an amazon |search. Option to prompt for each entry OR to use first one the same |for all following records (useful for series having same cover)||Renumber Files, will renumber all selected files. Best applied to all records|OR you may get duplicates which is a bad idea.|
License=
GetInfo=1

[Options]
Update Fields=1|1|0=Yes|1=No
Choose Case=3|3|0=All LowerCase|1=All UpperCase|2=First Letter UpperCase|3=Proper Case (First letter each word is UpperCase)
Duplicate Picture=1|1|0=Prompt For New Picture For Every Record|1=Same Picture For All Records
ConcatMode=0|0|0=Simple: Append of all items in order they come|1=Advanced: Use Title.01 format for proper sorting & multiple groups

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

program Auto_Tools;
uses
  ScorEpioNCommonScript, AutoUtils;
  

const
  VersionScript = '2007.03.22';
  NomScript = 'Auto.Tools (ENG)';

var
  Update, NewField, NewValue, Abort, FirstExec : String;
  Field1, Field2 : Integer;
  PicUrl : String;
  BaseTitle, FileList: string; // used by ConcatFiles
  arrayFiles : array of string;
  RecordCnt : Integer; // holds current record count
  
//------------------------------------------------------------------------------
// Confirm Dialog
//------------------------------------------------------------------------------
function confirm(leMessage : String): Boolean;
begin
  if (FirstExec <> 'N') then
  begin
    if (ShowConfirmation(leMessage) = True) then
    begin
      result := True;
    end else
      result := False;
  end else
    result := True;
end;

//------------------------------------------------------------------------------
// Give fields the desired case?
//------------------------------------------------------------------------------

function GetCase(titre : String; option : Integer) : string;
begin
  if (option = 0) then
  begin
     titre := AnsiLowerCase(titre);
  end else if (option = 1) then
  begin
     titre := AnsiUpperCase(titre);
  end else if (option = 2) then
  begin
     titre := AnsiUpFirstLetter(titre);
  end else if (option = 3) then
  begin
     titre := AnsiMixedCase(titre,' -');
  end;
  result := titre;
end;

//------------------------------------------------------------------------------
// Duplicate Fields
//------------------------------------------------------------------------------
procedure duplicateFields();
begin
  if (confirm('Are you sure you want to duplicate the field : '+GetField(fieldTranslatedTitle)+' ('+GetField(fieldOriginalTitle)+'). '+'Are you sure you have correctly selected the target ?') = True) then
  begin
     if (FirstExec <> 'N') then
     begin
      SetStatic('Titretraduit',GetField(fieldTranslatedTitle));  // Titre traduit
      SetStatic('Titreoriginal', GetField(fieldOriginalTitle));  // Titre original
      SetStatic('Description', GetField(fieldDescription));      // Description
      SetStatic('Media', GetField(fieldMedia));                  // Media
      SetStatic('Typedemedia', GetField(fieldMediaType));        // Type de media
      SetStatic('Source', GetField(fieldSource));                // Source
      SetStatic('Ladate', GetField(fieldDate));                  // Date
      SetStatic('Lemprunteur', GetField(fieldBorrower));         // Emprunteur
      SetStatic('Note', GetField(fieldRating));                  // Note
      SetStatic('Directeur', GetField(fieldDirector));           // Directeur
      SetStatic('Producteur', GetField(fieldProducer));          // Producteur
      SetStatic('Pays', GetField(fieldCountry));                 // Pays
      SetStatic('Categorie', GetField(fieldCategory));           // Categorie
      SetStatic('Annee', GetField(fieldYear));                   // Annee
      SetStatic('Duree', GetField(fieldLength));                 // Duree
      SetStatic('Acteurs', GetField(fieldActors));               // Acteurs
      SetStatic('URL', GetField(fieldURL));                      // URL
      SetStatic('Commentaires', GetField(fieldComments));        // Commentaires
      SetStatic('Formatvideo', GetField(fieldVideoFormat));      // Format video
      SetStatic('Formataudio', GetField(fieldAudioBitrate));     // Format audio
      SetStatic('Bitratevideo', GetField(fieldVideoBitrate));    // Bitrate video
      SetStatic('Bitrateaudio', GetField(fieldAudioBitrate));    // Bitrate audio
      SetStatic('Resolution', GetField(fieldResolution));        // Resolution
      SetStatic('Nbframe', GetField(fieldFrameRate));            // Nbframe
      SetStatic('Langue', GetField(fieldLanguages));             // Langue
      SetStatic('Soustitre', GetField(fieldSubtitles));          // Sous-titre
      SetStatic('Taille', GetField(fieldSize));                  // Taille
      SetStatic('Nbdisque', GetField(fieldDisks));               // Nb de disque
     end else
     begin
      if CanSetField(fieldTranslatedTitle) then SetField(fieldTranslatedTitle, GetStatic('Titretraduit'));
      if CanSetField(fieldOriginalTitle) then SetField(fieldOriginalTitle, GetStatic('Titreoriginal'));
      if CanSetField(fieldDescription) then SetField(fieldDescription, GetStatic('Description'));
      if CanSetField(fieldMedia) then SetField(fieldMedia, GetStatic('Media'));
      if CanSetField(fieldMediaType) then SetField(fieldMediaType, GetStatic('Typedemedia'));
      if CanSetField(fieldSource) then SetField(fieldSource, GetStatic('Source'));
      if CanSetField(fieldDate) then SetField(fieldDate, GetStatic('Ladate'));
      if CanSetField(fieldBorrower) then SetField(fieldBorrower, GetStatic('Lemprunteur'));
      if CanSetField(fieldRating) then SetField(fieldRating, GetStatic('Note'));
      if CanSetField(fieldDirector) then SetField(fieldDirector, GetStatic('Directeur'));
      if CanSetField(fieldProducer) then SetField(fieldProducer, GetStatic('Producteur'));
      if CanSetField(fieldCountry) then SetField(fieldCountry, GetStatic('Pays'));
      if CanSetField(fieldCategory) then SetField(fieldCategory, GetStatic('Categorie'));
      if CanSetField(fieldYear) then SetField(fieldYear, GetStatic('Annee'));
      if CanSetField(fieldLength) then SetField(fieldLength, GetStatic('Duree'));
      if CanSetField(fieldActors) then SetField(fieldActors, GetStatic('Acteurs'));
      if CanSetField(fieldURL) then SetField(fieldURL, GetStatic('URL'));
      if CanSetField(fieldComments) then SetField(fieldComments, GetStatic('Commentaires'));
      if CanSetField(fieldVideoFormat) then SetField(fieldVideoFormat, GetStatic('Formatvideo'));
      if CanSetField(fieldAudioBitrate) then SetField(fieldAudioBitrate, GetStatic('Formataudio'));
      if CanSetField(fieldVideoBitrate) then SetField(fieldVideoBitrate, GetStatic('Bitratevideo'));
      if CanSetField(fieldAudioBitrate) then SetField(fieldAudioBitrate, GetStatic('Bitrateaudio'));
      if CanSetField(fieldResolution) then SetField(fieldResolution, GetStatic('Resolution'));
      if CanSetField(fieldFrameRate) then SetField(fieldFrameRate, GetStatic('Nbframe'));
      if CanSetField(fieldLanguages) then SetField(fieldLanguages, GetStatic('Langue'));
      if CanSetField(fieldSubtitles) then SetField(fieldSubtitles, GetStatic('Soustitre'));
      if CanSetField(fieldSize) then SetField(fieldSize, GetStatic('Taille'));
      if CanSetField(fieldDisks) then SetField(fieldDisks, GetStatic('Nbdisque'));
     end;
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// FUNCTION to append the comments field to the description field
//------------------------------------------------------------------------------
procedure moveComment();
begin
  if (confirm('You will append the comments field to the description field.') = True) then
  begin
   if (CanSetField(fieldDescription) and CanSetField(fieldComments))  then
   begin
     moveComments();
   end;
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// FUNCTION to append Field1 to Field2
//------------------------------------------------------------------------------
procedure appendField(Fld1, Fld2 : Integer);
begin
//  if (confirm('You will append the " + Field1 + " field to the " + Field2 + " field.') = True) then
  if (confirm('You will append value of Field1 to end of Field2') = True) then
  begin
    if (CanSetField(Fld2)) then
   		SetField(Fld2, GetField(Fld2) + GetField(Fld1));
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// FUNCTION to renumber records
//------------------------------------------------------------------------------
procedure RenumberRecords();
begin
//  if (confirm('You will append the " + Field1 + " field to the " + Field2 + " field.') = True) then
  if (confirm('You will renumber ALL chosen records starting from 1') = True) then
  begin
    if (CanSetField(fieldNumber)) then
   		SetField(fieldNumber, IntToStr(RecordCnt));
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// UPDATED FUNCTION OF The CASE OF The TITLES AND The NAMES
//------------------------------------------------------------------------------
procedure UpdateCase();
begin
  if (confirm('You will modify the case of the fields ''''Title'''', and ''''Names'''', the ''''Country'''' and the ''''Genres'''', according to the modifiable fields and selected option.') = True) then
  begin
// Original Title
    if (CanSetField(fieldOriginalTitle)) then
      SetField(fieldOriginalTitle, GetCase(GetField(fieldOriginalTitle),GetOption('Choose Case')));
// Translated Title
    if (CanSetField(fieldTranslatedTitle)) then
      SetField(fieldTranslatedTitle, GetCase(GetField(fieldTranslatedTitle),GetOption('Choose Case')));
// Director
    if (CanSetField(fieldDirector)) then
      SetField(fieldDirector, GetCase(GetField(fieldDirector),GetOption('Choose Case')));
//Producer
  if (CanSetField(fieldProducer)) then
      SetField(fieldProducer, GetCase(GetField(fieldProducer),GetOption('Choose Case')));
// Actors
  if (CanSetField(fieldActors)) then
      SetField(fieldActors, GetCase(GetField(fieldActors),GetOption('Choose Case')));
// Category
  if (CanSetField(fieldCategory)) then
      SetField(fieldCategory, GetCase(GetField(fieldCategory),GetOption('Choose Case')));
// Country
  if (CanSetField(fieldCountry)) then
      SetField(fieldCountry, GetCase(GetField(fieldCountry),GetOption('Choose Case')));
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// Copy Title
//------------------------------------------------------------------------------
procedure CopyTitle();
begin
  if (confirm('You will duplicate the titles (if empty), with selected case.') = True) then
  begin
    if GetField(fieldTranslatedTitle) = '' then
    begin
      if (CanSetField(fieldTranslatedTitle)) then
        SetField(fieldTranslatedTitle, GetCase(GetField(fieldOriginalTitle),GetOption('Choose Case')));
    end else
    if GetField(fieldOriginalTitle) = '' then
    begin
      if (CanSetField(fieldOriginalTitle)) then
        SetField(fieldOriginalTitle, GetCase(GetField(fieldTranslatedTitle),GetOption('Choose Case')));
    end;
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// Delete titles
//------------------------------------------------------------------------------
procedure delTitle(Title : Integer);
begin
  if (confirm('You will delete the title fields') = True) then
  begin
      DeleteTitle(Title);
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// FUNCTION WHICH prompts to choose title to be removed
//------------------------------------------------------------------------------
procedure menuTitle();
var 
	Field: String;
begin
  if (FirstExec <> 'N') then
  begin
    PickTreeClear;
    PickTreeAdd('To choose the fields which you wish to remove :', '');
    PickTreeAdd('Original Title', IntToStr(fieldOriginalTitle));
    PickTreeAdd('Translated Title', IntToStr(fieldTranslatedTitle));
    PickTreeExec(Field);
    Field1 := StrToInt(Field,0)
  end;

  delTitle(Field1);

end;

//------------------------------------------------------------------------------
// DELETE A WORD
//------------------------------------------------------------------------------

procedure deleteWord(Champs : Integer);
begin
  if (NewField = '') then
    Input('Delete a Word', 'Enter the word to delete :', NewField);
  SetField(Champs, posReplaceString(NewField, '', '', GetField(Champs), 1));
end;



//------------------------------------------------------------------------------
// Replace a word
//------------------------------------------------------------------------------

procedure replaceWord(Champs : Integer);
begin
  if (NewField = '') then
    Input('Replace a Word','Enter the word to find :', NewField);
  if (NewValue = '') then
    Input('Replace a Word','Enter the word to replace it with :', NewValue);
  SetField(Champs, posReplaceString(NewField, '', NewValue, GetField(Champs), 1));
end;

procedure replaceWord2(Champs : Integer);
begin
  if (NewField = '') then
    Input('Replace a Word after 2nd instance','Enter the word to find :', NewField);
  if (NewValue = '') then
    Input('Replace a Word after 2nd instance','Enter the word to replace it with :', NewValue);
  SetField(Champs, nposReplaceString(NewField, NewValue, GetField(Champs), 2));
end;

// convert first space after last dot to a dot
procedure ReplaceSpaceDot(Champs : Integer);
var
  p : integer;
  s : string;
begin
  s := GetField(Champs);
  p := nposrev('.', s, 1);
  if (p > 0) then
  begin
    p := ppos(' ', s, p);
    if (p > 0) then s := StrLeft(s, p-1) + '.' + StrMid(s, p+1, 0);
  end;
  SetField(Champs, s);
end;


//------------------------------------------------------------------------------
// Replace a field
//------------------------------------------------------------------------------

procedure replaceField(Champs : Integer);
begin
  if (NewField = '') then
    Input('Replace a Field', 'Enter the new value for the field :', NewField);
  SetField(Champs, NewField);
end;

//------------------------------------------------------------------------------
// Insert Text at start of field
//------------------------------------------------------------------------------

procedure InsertText(Champs : Integer);
begin
  if (NewField = '') then
    Input('Insert Text', 'Enter the text to insert :', NewField);
  SetField(Champs, NewField+GetField(Champs));
end;


//------------------------------------------------------------------------------
// Delete a field
//------------------------------------------------------------------------------

procedure deleteField(Champs : Integer);
begin
  if (confirm('Are you sure you wish to delete the value for this field?') = True) then
  begin
    SetField(Champs, '');
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// Set checkmark against empty fields, clear for non empty
//------------------------------------------------------------------------------
procedure checkEmptyField(Champs : Integer);
begin
 if (GetField(Champs) = '') then
    SetField(fieldChecked, 'x')
  else
    SetField(fieldChecked, '');
end;

//------------------------------------------------------------------------------
// Import an image from a given URL
//------------------------------------------------------------------------------

procedure NewImage();
begin
  if (NewField = '') then
    Input('Import Image by URL', 'Enter the URL for the image :', NewField);
  GetPicture(NewField);
end;

// prompts to get amazon picture and uses same url for rest of pics
procedure GetPictures();
var
MovieName: string;
begin
  if CanSetPicture then
  begin
    if (FirstExec <> 'N') or (GetOption('Duplicate Picture') = 0) then
    begin
      picUrl := '';
      MovieName := ConvertAlphaSpace(GetField(fieldOriginalTitle));
      if not (Input('URL/Amazon.com Pic Import', 'Enter URL Or Amazon Title', MovieName)) then exit; //SeName := '';
      if MovieName = '' then exit;
      if StrLeft(MovieName,4) = 'http' then
        PicUrl := MovieName
      else
        PicUrl := GetAmazonPicUrl(MovieName, true); //get pic show picker
    end;

    if PicUrl <> '' then
      GetPicture(PicUrl); // use last value as will be same (for 2 part movies that use same image)
  end;
end;


//------------------------------------------------------------------------------
// Change country
//------------------------------------------------------------------------------

procedure transCountry();
begin
  if (confirm('You are about to transform the country field') = True) then
  begin
    if CanSetField(fieldCountry) then
      SetField(fieldCountry, transformCountry(GetField(fieldCountry)));
  end else
  begin
    abort := 'O';
  end;
end;

//------------------------------------------------------------------------------
// Proc to set the total size of the files
//------------------------------------------------------------------------------
procedure TotalFileSize();
var
  i, Total: Integer;
  s: string;
begin
  i := 1;
  Total := 0;
  s := GetField(fieldSize);
  while i <= Length(s) do
  begin
    if (StrGet(s, i) >= '0') and (StrGet(s, i) <= '9') then
      i := i + 1
    else
    begin
      if i > 1 then
        Total := Total + StrToInt(Copy(s, 1, i - 1), 0);
      Delete(s, 1, i);
      i := 1;
    end;
  end;
  if i > 1 then
  begin
    Total := Total + StrToInt(Copy(s, 1, i - 1), 0);
    SetField(fieldSize, IntToStr(Total));
  end;
end;

//------------------------------------------------------------------------------
// Translate Synopsis
//------------------------------------------------------------------------------
procedure translateSynopsis();
var
   Adresse, Parametre, Description, Resultat, Line : String;
   BeginPos, EndPos : Integer;
begin
  if (confirm('You will translate the fields''''Description''''.') = True) then
  begin
     if (NewField = '') then
     begin
				PickTreeClear;
				PickTreeAdd('Sélectionner les langues source et cible :', '');
				PickTreeAdd('From Chinese (simple) To English', 'zh_en');
				PickTreeAdd('From Chinese (trad) To English', 'zt_en');
				PickTreeAdd('From English to Chinese simpl.', 'en_zh');
				PickTreeAdd('From English to Chinese trad.', 'en_zt');
				PickTreeAdd('From English to Dutch', 'en_nl');
				PickTreeAdd('From English to French', 'en_fr');
				PickTreeAdd('From English to German', 'en_de');
				PickTreeAdd('From English to Greek', 'en_el');
				PickTreeAdd('From English to Italian', 'en_it');
				PickTreeAdd('From English to Japanese', 'en_ja');
				PickTreeAdd('From English to Korean', 'en_ko');
				PickTreeAdd('From English to Portuguese', 'en_pt');
				PickTreeAdd('From English to Russian', 'en_ru');
				PickTreeAdd('From English to Spanish', 'en_es');
				PickTreeAdd('From Dutch to English', 'nl_en');
				PickTreeAdd('From Dutch to French', 'nl_fr');
				PickTreeAdd('From French to Dutch', 'fr_nl');
				PickTreeAdd('From French to English', 'fr_en');
				PickTreeAdd('From French to German', 'fr_de');
				PickTreeAdd('From French to Greek', 'fr_el');
				PickTreeAdd('From French to Italian', 'fr_it');
				PickTreeAdd('From French to Portuguese', 'fr_pt');
				PickTreeAdd('From French to Spanish', 'fr_es');
				PickTreeAdd('From German To English', 'de_en');
				PickTreeAdd('From German To French', 'de_fr');
				PickTreeAdd('From Greek To English', 'el_en');
				PickTreeAdd('From Greek To French', 'el_fr');
				PickTreeAdd('From Italian To English', 'it_en');
				PickTreeAdd('From Italian To French', 'it_fr');
				PickTreeAdd('From Japanese To English', 'ja_en');
				PickTreeAdd('From Korean To English', 'ko_en');
				PickTreeAdd('From Portuguese To English', 'pt_en');
				PickTreeAdd('From Portuguese To French', ' pt_fr');
				PickTreeAdd('From Russian To English', 'ru_en');
				PickTreeAdd('From Spanish To English', 'es_en');
				PickTreeAdd('From Spanish To French', 'es_fr');
				PickTreeExec(NewField);
		end;
    Description := GetField(fieldDescription);
    Description := StringReplace(Description , #13#10, ' ');
    Description := UTF8Encode(Description);
		Adresse := URLEncode('http://babelfish.altavista.com/tr');
		Parametre := 'do it =done&intl=1&tt=urltext&trtext='+Description+'&lp='+NewField;
    Line := PostPage(Adresse,Parametre);
    BeginPos := Pos('<td bgcolor=white class=s><div style=padding:10px;>', Line);
    Delete(Line, 1, BeginPos+50);
		EndPos := Pos('</div></td>', Line);
		Resultat := Copy(Line, 1, EndPos-1 );
		Resultat := StringReplace(Resultat, #13#10, ' ');
		Resultat := UTF8Decode(Resultat);
		HTMLDecode(Resultat);
		HTMLRemoveTags(Resultat);
    SetField(fieldDescription, Resultat);
  end else
  begin
    abort := 'O';
  end;    
end;

//------------------------------------------------------------------------------
// Concat Filenames
//------------------------------------------------------------------------------
procedure ConcatFiles();
var
  Title, FileName: string;
  CurBaseTitle: string;
  i, cnt: integer;
begin
	if (GetOption('ConcatMode') = 0) then //simple concat all files in given order
	begin
		Filename := GetField(fieldSource);

		if FileList <> '' then FileList := FileList + ';';
		FileList := FileList + FileName;

		SetField(fieldSource, FileList);
		SetField(fieldChecked, 'x')
		SetField(fieldDisks, IntToStr(RecordCnt));
	end	else
	begin
		Title := GetField(fieldOriginalTitle);
		Filename := GetField(fieldSource);

		CurBaseTitle := nposLeft('.', Title, 1, true);  // Lost.1x01.Pilot.01 = Lost.1x01.Pilot
		if (CurBaseTitle <> BaseTitle) then
		begin
			BaseTitle := CurBaseTitle; //store new base title
			for i := 0 to 15 do
				arrayFiles[i] := '';
		end;
		i := StrToInt(StrLeft(nposRight('.', Title, 1, true),2),0);
		arrayFiles[i] := Filename;

		cnt := 0;
		Filename := '';
		for i := 0 to 15 do
		begin
			if (arrayFiles[i] <> '') then
			begin
				if Filename <> '' then Filename := Filename + ';';
				Filename := Filename + arrayFiles[i];
				cnt := cnt + 1;
			end;
		end;

		SetField(fieldOriginalTitle, CurBaseTitle + ' (' + IntToStr(cnt) + ')');
		SetField(fieldSource, Filename);
		SetField(fieldChecked, 'x')
		SetField(fieldDisks, IntToStr(cnt));
	end;	
end;


    


//--------------- MAIN FUNCS ---------------------------------------------------
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
// Main menu function
//------------------------------------------------------------------------------
function menu() : String;
begin
    PickTreeClear;
    PickTreeAdd('Import Image by URL Or Amazon', 'GetPictures');
    PickTreeAdd('Duplicate record', 'Duplicate');
    PickTreeAdd('Move Comments -> Description', 'Move');
    PickTreeAdd('Change letter format with option', 'GetCase');
    PickTreeAdd('Check Empty Field', 'checkEmptyField');
    PickTreeAdd('Remove title tags', 'Tags');
    PickTreeAdd('Copy Title If Empty Title', 'Copier');
    PickTreeAdd('Delete Double Title', 'DeleteDouble');
    PickTreeAdd('Delete a field', 'deleteF');
    PickTreeAdd('Replace a field', 'replaceF');
    PickTreeAdd('Delete Text', 'deleteW');
    PickTreeAdd('Replace text', 'replaceW');
    PickTreeAdd('Replace text after 2nd instance', 'replaceW2');
    PickTreeAdd('Insert Text At Start', 'insertT');
    PickTreeAdd('Transform Nationality to Country', 'transCountry');
    PickTreeAdd('Sum Format to Size Field', 'TotalFileSize');
    PickTreeAdd('Translate Synopsis with Altavista', 'Translate');
    PickTreeAdd('Append Field1 to end of Field2', 'appendField');
    PickTreeAdd('Concat Filenames', 'ConcatFiles');
    PickTreeAdd('Renumber Records', 'RenumberRecords');
    PickTreeExec(Update);
	result := Update;
end;

//------------------------------------------------------------------------------
// Function to call selected task
//------------------------------------------------------------------------------
procedure executeTask();
begin
   if (Update = 'GetPictures') then
   begin
     GetPictures();
   end else if (Update = 'checkEmptyField') then
   begin
     menuFields('checkEmptyField');
   end else if (Update = 'transCountry') then
   begin
     transCountry();
   end else if (Update = 'Move') then
   begin
     moveComment();
   end else if (Update = 'Tags') then
   begin
     SetField(fieldTranslatedTitle, GetCase(cleanTitle(GetField(fieldTranslatedTitle)),GetOption('Choose Case')));
     SetField(fieldOriginalTitle, GetCase(cleanTitle(GetField(fieldOriginalTitle)),GetOption('Choose Case')));
   end else if (Update = 'GetCase') then
   begin
     UpdateCase();
   end else if (Update = 'TotalFileSize') then
   begin
     TotalFileSize();
   end else if (Update = 'DeleteDouble') then
   begin
     menuTitle();
   end else if (Update = 'Copier') then
   begin
     CopyTitle();
   end else if (Update = 'deleteW') then
   begin
     menuFields('deleteW');
   end else if (Update = 'deleteF') then
   begin
     menuFields('deleteF');
   end else if (Update = 'insertT') then
   begin
     menuFields('insertT');
   end else if (Update = 'replaceW') then
   begin
     menuFields('replaceW');
   end else if (Update = 'replaceW2') then
   begin
     menuFields('replaceW2');
   end else if (Update = 'appendField') then
   begin
     menuFields('appendField');
   end else if (Update = 'replaceF') then
   begin
     menuFields('replaceF');
   end else if (Update = 'Translate') then
   begin
     translateSynopsis();
   end else if (Update = 'ConcatFiles') then
   begin
     ConcatFiles();
   end else if (Update = 'RenumberRecords') then
   begin
     RenumberRecords();
   end else if (Update = 'Duplicate') then
   begin
     duplicateFields();
   end;
end;

//------------------------------------------------------------------------------
// Prompt field
//------------------------------------------------------------------------------
function promptField() : Integer;
var 
	Field: String;
begin
	PickTreeClear;
	PickTreeAdd('Actors',IntToStr(fieldActors));
	PickTreeAdd('Borrower',IntToStr(fieldBorrower));
	PickTreeAdd('Category',IntToStr(fieldCategory));
	PickTreeAdd('Comments',IntToStr(fieldComments));
	PickTreeAdd('Country',IntToStr(fieldCountry));
	PickTreeAdd('Description',IntToStr(fieldDescription));
	PickTreeAdd('Director',IntToStr(fieldDirector));
	PickTreeAdd('Languages',IntToStr(fieldLanguages));
	PickTreeAdd('Media Label', IntToStr(fieldMedia));
	PickTreeAdd('Media Type', IntToStr(fieldMediaType));
	PickTreeAdd('Number', IntToStr(fieldNumber));
	PickTreeAdd('Original Title', IntToStr(fieldOriginalTitle));
	PickTreeAdd('Producer',IntToStr(fieldProducer));
	PickTreeAdd('Source', IntToStr(fieldSource));
	PickTreeAdd('Subtitles',IntToStr(fieldSubtitles));
	PickTreeAdd('Translated Title', IntToStr(fieldTranslatedTitle));
	PickTreeAdd('URL',IntToStr(fieldURL));
	PickTreeExec(Field);
  Result := StrToInt(Field,0)
end;


//------------------------------------------------------------------------------
// Select field menu
//------------------------------------------------------------------------------
procedure menuFields(lAction : String);
begin
	
  if (FirstExec <> 'N') then
  begin
    Field1 := promptField();
  end;
  
  if (lAction = 'checkEmptyField') then
  begin
    checkEmptyField(Field1);
  end else
  if (lAction = 'deleteW') then
  begin
    deleteWord(Field1);
  end else
  if (lAction = 'deleteF') then
  begin
    deleteField(Field1);
  end else
  if (lAction = 'insertT') then
  begin
    InsertText(Field1);
  end else
  if (lAction = 'replaceW') then
  begin
    replaceWord(Field1);
  end else
  if (lAction = 'replaceW2') then
  begin
    replaceWord2(Field1);
  end else
  if (lAction = 'appendField') then
  begin
    if (FirstExec <> 'N') then
	  begin
	    Field2 := promptField();
	  end;
    appendField(Field1, Field2);
  end else
  if (lAction = 'replaceF') then
  begin
    replaceField(Field1);
  end;
end;


//------------------------------------------------------------------------------
// Main
//------------------------------------------------------------------------------

begin
  if CheckVersion(3,5,0) then
  begin
    if GetOption('Update Fields') = 0 then
    begin
       execMenuMAJ(VersionScript,NomScript);
       exit;
    end;
    
    if FirstExec <> 'N' then
    begin
    	RecordCnt := 1;
      SetArrayLength(arrayFiles, 16);
    end else  
    begin
    	RecordCnt := RecordCnt + 1;
    end;
    
    if (Abort <> 'O') then
    begin
      if (Update = '') then
        Update := menu();
      executeTask();
      FirstExec := 'N';
    end else
    begin
      exit;
    end;
  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
    exit;
end.
AutoUtils.pas

Code: Select all

unit AutoUtils;

(***************************************************
AutoUtils by HappyTalk 2006.
Unit to add string, soundex and other functions to ANT
scripts. You may use unit in your scripts.
Please do not modify this original file, make a newly
named one. you can redistribute it and/or modify it under 
the terms of the GNU General Public License

--------------------------------------------------
Version = 2007.03.22 
Currently used by
Auto.TV.Com
Auto.IMDB.Com
Auto.Tools scripts
--------------------------------------------------

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


const AutoUtils_Version = '2007.03.22';


//-----------------------------
// MATHS FUNCTIONS
//-----------------------------
// rets min of 2 values
function Min(X, Y: Integer): Integer;
begin
  if X < Y then Min := X else Min := Y;
end;

// rets max of 2 values
function Max(X, Y: Integer): Integer;
begin
  if X > Y then Max := X else Max := Y;
end;



//-----------------------------
// STRING FUNCTIONS
//-----------------------------
Function stringReverse(S : String): String;
Var
   i : Integer;
Begin
   Result := '';
   For i := Length(S) DownTo 1 Do
   Begin
     Result := Result + Copy(S,i,1) ;
   End;
End;

//finds pos of last sFind in sStr
Function revpos(sFind, sStr: string; p: Integer) : Integer;
var
p2: Integer;
begin
  result := 0;
  if Length(Sstr) >= p then
  begin
    //p2 := pos(sFind, copy(sStr, p, length(sStr)- p + 1)) + p - 1;
    p2 := pos(sFind, StrMid(sStr, p, 0)) + p - 1;
    if p2 >= p then result := p2
  end;
end;

// returns the pos of nth instance of sFind found in sStr going from reverse of string to start
Function nposrev(sFind, sStr: string; n: Integer) : Integer;
var
sFindRev, sStrRev: string;
p: Integer;
begin
  sFindRev := stringReverse(sFind);
  sStrRev := stringReverse(sStr);

  p := npos(sFindRev, sStrRev, n);
  if p > 0 then
    result := Length(sStr) - p - Length(sFind) + 2
  else
    result := 0;
end;

// returns pos of sFind in sStr from position p in str
Function ppos(sFind, sStr: string; p: Integer) : Integer;
var
p2: Integer;
begin
  result := 0;
  if Length(Sstr) >= p then
  begin
    //p2 := pos(sFind, copy(sStr, p, length(sStr)- p + 1)) + p - 1;
    p2 := pos(sFind, StrMid(sStr, p, 0)) + p - 1;
    if p2 >= p then result := p2
  end;
end;

// returns the pos of nth instance of sFind found in sStr or 0 if none.
Function npos(sFind, sStr: string; n: Integer) : Integer;
var
p: Integer;
begin
  result := 0;
  p := 0;
  repeat
    p := ppos(sFind, sStr, p+1);
    n := n - 1;
  until (p = 0) or (n = 0);
  result := p;
end;

// gets the right hand string AFTER nth instance of sFind in sStr,
// if bReverse nth instance is nth from end working backwards
Function nposRight(sFind, sStr: string; n: Integer; bReverse: boolean) : string;
var
p: integer;
begin
  result := '';
  if bReverse then
    p := nposrev(sFind, sStr, n) + Length(sFind) // set to pos AFTER nth occurrence
  else
    p := npos(sFind, sStr, n) + Length(sFind); // set to pos AFTER nth occurrence
  if (p > Length(sFind)) and (p <= Length (sStr)) then
    result := StrMid(sStr, p, 0);
end;

// gets the left hand string BEFORE nth instance of sFind in sStr
Function nposLeft(sFind, sStr: string; n: Integer; bReverse: boolean) : string;
var
p: integer;
begin
  result := '';
  if bReverse then
    p := nposrev(sFind, sStr, n) - 1 // set to pos BEFORE nth occurrence
  else
    p := npos(sFind, sStr, n) - 1; // set to pos BEFORE nth occurrence

  if (p > 0) then
    result := StrLeft(sStr, p);
end;


Function StrLeft(str: string; len: Integer) : string;
begin
  result := copy(str,1,len);
end;

Function StrRight(str: string; len: Integer) : string;
begin
  result := copy(str,Max(1,length(str)-len+1), len);
end;

// rets len chars from position p or rest if len=0
Function StrMid(str: string; p, len: Integer) : string;
begin
  if len = 0 then len := length(str)- p + 1;
  result := copy(str,p,len);
end;


// replaces all occurences of sFind with sReplace in sStr from after n'th instance of sFind
function nposReplaceString(sFind, sReplace: string; sStr: string; n:Integer): string;
var
  p: Integer;
begin
  p := npos(sFind, sStr, n) + 1;
  if p > 1 then
    sStr := posReplaceString(sFind, '', sReplace, sStr, p);
  result := sStr;
end;


// replaces all occurences of text between sFindBeg & sFindEnd with sReplace in sStr from position FBeg onwards
// sFindEnd can be '' to only replace sFindBeg's not range
// sReplace can be '' to just erase each occurence
function posReplaceString(sFindBeg, sFindEnd, sReplace: string; sStr: string; FBeg: Integer): string;
var
  FEnd: Integer;
begin
  if FBeg < 1 then FBeg := 1;
  while (true) do
  begin
    FBeg := ppos(sFindBeg, sStr, FBeg);
    if FBeg = 0 then break;

    if sFindEnd <> '' then
    begin
      FEnd := ppos(sFindEnd, sStr, FBeg+1);
      if FEnd = 0 then break;
      FEnd := FEnd + Length(sFindEnd);
    end else
      FEnd := FBeg + Length(sFindBeg);

    delete(sStr, FBeg, FEnd-FBeg);
    if sReplace <> '' then insert(sReplace, sStr, FBeg);
    FBeg := FBeg + Length(sReplace);
    if FBeg > Length(sStr) then Break;
  end;
  result := sStr;
end;


// Removes all space from start and end and ensures there is no more than SpCnt consecutive space inside string
// also Strips HTML out if required
Function StripSpace(s: string; SpCnt: Integer; StripHTML: Boolean) : string;
var
i, cnt: Integer;
s2, ch: string;
begin
  s2 := '';
  s := Trim(s);
  For i := 1 To Length(s) do
  begin
    ch := copy(s, i, 1);
    if (ch = ' ') then
    begin
      if (cnt < SpCnt) then
      begin
        s2 := s2 + ch;
        cnt := cnt + 1;
      end;
    end else
    begin
      s2 := s2 + ch;
      cnt := 0;
    end;
  end;

  if (StripHTML) and (Length(s2) > 0)  then
  begin
    HTMLRemoveTags(s2);
    HTMLDecode(s2);
  end;

  result := s2;
end;


// ConvertAlphaSpace: converts certain punc chars to space(only allows 1 consecitive space) + removes numbers & rets rest as lower case
Function ConvertAlphaSpace(s: string) : string;
var
i: Integer;
s2, ch: string;
begin
    s := AnsiLowerCase(s);
    s2 := '';
    For i := 1 To Length(s) do
    begin
        ch := copy(s, i, 1);
        if (ch >= 'a') and (ch <= 'z') then
          s2 := s2 + ch
        else
        begin
          case ch of
            ' ', '-', ':', '*', '?', '"', '<', '>', '.', '_', '\', '/', '|' : If StrRight(s2, 1) <> ' ' Then s2 := s2 + ' ';
          end;
        end;
    end;
    result := Trim(s2);
end;

// ConvertAlpha: removes from a string all non alpha chars (inc spaces) and rets rest as lower case
Function ConvertAlpha(s: string) : string;
var
i: Integer;
s2, ch: string;
begin
    s := AnsiLowerCase(s);
    s2 := '';
    For i := 1 To Length(s) do
    begin
      ch := copy(s, i, 1);
      if (ch >= 'a') and (ch <= 'z') then
        s2 := s2 + ch;
    end;
    result := s2;
end;

// ConvertAlphaNum: removes from a string all non alphanum chars (inc spaces) and rets rest as lower case
Function ConvertAlphaNum(s: string) : string;
var
i: Integer;
s2, ch: string;
begin
    s := AnsiLowerCase(s);
    s2 := '';
    For i := 1 To Length(s) do
    begin
      ch := copy(s, i, 1);
      if ((ch >= 'a') and (ch <= 'z')) or ((ch >= '0') and (ch <= '9')) then
        s2 := s2 + ch;
    end;
    result := s2;
end;


//-----------------------------
// LOCATE TEXT FUNCTIONS
//-----------------------------
// accumulates all lines between those containing FindBeg & FindEnd strings (inclusive) offset by OffBeg & OffEnd
// BegFind can = EndFind to get same line if BegOff=0
function PageTextBetween(BegFind: string; BegOff: Integer; EndFind: string; EndOff: Integer; Page: TStringList; LineNr: Integer; StripHTML: Boolean): string;
var
BegPos, EndPos, i: Integer;
Line: string;
begin
  result := '';
  if BegFind = '' then
    BegPos := LineNr // if no beg string go from current pos
  else
    BegPos := FindLine(BegFind, Page, LineNr);// + BegOff;

  if BegPos > -1 then
  begin
    if EndFind = '' then
      EndPos := BegPos
    else
      EndPos := FindLine(EndFind, Page, BegPos);

    if EndPos > -1 then
    begin
      BegPos := BegPos + BegOff;
      EndPos := EndPos + EndOff;
      for i := BegPos to EndPos do
      begin
        Line := Line + Page.GetString(i);
      end;
      Line := Trim(Line);
      if StripHTML then
      begin
        HTMLRemoveTags(Line);
        HTMLDecode(Line);
      end;
      result := Line;
    end;
  end;
end;

// rets text between BegFind & EndFind use BegOff & EndOff to reposition
function LineTextBetween(BegFind: string; BegOff: Integer; EndFind: string; EndOff: Integer; Line: string; StripHTML: Boolean): string;
var
BegPos, EndPos, i: Integer;
begin
  result := '';
  BegPos := pos(BegFind, Line);
  if BegPos = -1 then exit;
  EndPos := ppos(EndFind, Line, BegPos+1);
  if EndPos = -1 then exit;

  BegPos := BegPos + Length(BegFind) + BegOff; //Beg = 1st char after BegFind
  EndPos := EndPos + EndOff; //End = 1st Char off EndFind

  if (BegPos <= EndPos) and (BegPos > 0) and (EndPos < Length(Line)) then
  begin
    Line := copy(Line, BegPos, EndPos-BegPos);
    if StripHTML then
    begin
      HTMLRemoveTags(Line);
      HTMLDecode(Line);
    end;
    result := Line;
  end;
end;


function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
  i, Cnt: Integer;
begin
  result := -1;
  if StartAt < 0 then
    StartAt := 0;
  Cnt := List.Count-1;
  for i := StartAt to Cnt do
    if Pos(Pattern, List.GetString(i)) <> 0 then
    begin
      result := i;
      Break;
    end;
end;


function FindLineNoCase(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
  i: Integer;
begin
  result := -1;
  Pattern :=  AnsiLowerCase(Pattern);
  if StartAt < 0 then
    StartAt := 0;
  for i := StartAt to List.Count-1 do
    if Pos(Pattern, AnsiLowerCase(List.GetString(i))) <> 0 then
    begin
      result := i;
      Break;
    end;
end;


function FindLineAlpha(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
  i: Integer;
begin
  result := -1;
  Pattern :=  ConvertAlpha(Pattern);
  if StartAt < 0 then
    StartAt := 0;
  for i := StartAt to List.Count-1 do
    if Pos(Pattern, ConvertAlpha(List.GetString(i))) <> 0 then
    begin
      result := i;
      Break;
    end;
end;


// do fuzzy search
function FindLineSoundEx(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
  i: Integer;
begin
  result := -1;
  Pattern :=  ConvertSoundEx(Pattern);
  if StartAt < 0 then
    StartAt := 0;
  for i := StartAt to List.Count-1 do
    if SoundExComp(Pattern,List.GetString(i)) then
    begin
      result := i;
      Break;
    end;
end;




//-----------------------------
// SOUNDEX FUNCTIONS
//-----------------------------
Function ConvertSoundEx(sSent: string) : string;
var
Pos1,Pos2,SLen: Integer;
s, wrd: string;
begin
    sSent := ConvertAlphaSpace(sSent);
    //sSent = ValidateChars(sSent) 'replace dodgy chars with spaces
    SLen := Length(sSent);
    Pos1 := 1;
    s := '';
    Repeat
        Pos2 := ppos( ' ', sSent,Pos1); //look for rest of str
        If Pos2 = 0 Then Pos2 := SLen + 1;
        wrd := copy(sSent, Pos1, Pos2 - Pos1);
        s := s + SoundEx(wrd);
        Pos1 := Pos2 + 1;
    Until Pos1 > SLen;
    result := s;
end;

//takes 2 soundex strings looks for soundex string(s) sStr2 in sStr1. does as 4 char comps
Function SoundExIn(sFind, sStr: string) : Boolean;
var SLen, i, MatchCnt: Integer;
begin
    SLen := Length(sFind) DIV 4;
    MatchCnt := 0;
    for i := 0 to SLen-1 do
    begin
        if (pos(copy(sFind, i * 4 + 1, 4), sStr) > 0) Then MatchCnt := MatchCnt + 1;
    end;
    result := ((MatchCnt * 100) DIV SLen) >= 60; //greater than 75% match => match
End;

//takes 2 normal strings and soundex converts. Then compares if str2 is in str1
Function SoundExComp(sFind, sStr : string) : Boolean;
var
  r: boolean;
begin
    r := SoundExIn(ConvertSoundEx(sFind), ConvertSoundEx(sStr));
    result := r
End;

//converts a string into soundex. 4 chars per word
Function SoundEx(sWord: String) : String;
var Num, sChar, sLastCode: string;
    lWordLength, i: Integer;
begin
    sWord := AnsiUpperCase(sWord);
    Num := copy(sWord, 1, 1); // Get the first letter
    sLastCode := GetSoundCodeNumber(Num);
    lWordLength := Length(sWord);

    // Create the code starting at the second letter.
    for i := 2 To lWordLength do
    begin
        sChar := GetSoundCodeNumber(copy(sWord, i, 1));
        
        // If two letters that are the same are next to each other only count one of them
        if (Length(sChar) > 0) And (sLastCode <> sChar) Then
        begin
          Num := Num + sChar;
          sLastCode := sChar;
        end;
    end;

    result := copy(Num + '    ', 1, 4); // Make sure code is exactly 4 chars
end;

//The letters A,E,I,O,U,Y,H,W and other characters are not coded.
function GetSoundCodeNumber(sChar: string) : String;
var
  SC: string;
begin
  SC := '';

// comma seperating this case statement = memory leaks???, hence done like this
  Case sChar of
    'B' : SC := '1';
    'F' : SC := '1';
    'P' : SC := '1';
    'V' : SC := '1';
    'C' : SC := '2';
    'G' : SC := '2';
    'J' : SC := '2';
    'K' : SC := '2';
    'Q' : SC := '2';
    'S' : SC := '2';
    'X' : SC := '2';
    'Z' : SC := '2';
    'D' : SC := '3';
    'T' : SC := '3';
    'L' : SC := '4';
    'N' : SC := '5';
    'M' : SC := '5';
    'R' : SC := '6';
  end;

  result := SC;
end;



//-----------------------------
// FIELD FUNCTIONS
//-----------------------------
// removes dots after 4th dot
function FixTitles(sStr: string): string;
begin
  result := '';	
  if sStr = '' then exit;
  result := nposReplaceString('.', ' ', sStr, 4); // replace '.' with ' ' after 4th '.' change the 4 to ? as required
end;


/// IMDB info has 'actorname (as partname)' this changes that to 'actor1,actor2,actor3'
function FixActors(sStr: string): string;
begin
  result := '';	
  if sStr = '' then exit;
  sStr := posReplaceString(' (', '), ',',', sStr, 1); // replace ' (.....), '
  sStr := posReplaceString(' (', ')','', sStr, 1); // replace '.' with ' ' after 4th '.'
  sStr := posReplaceString('(', '','', sStr, 1); // erase any remaining '('
  sStr := posReplaceString(')', '','', sStr, 1); // erase any remaining ')'
  // sStr := posReplaceString(', ', '',',', sStr, 1); // remove spaces between ,'s
  result :=  sStr;
end;




//-----------------------------
// OTHER FUNCTIONS
//-----------------------------
// rets url for large amazon pic given title. If ShowPicker = true will prompt with choices (if any)
function GetAmazonPicUrl(Title: String; ShowPicker: boolean) : String;
var
  Page: TStringList;
  LineNr, MovieCnt: Integer;
  Line, Address, Match: string;
begin
  result := '';
  MovieCnt := 0;
  Page := TStringList.Create;
  Address := 'http://www.amazon.com/s/ref=nb_ss_gw/103-7540265-9891830?url=search-alias%3Ddvd&field-keywords=' + StringReplace(UrlEncode(Title),'+', '%20');
  Page.Text := GetPage(Address);

  PickTreeClear;
  PickTreeAdd('Amazon matches for "' + Title + '" (' + GetField(fieldSource) + ')', '');
  LineNr := -1;
  repeat
    LineNr := FindLine('<span class="srTitle">', Page, LineNr + 1);
    if LineNr < 0 then Break;
    Line := Page.GetString(LineNr);
    Address := LineTextBetween('"http', -4, '">', 0, Line, False);
    HTMLRemoveTags(Line);
    if (Line <> '') and (Address <> '') then
    begin
      PickTreeAdd(Line, Address);
      if MovieCnt = 0 then Match := Address;
      MovieCnt := MovieCnt + 1;
    end;
  until (false);// or (LineNr > EndLine) or ((AutoFlag >= 3) and (SeCnt > 0));

  if MovieCnt <> 0 then //if no movies to select from may be it has gone straight to only choice so carry on
  begin
    if ShowPicker then
    begin
      if PickTreeExec(Address) = false then exit; //user select from all episodes
    end else
      Address := Match; //set to 1st match

    Page.Text := GetPage(Address); // get main movie page
  end;

// main movie page
  Line := PageTextBetween('registerImage("original_image"', 0, '', 0, Page, 0, False); //get the line
  Address := LineTextBetween('<a href="+''"''+"', 0, '"+''"''+" target="', 0, Line, False);
  if Address = '' then exit;

// movie large image page
  Page.Text := GetPage(Address);
  Line := PageTextBetween('imagePlaceHolder', 1, '', 1, Page, 0, False); //get the line after the 'imageplaceholder' one
  Address := LineTextBetween('<img src="', 0, '.jpg"', 4, Line, False);
  result := Address;
End;



//-----------------------------
// END
//-----------------------------
begin
end.

Posted: 2007-03-22 19:04:43
by antp
Thanks, I will include it with the other scripts, I guess that it can be useful.