OFDB Script Fix

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
DarkS
Posts: 9
Joined: 2004-10-15 23:47:24

OFDB Script Fix

Post by DarkS »

Hi

Here is the fixed version 1.0.4 of the OFDB script. It fixes following bugs.

- Parse correct movie address (with no onmouseover part)
- Import description fix. I've described this problem here already, but since the script wasn't updated yet I've included this fix in the new version.

Code: Select all

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

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

[Infos]
Authors=Fabian Filipczyk / fixed 20061222 bad4u / fixed 20070311 yeti
Title=OFDb
Description=Online-Filmdatenbank (OFDb) import with small picture (DE)
Site=http://www.ofdb.de
Language=DE
Version=1.0.4
Requires=3.5.0
Comments=
License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
GetInfo=1

[Options]
ReformatDescription=1|1|0=Do not reformat. Add the description as on OFDB|1=Reformat the description. Remove all Linefeeds and make a long flow text.

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

(***************************************************
1.0.4 (02/12/2007) by DarkS
- Fix: Parse correct URL for movie address (with no onmouseover part)
- Fix: if the movie description on the first ofdb page has no [mehr]-Link, the
  script adds an empty string only

1.0.3 (06/11/2007) by yeti (yeti@gmx.info)
- Fix: if the actors list on the first ofdb page have no [mehr]-Link, the
  script adds an empty string only (thx DarkS)

1.0.2 (03/06/2007) by yeti (yeti@gmx.info)
- Chg: Code cleanup
- New: Option to import the description as is, include all line feeds.
  Standard is reformat as before.
- Fix: The last change in actors loading from the cast/crew details page
  reads the crew names too :( Hope I've finally fixed this now.

1.0.1 (03/04/2007) by yeti (yeti@gmx.info)
- Chg: Added stringUtils1-Lib and removed FindLine(), Code cleanup (not completed yet)
- Fix: If the actor-name in the details view is clickable to view the actors
  profile, the name was not imported.

1.0.0 (03/03/2007) by yeti (yeti@gmx.info)
- Fix/Chg: Ratingimport changed to 2 digits (rounded)
  Rating 6.49 -> Old: 7 -> New: 6.5
- Chg: Removed old code
- New: Version number 1.0.0 added for better distinction between versions
***************************************************)


program OFDB_DE;

uses
  stringUtils1;

const
  CRLF = #13#10;

var
  MovieName: string;


procedure AnalyzePage(Address: string);
var
  Page: TStringList;
  LineNr: Integer;

begin
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  if pos('<title>OFDb - Suchergebnis', Page.Text) = 0 then
  begin
    SetField(fieldURL, Address);
    AnalyzeMoviePage(Page)
  end else
  begin
    PickTreeClear;
    LineNr := FindLine('<b>Titel:</b>', Page, 0);
    if LineNr > 0 then
    begin
      PickTreeAdd('Filme :', '');
      AddMoviesTitles(Page, LineNr);
      if PickTreeExec(Address) then
         AnalyzePage(Address);
    end;
  end;
  Page.Free;
end;


procedure AnalyzeMoviePage(Page: TStringList);
var
  Line, Temp, Value: string;
  LineNr, LineNrTmp, IntValue: Integer;
  BeginPos, EndPos: Integer;

begin
  // Picture
  LineNr := FindLine('images/film/', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    Value := TextBetween(Line, '<img src="', '" alt=');
    if Value <> '' then
    begin
      Temp := 'http://www.ofdb.de/' + Value;
      GetPicture(Temp);
    end;
  end;
  
  // Original Title
  LineNr := Findline('Originaltitel:', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr + 2);
    HTMLRemoveTags(Line);
    Line := Trim(Line);
    if Line <> '' then SetField(fieldOriginalTitle, Line);
  end;

  // Translated Title
  LineNr := Findline('sans-serif" size="3"><b>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    HTMLRemoveTags(Line);
    Line := Trim(Line);
    if Line <> '' then SetField(fieldTranslatedTitle,Line);  
  end;
  
  // Country
  LineNr := Findline('Herstellungsland:', Page, 0);
  if LineNr > -1 then
  begin
    LineNr := LineNr + 3;
    Line:= Page.GetString(LineNr);
    Delete(Line, 1, Pos('<a', Line) - 1);
    Line := StringReplace(Line, '<br><a', ', <br><a');
    HTMLRemoveTags(Line);
    SetField(fieldCountry, Line);
  end;
  
  // Year
  LineNr := Findline('Erscheinungsjahr:', Page, 0);
  if LineNr > -1 then
  begin
    LineNr := LineNr + 3;
    Line:= Page.GetString(LineNr);
    Delete(Line, 1, Pos('<a', Line) - 1);
    Value := TextBetween(Line, '">', '</a></b>');
    if Value <> '' then SetField(fieldYear, Value); 
  end;    
  
  // Category
  LineNr := Findline('Genre(s):', Page, 0);
  if LineNr > -1 then
  begin
    Value:= '';
    LineNr := LineNr + 2;
    Line:= Page.GetString(LineNr);
    repeat
      Line := TextAfter(Line, '<a');
      Temp := TextBetween(Line, '">', '</a><br>');
      if Temp <> '' then Value := Value + ', ' + Temp ;
    until (Temp = '');
    
    Value:= Copy(Value, 3, Length(Value) - 1);
    SetField(fieldCategory, Value);
  end;
    
  // Actors
  LineNr := Findline('Darsteller', Page, 0);
  if LineNr > -1 then
  begin
     LineNr := LineNr + 3;
     Line:= Page.GetString(LineNr);
     Delete(Line, 1, Pos('<a', Line) - 1);

     if Pos('">[mehr]', Line) > 0 then
     begin
       BeginPos := Pos('<a href="view.php?page=film_detail', Line) + 9;
       EndPos := Pos('">[mehr]', Line);
       Value := Copy(Line, BeginPos, EndPos - BeginPos);
       GetOFDBActors(Value);
     end else
     begin
       Line := StringReplace(Line, '<br><a', ', <br><a');
       HTMLRemoveTags(Line);
       SetField(fieldActors, Line);
     end;
  end;

  // Director
  LineNr := Findline('Regie', Page, 0);
  if LineNr > -1 then
  begin
    Value := '';
    LineNr := LineNr + 3;
    Line := Page.GetString(LineNr);
    Delete(Line, 1, Pos('<a', Line) - 1);
    Line := StringReplace(Line, '<br><a', ', <br><a');
    HTMLRemoveTags(Line);
    SetField(fieldDirector, Line);
  end;
 
  // Description
  LineNr := Findline('<b>Inhalt:</b>', Page, 0);
  LineNrTmp := LineNr;
  if LineNr > -1 then
  begin
    LineNr := Findline('<a href="view.php?page=inhalt', Page, 0);
    if LineNr > -1 then
    begin //"[mehr]" part exists
      Line := Page.GetString(LineNr);
      BeginPos := Pos('<a href="view.php?page=inhalt', Line) + 9;
      EndPos := Pos('"><b>[mehr]', Line);
      Value := Copy(Line, BeginPos, EndPos - BeginPos);
      GetDescriptions(Value);
    end else
    begin //No "[mehr]" part exists
      Line := Page.GetString(LineNrTmp);
      Value := TextBetween(Line, '<b>Inhalt:</b>', '</p></font></td>');
      SetField(fieldDescription, FullTrim(Value));
    end;
  end;
  
  // Rating
  LineNr := Findline('<br>Note:', Page, 0);
  if LineNr > -1 then
  begin
    Line:= Page.GetString(LineNr);
    BeginPos := Pos('<br>Note:',Line) + 10;

    // I had to add 0.1 here to make the rounding more precise
    Value := IntToStr(Round((StrToInt(Copy(Line, BeginPos+2, 2), 0) + 0.1) / 10));

    if StrToInt(Value,0) > 9 then
      Value := IntToStr(StrToInt(StrGet(Line, BeginPos),0) + 1) + '.0'
    else
      Value := StrGet(Line, BeginPos) + '.' + Value;
    SetField(fieldRating, Value);
  end;
end;
   
    
procedure GetOFDBActors(Address: string);
var
  Line,Temp, Value: string;
  LineNr, EndLine: Integer;
  Page: TStringList;

begin
  Page := TStringList.Create;
  Page.Text := GetPage('http://www.ofdb.de/'+Address);
  LineNr := Findline('Darsteller', Page, 0);
  if LineNr > -1 then
  begin
    Value:= '';

    EndLine := FindLine('/table', Page, LineNr);  // Find the end of the cast-table
    repeat
      LineNr := Findline('<a href="view.php?page=', Page, LineNr + 1);
      if LineNr >= EndLine then LineNr := -1;     // Cast-Table ended, leave loop
      if LineNr > -1 then
      begin
        Line := Page.GetString(LineNr);
        Delete(Line, 1, pos('<a href="view.php?page=', Line) + 22);
        Temp := TextBefore(Line, '=', '');
        if (Temp = 'person&id') Or (Temp = 'liste&Name') then
        begin
          Temp := TextBetween(Line, '">', '</a>');
          HTMLRemoveTags(Temp);
          if Temp <> '' then Value := Value + ', ' + Temp;
        end;
      end;
    until (LineNr < 0);

    Value:= copy(Value, 3,length(Value)-1);
    SetField(fieldActors, Value);
  end;
  Page.Free;
end;

    
procedure GetDescriptions(Address: string);
var
  Line, Value, Temp: string;
  LineNr: Integer;
  Page: TStringList;
  Reformat: Boolean;
  
begin
  Value := '';
  if GetOption('ReformatDescription') = 1 then Reformat := True else Reformat := False;

  Page := TStringList.Create;
  Page.Text := GetPage('http://www.ofdb.de/' + Address);
  LineNr := FindLine('Eine Inhaltsangabe von', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    Line := TextAfter(Line, '</a></b><br><br>');
    while (Pos('<br />', Line) > 0) do
    begin
      Temp := TextBefore(Line, '<br />', '');
      if Not Reformat then
      begin
        Value := Value + Temp + CRLF;
      end else
      begin
        if Temp <> '' then Value := Value + Temp + ' ';
      end     
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
    end;    
    Value := Value + TextBefore(Line, '</font></p>', '');
    SetField(fieldDescription, Value);
  end;
  Page.Free;
end;
   

procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
var
  Line: string;
  MovieTitle, MovieAddress, CutMark, CutMarkAddress: string;
  StartPos, EndPos: Integer;
 
begin
  Line := Page.GetString(LineNr);
  repeat
    CutMark := '">';
    CutMarkAddress := '" ';
    StartPos := Pos('<a href="view.php?page=film&fid=', Line);
    if StartPos = 0 then
    begin
      StartPos := Pos('<a href=''view.php?page=film&fid=', Line);
      CutMark := '''>';
      CutMarkAddress := ''' ';
    end;
    if StartPos > 0 then
    begin
      Delete(Line, 1, StartPos + 8);
      MovieAddress := TextBefore(Line, CutMarkAddress, '');
      MovieTitle := TextBetween(Line, CutMark, '</a>');
      HTMLRemoveTags(MovieTitle);
      if (MovieAddress <> '') And (MovieTitle <> '') then
      begin
        //MovieAddress := MovieAddress + '&full=1';
        PickTreeAdd(MovieTitle , 'http://www.ofdb.de/' + MovieAddress);
      end else
        StartPos := -1; // Error - Leave the Loop
    end;
  until (StartPos < 1);
end;


begin
  if CheckVersion(3,5,0) then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    if Input('OFDb', 'Bitte Titel eingeben :', MovieName) then
    begin
      AnalyzePage('http://www.ofdb.de/view.php?page=suchergebnis&SText='+UrlEncode(MovieName)+'&Kat=All');
    end;
  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.
Last edited by DarkS on 2007-12-03 09:51:13, edited 1 time in total.
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

You might have to set new variable "CutMarkAddress" for this part of the code, too :

Code: Select all

    if StartPos = 0 then
    begin
      StartPos := Pos('<a href=''view.php?page=film&fid=', Line);
      CutMark := '''>';
    end;
It is neccessary if there are pages that use two ' instead of one " for a link, but unfortunatly I do not have an example page to test this.
DarkS
Posts: 9
Joined: 2004-10-15 23:47:24

Post by DarkS »

You are right. I have overlooked this part.
I've updated the script in the first post with a new line.
yeti
Posts: 60
Joined: 2003-09-14 15:50:05

Post by yeti »

Thanks for your Update. I had no time to read the forum in the last months. And because I've no problems with the version 1.0.3, I don't update the script myself.

Greets,
yeti
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

Here's a new version (1.0.5) of OFDB script :
http://www.bad4u.741.com/full/OFDb%20%28DE%29.ifs (copy link into a NEW browser window !)

- Fix: some films have been missing on the results list (i.e. 'Am Tode vorbei')
- Fix: description import broken for some films (i.e. 'Cashback' - one version worked, one not)

They (currently) use multiple formats for links on result lists and movie detail pages, if you find more problems please post the movie name here..
raistlin2k
Posts: 6
Joined: 2003-07-13 08:46:06

another not working movie :(

Post by raistlin2k »

First of all, thanks for your fix!
Its working for most movies!! :grinking:

But it doesn't work on "In & Out", a movie from 1997.
The movie is available on OFDB, but i get no results with AMC.

Hope you can fix this!

Thanks in advane,
Raist
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Re: another not working movie :(

Post by bad4u »

raistlin2k wrote:But it doesn't work on "In & Out", a movie from 1997.
This bug is not caused by the script, it is caused by the function URLEncode, that does not translate the '&' into '%26'. Maybe antp can fix this or is it wanted/not possible ?

Most scripts will work if you just search for 'in out', but OFDb doesn't find correct movie. Nevertheless I did a short workaround on the scripts OMDb and OMDb+IMDb using StringReplace.

OFDb 1.0.6: http://www.bad4u.741.com/full/OFDb%20%28DE%29.ifs (copy link into a NEW browser window !)

OFDb - IMDb 1.3.3: http://www.bad4u.741.com/full/OFDb%20-% ... 8DE%29.ifs (copy link into a NEW browser window !)
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Good question... I am not sure if it is made on purpose or if it is a bug. I'll write it in my to-do list to check.
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

Thanks ;)
raistlin2k
Posts: 6
Joined: 2003-07-13 08:46:06

Post by raistlin2k »

thanks bad4u, works now :) :grinking:
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

OFDb 1.0.7: http://www.bad4u.741.com/full/OFDb%20%28DE%29.ifs (copy link into a NEW browser window !)

Fixed broken picture import.
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

OFDb 1.0.8: http://www.bad4u.741.com/full/OFDb%20%28DE%29.ifs (copy link into a NEW browser window !)

Fixed special characters import (UTF8).
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

OFDb 1.0.9: http://www.bad4u.741.com/full/OFDb%20%28DE%29.ifs (copy link into a NEW browser window !)

Fixed broken description import (from additional page).
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

OFDb 1.0.10: http://www.bad4u.741.com/full/OFDb%20%28DE%29.ifs (copy link into a NEW browser window !)

Fixed broken description import for special cases (when short description exceeds one row it could not find link to complete summary).
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

antp wrote:Good question... I am not sure if it is made on purpose or if it is a bug. I'll write it in my to-do list to check.
Beter late than never: the reason why & is not converted is because I use a function called ParamsEncode, which (as its name says) is dedicated to parameters encoding, and it supports that the string given is a list of parameters, not especially one parameter.
So indeed converting & would be dangerous, as in some cases it does not have to be converted.
I do not know what would be the best solution in this case. Maybe a second function which also encodes the & ?
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

antp wrote:I do not know what would be the best solution in this case. Maybe a second function which also encodes the & ?
:) I'd say, it depends on how much work this would be. The StringReplace workaround works for the ofdb script, not sure if it would make sense to add support for the & on other scripts, too. I personally did not need it yet.. but didn't test some more scripts for their behaviour on using the & symbol on movie names.
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

It would probably fail in most of the scripts, as what follows the & will be part of a separate parameter for the site.
Post Reply