Page 1 of 1

How modify latest imdb script to import only first 5 actors

Posted: 2005-02-02 23:17:01
by Mguel
Besides from importing the complete list, I used to import the 5 first actors to the producer field for sumarized html export.

As the latest imdb script changed quite a lot, I haven't been able to make it work, I have tested lot's of combinations trying to use repeat - until and so, but I haven't find a solution (I'm not a programmer)

This is what I have till now, that makes import the complete actor list comma separated (Using the part of the code for: 0=Only actor names, separated by commas). But need to limit this to only the first five actors...

Code: Select all

  if CanSetField(fieldActors) then
  begin
    Value := TextBetween(PageText, 'ast overview', '</div>');
    if Value = '' then
      Value := TextBetween(PageText, 'redited cast', '</div>');
    if Value <> '' then
    begin
      Value := TextAfter(Value, '</tr> ');
      FullValue := '';
          while Pos('<tr>', Value) > 0 do
          begin
            Value2 := TextBetween(Value, '<tr>', '</tr>');
            Value := RemainingText;
            if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
              Break;
            if FullValue <> '' then
              FullValue := FullValue + ', ';
            FullValue := FullValue + TextBefore(Value2, '</td>', '');
          end;
      end;
      HTMLRemoveTags(FullValue);
      HTMLDecode(FullValue);
      SetField(fieldProducer, FullValue);
  end;

I used to use this code for that (with old script):

Code: Select all

 // Actors (short list) 
 LineNr := FindLine('ast overview', Page, 0);
 if LineNr = -1 then
  LineNr := FindLine('redited cast', Page, 0);
 if LineNr > -1 then
 begin
  FullValue := '';
  Line := Page.GetString(LineNr);
  nActors := 0;
  repeat
   BeginPos := Pos('<td valign="top">', Line);
   if BeginPos > 0 then
   begin
    Delete(Line, 1, BeginPos);
    Line := copy(Line, 25, Length(Line));
    BeginPos := pos('">', Line) + 2;
    EndPos := pos('</a>', Line);
    if EndPos = 0 then
     EndPos := Pos('</td>', Line);
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    if (Value <> '(more)') and (Value <> '') then
    begin
     if FullValue <> '' then
      FullValue := FullValue + ', ';
     FullValue := FullValue + Value;
     nActors := nActors + 1;
    end;
    EndPos := Pos('</td></tr>', Line);
    Delete(Line, 1, EndPos);
   end else
   begin
    Line := '';
   end;
  until (Line = '') or (nActors >= 5);
  HTMLDecode(FullValue);
  SetField(fieldProducer, FullValue);
 end;
Thanks in advance,
Mguel

Posted: 2005-02-03 09:04:00
by antp
Add a variable called ActorCount initialized to 0 before the "case" containings all the while's
Then modify the while :

Code: Select all

          while Pos('<tr>', Value) > 0 do
          begin
             ActorCount := ActorCount + 1;
             if ActorCount > 5 then
               Break;
             [etc...]

Posted: 2005-02-04 21:07:59
by Mguel
Great! thanks a lot...

So the final result in case someone else finds it usefull (remember this uses the Producer field for the five first actors of the movie):

Code: Select all

procedure AnalyzeMoviePage(PageText: string);
var
  Value, Value2, Value3, FullValue: string;		
  ActorCount: integer;                              // to add the new ActorCount variable
...

Code: Select all

  // 5 first actors in producer field (comma separated)
  if CanSetField(fieldActors) then
  begin
    Value := TextBetween(PageText, 'ast overview', '</div>');
    if Value = '' then
      Value := TextBetween(PageText, 'redited cast', '</div>');
    if Value <> '' then
    begin
      ActorCount := 0;
      Value := TextAfter(Value, '</tr> ');
      FullValue := '';
          while Pos('<tr>', Value) > 0 do
          begin
             ActorCount := ActorCount + 1;
             if ActorCount > 5 then
               Break; 
            Value2 := TextBetween(Value, '<tr>', '</tr>');
            Value := RemainingText;
            if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
              Break;
            if FullValue <> '' then
              FullValue := FullValue + ', ';
            FullValue := FullValue + TextBefore(Value2, '</td>', '');
          end;
      end;
      HTMLRemoveTags(FullValue);
      HTMLDecode(FullValue);
      SetField(fieldProducer, FullValue);
  end;
Cheers,
Mguel