
//Some useful constants
const
 //Script types
 stMovies = 0;
 stPeople = 1; 
 stPoster = 2;
  
 //Script modes
 smSearch = 0; 
 smNormal = 1;
 //Custom modes 
 smDetail = 2; 
 smLinks  = 3; 
 smImage  = 4;
 smFinished = 5;
  
 //Parse results
 prError     = 0; 
 prFinished  = 1;
 prList      = 2;
 prListImage = 3;
 prDownload  = 4;
  
 //Movie fields
 mfURL         = 0;
 mfTitle       = 1;
 mfOrigTitle   = 2;
 mfAka         = 3;
 mfYear        = 4;
 mfGenre       = 5;
 mfCategory    = 6;
 mfCountry     = 7;
 mfStudio      = 8;
 mfMPAA        = 9;
 mfRating      = 10;
 mfTags        = 11;
 mfTagline     = 12;
 mfDescription = 13;
 mfDuration    = 14;
 mfFeatures    = 15;
  
 //People fields
 pfURL        = 0;
 pfName       = 1;
 pfTransName  = 2;
 pfAltNames   = 3;
 pfBirthday   = 4;
 pfBirthplace = 5;
 pfGenre      = 6;
 pfBio        = 7;
 pfDeathDate  = 8;
  
 //Credits types
 ctActors    = 0;
 ctDirectors = 1;
 ctWriters   = 2;
 ctComposers = 3;
 ctProducers = 4;
 
  
  
 //Script data 
 SCRIPT_VERSION = '0.1.0.3'; 
 SCRIPT_NAME    = 'Zelluloid [DE]';
 SCRIPT_DESC    = '[DE] hole Film-Information von Zelluloid.de';
 SCRIPT_LANG    = $07; //German
 SCRIPT_TYPE    = stMovies;
 
 BASE_URL    = 'http://www.zelluloid.de';
 RATING_NAME = 'ZELLU';
 
 SEARCH_STR  = 'http://www.zelluloid.de/suche/index.php3?qstring=%s';
 
 CODE_PAGE   = 0; //Use 0 for Autodetect 

 //OPTIONS
 DOWNLOAD_DETAIL = True;//Set to False if you do not want Persons being parsed from zelluloid.de 
 DOWNLOAD_LINKS  = True;//Set to False if you do not want Links being parsed from zelluloid.de
 DOWNLOAD_IMAGES = False;//nomatter not supported yet
 PERFORM_CUSTOMFIELDS = True;//Set to False if you do not want custom-fields being filled                             //requiered fields are: FSK, Budget, ID IMDb, ID Zelluloid 
 ADD_OFFICIAL_URLS = False;
 IMAGE_COUNT     = 3; // max = 8  not supported yet
 
 //coustom field names      setup here the names for requierd custom-fields
 cf_FSK     = 'FSK';
 cf_BUDGET  = 'Budget';
 cf_idIMDB  = 'ID IMDb';
 cf_idZELLU = 'ID Zelluloid';
 
 
//Global variables 
var
 ELI, PLI : Integer;
 Mode : Byte;
 ExtraLinks : array [smDetail..smImage] of WideString;
 PictureLinks : array [0..IMAGE_COUNT] of WideString;  // not supported yet
 zelluID : String;
 havePics : Boolean;
 
//Functions 
function GetScriptVersion : WideString;
begin
 Result := SCRIPT_VERSION;
end; 
 
function GetScriptName : WideString;
begin
 Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : WideString;
begin
 Result := SCRIPT_DESC;
end;

function GetRatingName : WideString;
begin
 Result := RATING_NAME;
end;

function GetScriptLang: Cardinal;
begin
 Result := SCRIPT_LANG;
end;

function GetCodePage : Cardinal;
begin
 Result := CODE_PAGE;
end;

function GetBaseURL : String;
begin
 Result := BASE_URL;
end;



function NextMode(curMode : Integer) : Integer;
var
 I : Integer;
begin
 Result := smFinished;
 
 if curMode < Low(ExtraLinks) - 1 then
  curMode := Low(ExtraLinks) - 1;

 for I := curMode + 1 to High(ExtraLinks) do
  if ExtraLinks[I] <> '' then begin
   Result := I;
   Break;
  end;
end;


function GetDownloadURL : String;
begin
 if (Mode = smSearch) then
  Result := SEARCH_STR
 else
  Result := ExtraLinks[Mode]; 
end;

function GetScriptType : Byte; 
begin
 Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte; 
begin
 Result := Mode;
end;

procedure ParseGenres(HTML, startstr, endstr : WideString);
var
 P : Integer;
begin
 P := 1;
 //Genre
 AddFieldValue(mfGenre, HTMLValues2(HTML, startSTR, endstr,
			                 'az.php3?g=', '</A>',
			                  ', ', P) );
end;

procedure ParseCountries(HTML, startstr, endstr : WideString);
var
 P : Integer;
begin
 P := 1;
 //Country
 AddFieldValue(mfCountry, HTMLValues2(HTML, startSTR, endstr,
			                 'az.php3?l=', '</A>',
			                  ', ', P) );
end;

procedure ParseOurLinks(MovieURL : WideString; HTML : WideString);
var
 curPos, startPos, lastPos,  P : Integer;
   
begin
	P := 0;
	startPos := Pos('<DIV CLASS=smallDark', HTML);
  lastPos  := PosFrom('schreiben</A>', HTML, startPos);  
      
 //DETAILs
 if DOWNLOAD_DETAIL then begin
  curPos := PosFrom('details.php3?id='+zelluID, HTML, startPos);
  if curPos > 0 then begin
   ExtraLinks[smDetail] := 'http://www.zelluloid.de/filme/details.php3?id=' + zelluID;
  end;
 end;
 
 //Links
 if DOWNLOAD_LINKS then begin
  curPos := PosFrom('links.php3?id='+zelluID, HTML, startPos);
  if curPos > 0 then begin
   ExtraLinks[smLinks] := 'http://www.zelluloid.de/filme/links.php3?id=' + zelluID;
  end;
 end;
  
 //IMAGES
 if DOWNLOAD_IMAGES then begin
  curPos := PosFrom('bilder.php3?id='+zelluID, HTML, startPos);
  if curPos > 0 then begin
   ExtraLinks[smImage] := 'http://www.zelluloid.de/filme/bilder.php3?id=' + zelluID;
  end;
 end;
  
end;
procedure ParseMovie(MovieURL : WideString; HTML : WideString);
var
 curPos, EndPos, nextPos, startPos, lastPos,  P : Integer;
 tmp, tmpstring, startSTR : WideString;
  
begin
	P := 0;	
  tmpstring  := '';	
  tmp        := '';    
  AddFieldValue(mfURL, Trim(MovieURL) );
  
  zelluID := StringReplace(MovieURL, 'http://www.zelluloid.de/filme/index.php3?id=', '',false,false,false);
    
  ParseOurLinks(MovieURL, HTML);
 
 //Title 	
 curPos := Pos('<title>', HTML)+ Length('<title>');	
 EndPos := PosFrom('|', HTML, curPos);
 tmpstring  := Trim( Copy(HTML, curPos, EndPos - curPos) );
 if Length(tmpstring) > 0 then begin
   AddFieldValue(mfTitle, RemoveTags(tmpstring, false) );
 end;
 
 tmpstring  := ''; 
 startSTR := 'SRC="/gfx/headers/dyn_bottom.gif"';
 startPos := Pos(startSTR, HTML);
 nextPos  := PosFrom('<TABLE', HTML, startPos);
 lastPos  := PosFrom('</TABLE>', HTML, startPos);
 
 curPos := 0;	
//original Title
curPos := Pos('Originaltitel:', HTML)+ Length('Originaltitel:');
if curPos > Length('Originaltitel:') then begin
	EndPos := PosFrom('<BR>',HTML, curPos);
	tmpstring := Trim( Copy(HTML, curPos, EndPos - curPos) );
	AddFieldValue(mfOrigTitle, tmpstring );
end;
 
 //Country
 ParseCountries(HTML, startstr, 'Übersicht');
  		                   						 
 //Genre
 ParseGenres(HTML, startstr, 'Übersicht');
	
 
 tmpstring  := '';
 //Year
 curPos := PosFrom('az.php3?j=', HTML, startPos)+ Length('az.php3?j=');
 EndPos := PosFrom('</A>', HTML, curPos);	
 curPos := EndPos-4;
 tmpstring  := Trim( Copy(HTML, curPos, EndPos - curPos) ); 
 if length(tmpstring) > 0  then begin
 	AddFieldValue(mfYear, RemoveTags(tmpstring, false)  );
 end;
 if PERFORM_CUSTOMFIELDS  then begin
 	 
   AddCustomFieldValueByName(cf_idZELLU, zelluID);
    
   tmpstring  := '';
   tmp        := '';
   curPos := 0;
   P := 1;
   //FSK
   curPos := PosFrom('FSK: ', HTML, startPos)+ Length('FSK: ');
   if curPos > Length('FSK: ') then begin
     EndPos := curPos + 5;
     tmpstring  := Trim( Copy(HTML, curPos, EndPos - curPos) );
     if length(tmpstring) > 0  then begin
     	if PosFrom('ohne', tmpstring, P) > 0 then begin
     	   tmp := 'ohne'     	
     	end;  
     	if PosFrom('ab 6', tmpstring, P) > 0 then begin
     	  tmp := 'ab 6'
     	end;
     	if PosFrom('ab 12', tmpstring, P) > 0 then begin
     	  tmp := 'ab 12'
     	end;
     	if PosFrom('ab 16', tmpstring, P) > 0 then begin
     	  tmp := 'ab 16'
     	end;
     	if PosFrom('ab 18', tmpstring, P) > 0 then begin
     	  tmp := 'ab 18'
     	end;  
     	  
   	  AddCustomFieldValueByName(cf_FSK, RemoveTags(tmp, false) );
     end;
   end;
   
   tmpstring  := '';
   //Budget
   curPos := PosFrom('$', HTML, startPos);
   EndPos := PosFrom(' Budget', HTML, curPos);
   tmpstring  := Trim( Copy(HTML, curPos, EndPos - curPos) ); 
   if length(tmpstring) > 0  then begin
     AddCustomFieldValueByName(cf_BUDGET, RemoveTags(tmpstring, false) );
   end;
 end;
 
 tmpstring  := '';
 //Duration
 curPos := PosFrom('ca.&nbsp;', HTML, startPos)+ Length('ca.&nbsp;');
 EndPos := PosFrom('&nbsp;min', HTML, curPos);
 tmpstring  := Trim( Copy(HTML, curPos, EndPos - curPos) ); 
 if length(tmpstring) > 0  then begin
 	tmpstring  := RemoveTags(tmpstring, false);
 	tmpstring  := IntToStr( StrToInt(tmpstring) );
 	AddFieldValue(mfDuration,  tmpstring);
 end;
 
 tmpstring  := '';
 //Rating
 startPos := Pos('User-Wertung:', HTML);
 if startPos > 0 then begin
 	  curPos := PosFrom('<TR><TD WIDTH=', HTML, startPos)+ Length('<TR><TD WIDTH=');
 	  if curPos > 0 then begin	
     EndPos := PosFrom('>', HTML, curPos);
     tmpstring  := Trim(HTMLToText(Copy(HTML, curPos, EndPos - curPos)));
     P := Pos('.', tmpstring);
     if P > 0 then begin
     	tmpstring  := Copy(tmpstring, 0, P);
     end;
     tmpstring  := FloatToStr(StrToFloat(tmpstring)/10);
    end;    
 end;  
 if length(tmpstring) > 0  then begin
 	AddFieldValue(mfRating, tmpstring);
 end;
 
 tmpstring  := ''; 
 //Description
 startPos := Pos('<DIV CLASS=bigtext>', HTML);
 curPos := startPos;
 tmpstring := TextBetween(HTML, '<DIV CLASS=bigtext>', '</DIV>', true ,startPos);  
 if length(tmpstring) > 0  then begin
 	AddFieldValue(mfDescription, tmpstring);    	    
 end;
 
 tmpstring  := ''; 
   
  
end;

procedure ParseDetail(MovieURL : WideString; HTML : WideString);
var
 curPos, EndPos, urlPos, urlEndPos, startPos, itemStart, itemEnd, actorPos, crewPos, studioPos, distributionPos, lastPos,  P : Integer;
 Person, Role, Job, Studio, URL, cell1, cell2, cell3 : WideString;
  
begin
	
	P := 0;
	startPos := Pos('<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=10 BORDER=0 HEIGHT=300 BGCOLOR="#444444">', HTML);
  Job := '';
  Studio := '';
  if startPos < 1 then
   Exit;
  cell1 := '<td align="right">'; 
  cell2 := '<td>';  
  cell3 := '<tr><td align="center" colspan="2">'; 
  actorPos   := PosFrom('alt="Besetzung"', HTML, startPos);
  crewPos    := PosFrom('alt="Crew"', HTML, startPos); 
  studioPos  := PosFrom('alt="Produktion"', HTML, startPos); 
  distributionPos  := PosFrom('alt="Verleih"', HTML, startPos);
  lastPos  := PosFrom('</TABLE>', HTML, startPos);
  P := 0;
  // Actors
  if (actorPos > 0) AND (crewPos > 0) then begin   
   	 curPos := PosFrom(cell1, HTML, actorPos)+ Length(cell1);   
   	 EndPos := PosFrom('</tr>', HTML, actorPos);
   	 while (curPos > 0) AND (curPos < crewPos) do begin
           Role := Trim( RemoveTags( Copy(HTML, curPos, EndPos - curPos), false ) );
   	 curPos := PosFrom(cell2, HTML, EndPos)+ Length(cell2);
   	 EndPos := PosFrom('</A>', HTML, curPos);
   	 urlPos := PosFrom('/person/index.php3?id=', HTML, curPos);
   	 urlEndPos := PosFrom('"', HTML, urlPos);
   	 URL := BASE_URL +  Copy(HTML, urlPos, urlEndPos - urlPos);   
	 curPos := PosFrom('>', HTML, urlEndPos)+ Length('>');
	 EndPos := PosFrom('</A>', HTML, curPos);
           Person := Trim( RemoveTags( Copy(HTML, curPos, EndPos - curPos), false ) );             
      AddMoviePerson(Person, '', Role, URL, ctActors);        
   	 curPos := PosFrom(cell1, HTML, EndPos)+ Length(cell1);
     end;    	    
  end;
  
  //Directors
  Job := 'Regisseur';
  itemStart := PosFrom(cell1+'Regie', HTML, crewPos);
  if itemStart > 0 then begin
    itemEnd := PosFrom('</TR>', HTML, itemStart);
    curPos := PosFrom('/person/index.php3?id=', HTML, itemStart);
    while (curPos > 0) AND (curPos < itemEnd) do begin    
   	 urlEndPos := PosFrom('"', HTML, curPos);	
   	 URL := BASE_URL +  Copy(HTML, curPos, urlEndPos - curPos);
   	 curPos := PosFrom('>', HTML, urlEndPos)+ Length('>');
   	 EndPos := PosFrom('</A>', HTML, curPos);
     Person := Trim( RemoveTags( Copy(HTML, curPos, EndPos - curPos), false ) );
     AddMoviePerson(Person, '', Job, URL, ctDirectors);     
     curPos := PosFrom('/person/index.php3?id=', HTML, EndPos);   	 
    end;    
  end;
  
  //Producers
  Job := 'Produzent';
  itemStart := PosFrom(cell1+'Produktion', HTML, crewPos);
  if itemStart > 0 then begin
    itemEnd := PosFrom('</TR>', HTML, itemStart);
    curPos := PosFrom('/person/index.php3?id=', HTML, itemStart);
    while (curPos > 0) AND (curPos < itemEnd) do begin    
   	 urlEndPos := PosFrom('"', HTML, curPos);	
   	 URL := BASE_URL +  Copy(HTML, curPos, urlEndPos - curPos);
   	 curPos := PosFrom('>', HTML, urlEndPos)+ Length('>');
   	 EndPos := PosFrom('</A>', HTML, curPos);
     Person := Trim( RemoveTags( Copy(HTML, curPos, EndPos - curPos), false ) );
     AddMoviePerson(Person, '', Job, URL, ctProducers);     
     curPos := PosFrom('/person/index.php3?id=', HTML, EndPos);   	 
    end;    
  end;
  
  //Composers
  Job := 'Film-Komponist';
  itemStart := PosFrom(cell1+'Musik', HTML, crewPos);
  if itemStart > 0 then begin
    itemEnd := PosFrom('</TR>', HTML, itemStart);
    curPos := PosFrom('/person/index.php3?id=', HTML, itemStart);
    while (curPos > 0) AND (curPos < itemEnd) do begin    
   	 urlEndPos := PosFrom('"', HTML, curPos);	
   	 URL := BASE_URL +  Copy(HTML, curPos, urlEndPos - curPos);
   	 curPos := PosFrom('>', HTML, urlEndPos)+ Length('>');
   	 EndPos := PosFrom('</A>', HTML, curPos);
     Person := Trim( RemoveTags( Copy(HTML, curPos, EndPos - curPos), false ) );
     AddMoviePerson(Person, '', Job, URL, ctComposers);     
     curPos := PosFrom('/person/index.php3?id=', HTML, EndPos);   	 
    end;    
  end;
  
  //Writers
  Job := 'Drehbuch-Autor';
  itemStart := PosFrom(cell1+'Drehbuch', HTML, crewPos);
  if itemStart > 0 then begin
    itemEnd := PosFrom('</TR>', HTML, itemStart);
    curPos := PosFrom('/person/index.php3?id=', HTML, itemStart);
    while (curPos > 0) AND (curPos < itemEnd) do begin    
   	 urlEndPos := PosFrom('"', HTML, curPos);	
   	 URL := BASE_URL +  Copy(HTML, curPos, urlEndPos - curPos);
   	 curPos := PosFrom('>', HTML, urlEndPos)+ Length('>');
   	 EndPos := PosFrom('</A>', HTML, curPos);
     Person := Trim( RemoveTags( Copy(HTML, curPos, EndPos - curPos), false ) );
     AddMoviePerson(Person, '', Job, URL, ctWriters);     
     curPos := PosFrom('/person/index.php3?id=', HTML, EndPos);   	 
    end;    
  end;
  
  //Studios  
  itemStart := PosFrom(cell3, HTML, studioPos);
  if (itemStart > 0) AND (itemStart < distributionPos) then begin
  	curPos := itemStart + Length(cell3);
    while (curPos > 0) AND (curPos < distributionPos) do begin
   	 EndPos := PosFrom('</TD></TR>', HTML, curPos);
     Studio := Trim( RemoveTags( Copy(HTML, curPos, EndPos - curPos), false ) );
     AddFieldValue(mfStudio, Studio);     
     curPos := PosFrom(cell3, HTML, EndPos) + Length(cell3);   	 
    end;  	 
  end;
  // distributors and other jobs are curently not suported by PVD
end;

procedure ParseLinks(MovieURL : WideString; HTML : WideString);
var
 curPos, EndPos, urlPos, startPos, lastPos : Integer;
 tmpstring, IMDbID, IMDbPage : WideString;
  
begin
 tmpstring :=''; 
 startPos := Pos('</A></DIV></TD></TR></TABLE></TD></TR></TABLE></TD></TR>', HTML);
 lastPos := Pos('<A HREF="/addlink.php3?t=m&id=', HTML);
 curPos := PosFrom('<TABLE', HTML, startPos);
 EndPos := PosFrom('>', HTML, curPos) + 1;
 curPos := EndPos;
 
 // IMDB LINK
 urlPos := PosFrom('<A HREF="http://german.imdb.com/title/tt', HTML, curPos);
 if urlPos > 0 then begin
 	 urlPos := urlPos + Length ('<A HREF="http://german.imdb.com/title/tt');
 	 EndPos := PosFrom('"', HTML, urlPos);
 	 tmpstring  := Trim(Copy(HTML, urlPos, EndPos - urlPos)); 	 
 	 IMDbID := StringReplace(tmpstring, '/', '', true,false,false);
 end; 
 // or alternate IMDB LINK
 urlPos := PosFrom('<A HREF="http://german.imdb.com/Title?', HTML, curPos);
 if urlPos > 0 then begin
 	 urlPos := urlPos + Length ('<A HREF="http://german.imdb.com/Title?');
 	 EndPos := PosFrom('"', HTML, urlPos);
 	 tmpstring := Trim(Copy(HTML, urlPos, EndPos - urlPos));
 	 IMDbID := StringReplace(tmpstring, '/', '', true,false,false);
 end;  
 if ( Length (IMDbID) > 3 ) AND (Length (IMDbID) < 10 ) then begin 	 	
 	if PERFORM_CUSTOMFIELDS  then begin
 		AddCustomFieldValueByName(cf_idIMDB, IMDbID );
 	end;
 	IMDbPage := 'http://www.imdb.com/title/tt' + IMDbID;
 	AddFieldValue(mfURL, Trim(IMDbPage) );	
 end;
  	 
 if ADD_OFFICIAL_URLS then begin
    urlPos := PosFrom('<B>Offizielle Seite', HTML, curPos);
    if urlPos > 0 then begin
      while (urlPos > 0) AND (urlPos < lastPos) do begin
      	  urlPos := PosFrom('</B></DIV><DIV CLASS=smallBlur>', HTML, urlPos) + Length ('</B></DIV><DIV CLASS=smallBlur>');
      	  EndPos := PosFrom('</DIV>', HTML, urlPos);
      	  tmpstring := Trim(Copy(HTML, urlPos, EndPos - urlPos));
      	  if Length(tmpstring) > 0 then begin
      	  	AddFieldValue(mfURL, 'http://' + RemoveTags(tmpstring, false) );
      	  end;
      	  urlPos := PosFrom('<B>Offizielle Seite', HTML, EndPos);	
      end;
    end;
 end;
 
end;

procedure ParseImages(MovieURL : WideString; HTML : WideString);
var
 curPos : Integer;  
begin
 havePics := false;
 curPos := 0;
 // currently there is no way to add scene-images 
end;

procedure ParseSearchResults(HTML : WideString);
var
 // obi 11.08.09: add xeoPos
 curPos, iconPos, EndPos,  nextPos, isPos, xeoPos : Integer;
 tmpstring, tmpstringa, Title, Year, URL, strID, orgTitle : WideString;
begin
 curPos := Pos('<B>Der Suchbegriff erzielte', HTML);
 if curPos < 1 then
  Exit;
       
 EndPos := PosFrom('</TD></TR>', HTML, curPos);  
 iconPos := PosFrom('icoMovie.gif', HTML, curPos);
 nextPos := PosFrom('</TR>', HTML, iconPos);
 curPos := PosFrom('hit.php3?hit=', HTML, iconPos);
 xeoPos := PosFrom('CLASS=normLight>', HTML, curPos);
  
 while iconPos > 0 do begin
   isPos := PosFrom('movie-', HTML, curPos)+6;
   EndPos := PosFrom('-', HTML, isPos);
   strID := Copy(HTML, isPos, EndPos - isPos);
   URL := BASE_URL + '/filme/index.php3?id=' + strID;   
   curPos := PosFrom('>', HTML, EndPos)+ Length('>');
   EndPos := PosFrom('</NOBR>', HTML, curPos);
   isPos := PosFrom('STYLE="color:#AAAAAA;">', HTML, curPos)+23;
   tmpstring := Copy(HTML, curPos, EndPos - curPos) +'</NOBR>';
   EndPos := PosFrom('</TR>', HTML, curPos);
   tmpstringa := Copy(HTML, isPos, EndPos - isPos);
     if ( isPos > curPos) AND (isPos < EndPos) then
      Title := Trim ( RemoveTags(tmpstring, false) )+ ' Orig: ' +Trim ( RemoveTags(tmpstringa, false) );
     if ( isPos < curPos) OR (isPos > EndPos) then
      Title := Trim ( RemoveTags(tmpstring, false) );
   AddSearchResult(Title, orgTitle, Year, URL, '');    
   iconPos := PosFrom('icoMovie.gif', HTML, nextPos);
   nextPos := PosFrom('</TR>', HTML, iconPos);
   curPos := PosFrom('hit.php3?hit=', HTML, iconPos);  
 end;
end;
  
function ParsePage(HTML : WideString; URL : String) : Cardinal;

begin
 if Pos('<title>Suche nach', HTML) > 0 then begin
  ParseSearchResults(HTML);
  // obi 11.08.09: change prLt to prList
  Result := prList; 
  Exit;
 end else
 if Pos('<B>Zu diesem Suchbegriff wurde leider nichts gefunden.</B>', HTML) > 0 then begin
  Result := prError;
  Exit;
 end else 
 if Pos('User-Wertung:', HTML) > 0 then
  ParseMovie(URL, HTML)   
 else
 if Pos('alt="Besetzung"', HTML) > 0 then
  ParseDetail(URL, HTML)
 else
 if Pos(': Links  | zelluloid.de</title>', HTML) > 0 then //addlink.php3?t=m&id=
  ParseLinks(URL, HTML)
 else
 if (Pos('pic="/images/szenen/', HTML) > 0) AND (Pos('rel="lightbox[filmbilder]"', HTML) > 0) then
  ParseImages(URL, HTML)
 else 
 if Pos('<title>zelluloid.de - Das Kinoportal (Kinomagazin', HTML) > 0 then begin 
  Mode := Mode + 1;
 end;

 Mode := NextMode(Mode); 
 // obi 11.08.09: change smFinhed to smFinished	
 if Mode <> smFinished then
  Result := prDownload
 else
  // obi 11.08.09: change prFinhed to prFinished	
  Result := prFinished;     
end;

begin
 Mode := smSearch;

 for ELI := Low(ExtraLinks) to High(ExtraLinks) do
  ExtraLinks[ELI] := '';
 for PLI := Low(PictureLinks) to High(PictureLinks) do //not supported yet
  PictureLinks[PLI] := '';                               
end.