Page 1 of 1

Summary in comments field

Posted: 2002-07-30 00:58:21
by lukecs
I like to see users comments when I look for a movie on imdb. So I added this code to the imdb script so that the users comment went in the comment field

Code: Select all

  // Comments
  LineNr := FindLine('Summary:</B>', Page, 0);
  if LineNr > -1 then
  begin
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
      BeginPos := pos('<P>', Line) + 3;
      repeat
         LineNr := LineNr + 1;
         Line := Line + Page.GetString(LineNr);
         EndPos := pos('</P>', Line);
      until EndPos > 0;
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    HTMLDecode(Value);
    SetField(fieldComments, Value);
  end;

Posted: 2002-07-30 09:20:10
by antp
Thanks ;)

I just added this :

Code: Select all

    Value := StringReplace(Value, '<BR>', #13#10);
before the "setField" instruction, since for some movies there are line breaks (e.g. for Matrix)

Posted: 2002-07-30 10:43:44
by lukecs
cool thanks

Just some additional questions
-whats with #13#10?
-Where does the function HTMLDecode come from?

Posted: 2002-07-30 11:47:32
by antp
HTMLDecode remplace things like "é" by "é", etc...
#13#10 is a linebreak. Under Windows the linebreaks are stored on two bytes, that have the ASCII values 13 and 10 (the 32 first ASCII values are special things, non-printable characters. From 32 to 255 they are the standard characters and symbols).

Posted: 2002-07-30 11:48:06
by lukecs
I found that the script returned nothing if the one line summary was longer than one line. Here is the script again with both corrections

Code: Select all

  // Comments
  LineNr := FindLine('Summary:</B>', Page, 0);
  if LineNr > -1 then
  begin
      BeginPos := 0;
      repeat
         LineNr := LineNr + 1;
         Line := Page.GetString(LineNr);
         BeginPos := pos('<P>', Line);
      until BeginPos > 0;
      BeginPos := BeginPos + 3;
      repeat
         LineNr := LineNr + 1;
         Line := Line + Page.GetString(LineNr);
         EndPos := pos('</P>', Line);
      until EndPos > 0;
    HTMLDecode(Value);
    Value := copy(Line, BeginPos, EndPos - BeginPos);
    Value := StringReplace(Value, '<BR>', #13#10);
    SetField(fieldComments, Value);
  end;

Posted: 2002-07-30 12:13:16
by antp
Thanks

But the HTMLDecode has to be done before the Value := copy... since if you do it before it will do nothing (value is empty)