Page 1 of 1

[MOD] Bug in Yahoo Cinema (ES).ifs - Solved here

Posted: 2005-03-29 21:59:39
by enriquevagu
When reading some movies data, the spanish script from Yahoo! page gets "blocked", just try searching for "Los increíbles" (The Incredibles).

The problem is in the "Calificación" field, which is taken from the number of coloured stars (from 0 to 5) in the Yahoo Page. The value for the field is the number of yellow stars*2. The problem is that, if the movie is very good and it has 5 yellow stars at the Yahoo! page, the script will roll forever searching for the first (unexistant) white star, in an infinite loop.

The solution for this problem is to substitute line #186:

Code: Select all

 while EndRating = 0 do
with the following one:

Code: Select all

while (EndRating = 0) and (irate < 5) do
I hope it will get corrected in the next version of the script.

Very good job!

Enriquevagu

Posted: 2005-03-30 07:39:18
by antp
Thanks ;)

Posted: 2005-03-30 08:07:31
by folgui
Thanks enrique

:grinking:

Posted: 2005-04-02 22:34:35
by folgui
Hello!

Here's the updated script with changed version and date, so users can easily detect latest version of script.

antp, copy/save it to update latest version of script.

Regards, folgui

Code: Select all

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

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

[Infos]
Authors=Andrea Cristaudo (achris@tiscalinet.it) & folgui (folgui@bigfoot.com)
Title=Yahoo!Cinema Spain
Description=Movie importation script for Yahoo!Cinema Spain
Site=http://es.movies.yahoo.com
Language=ES
Version=1.2 (30 Mar 2005)
Requires=3.5.0
Comments=Updated by folgui for Spanish Database Support and more info importing. Reported/fixed bug by enriquevagu, thanks!|
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]
LargePic=1|1|0=It imports default (small) pic|1=It imports a larger pic

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

program YahooCinema;
var
MovieName: string;
TheMovieAddress: string;

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

function TextBetween(var S: string; StartTag: string; EndTag: string): string;
var
  InitialPos: Integer;
begin
  InitialPos := Pos(StartTag, S);
  Delete(S, 1, InitialPos + Length(StartTag) - 1);
  InitialPos := Pos(EndTag, S);
  result := copy(S, 1, InitialPos - 1);
  Delete(S, 1, InitialPos + 1);
end;

procedure AnalyseLargePicPage(Address: string);
var
Page: TStringList;
LineNr: integer;
Line: string;
ImageURL: string;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<img src="http://eur.news1.yimg.com/eur.yimg.com/', Page, 0);
If LineNr <> -1 then
 begin
  Line := Page.GetString(LineNr);
  ImageURL := TextBetween (Line, '<img src="', '"');
  GetPicture (ImageURL);
 end
Page.Free;
end;

procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr: integer;
BeginPos: integer;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<font face=arial,helvetica size=+1><b>Resultados de búsqueda</b></font>', Page, 0);
if LineNr = -1 then
begin
  SetField(fieldURL, Address);
  AnalyzeMoviePage(Page);
end
else
begin
  PickTreeClear;
  AddMoviesTitles(Page);
  if TheMovieAddress='' then
  begin
   if PickTreeExec(Address) then
   begin
    SetField(fieldURL, Address);
    Page.Text := GetPage(Address);
    AnalyzeMoviePage(Page);
   end;
  end
  else
  begin
   SetField(fieldURL, TheMovieAddress);
   Page.Text := GetPage(TheMovieAddress);
   AnalyzeMoviePage(Page);
  end;
end;
Page.Free;
end;

procedure AnalyzeMoviePage(Page: TStringList);
var
 Fine: Integer;
 EndActors: Integer;
 EndProducers: Integer;
 EndMusics: Integer;
 EndDirectors: Integer;
 EndPhotographers: Integer;
 EndWriters: Integer;
 EndRating: Integer;
 strActors: string;
 strComments: string;
 strProducers: string;
 strMusics: string;
 strDirectors: string;
 strPhotographers: string;
 strWriters: string;
 Line: string;
 ImageURL: string;
 strTemp: string;
 LineNr: Integer;
 BeginPos, EndPos: Integer;
 Field: integer;
 irate: integer;
begin
Page.Text := StringReplace(Page.Text, ' ', '');
Fine := 0;
  LineNr := FindLine('<FONT color=white face="arial, helvetica"><b>', Page, 0);
if LineNr > -1 then
begin
  //Translated Title
  Line := Page.GetString(LineNr);
  HTMLRemoveTags(Line);
  Line := StringReplace(Line,'"','');
  SetField(fieldTranslatedTitle,Line);

  repeat
   LineNr := LineNr + 1;
   Line := Page.GetString(LineNr);
   //GetPicture of Movie
   if GetOption('LargePic') = 0 then
    // Import Small Picture
    begin
      if pos('html"><img src="http:', Line) <> 0 then
       begin
        Delete(Line, 1, pos('<img ', Line) + 9);
        Delete(Line, pos('" border=', Line), pos('</a>', Line) + 1);
        GetPicture(Line);
       end
    end
   // Import Large Picture
   else
    begin
      if pos('Agrandar la imagen</a>', Line) <> 0 then
       begin
        ImageURL := TextBetween(Line, '<a href="', '">Agrandar la imagen</a>');
        AnalyseLargePicPage('http://es.movies.yahoo.com' + ImageURL);
      end
    end
   //Original Title
   if pos('<b>Título original:</b>', Line) <> 0 then
    begin
     HTMLRemoveTags(Line);
     Delete(Line, 1, 16);
     Line := StringReplace(Line,'"','');
     SetField(fieldOriginalTitle, Line);
    end
   //Country and Year
   else if pos('<b>País y año:</b>',Line) <> 0 then
    begin
     LineNr := LineNr + 1;
     Line := Page.GetString(LineNr);
     SetField(fieldCountry, Line);
     LineNr := LineNr + 1;
     Line := Page.GetString(LineNr);
     SetField(fieldYear, copy(Line, 2, 4));
    end
   //Category and Length
   else if pos('<b>Género:</b>', Line) <> 0 then
    begin
     HTMLRemoveTags(Line);
     Delete(Line, 1, 7);
     SetField(fieldCategory, Line);
     LineNr := LineNr + 1;
     Line := Page.GetString(LineNr);
     HTMLRemoveTags(Line);
     Delete(Line, 1, 9);
     SetField(fieldLength, copy(Line, 1, 3));
     If GetField(fieldLength) = '' then
      SetField(fieldLength, copy(Line, 1, 2));
    end
   //Rating
   else if pos('<b>Crítica:</b>', Line) <> 0 then
    begin
     irate := 0;
     LineNr := LineNr + 1;
     Line := Page.GetString(LineNr);
     EndRating := pos('<img src="http://eur.i1.yimg.com/eur.yimg.com/i/de/mo/1sg.gif" width=10 height=9>', Line);
     while (EndRating = 0) and (irate < 5) do
      begin
       irate := irate + 1;
       LineNr := LineNr + 1;
       Line := Page.GetString(LineNr);
       EndRating := pos('<img src="http://eur.i1.yimg.com/eur.yimg.com/i/de/mo/1sg.gif" width=10 height=9>', Line);
      end
     SetField(fieldRating, IntToStr(irate*2));
    end
   //Description
   else if pos('<b>Sinopsis:</b>', Line) <> 0 then
    begin
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     HtmlRemoveTags(Line);
     SetField(fieldDescription, Line);
    end
   //List of Actors
   else if pos('<b>Actor / Actriz:</b>', Line) <> 0 then
    begin
     strActors := '';
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     EndActors := pos('</font></td></tr>', Line);
     while EndActors = 0 do
      begin
       HtmlRemoveTags(Line);
       if strActors = '' then
        strActors := Line
       else
        strActors := strActors + ' ' + Line;
       LineNr := LineNr + 1;
       Line := Page.GetString(LineNr);
       EndActors := pos('</font></td></tr>', Line);
      end
     SetField(fieldActors, strActors);
    end
   else if pos('Montador:</b>', Line) <> 0 Then
    begin
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     HtmlRemoveTags(Line);
     strComments := 'Montaje: ' + Line + #13#10;
    end
   // Music for Comments
   else if pos('<b>Musica:</b>', Line) <> 0 then
    begin
     strMusics := '';
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     EndMusics := pos('</font></td></tr>', Line);
     while EndMusics = 0 do
      begin
       HtmlRemoveTags(Line);
       if strMusics = '' then
        strMusics := Line
       else
        strMusics := strMusics + ' ' + Line;
       LineNr := LineNr + 1;
       Line := Page.GetString(LineNr);
       EndMusics := pos('</font></td></tr>', Line);
      end
     strComments := strComments + 'Música: ' + strMusics + #13#10;
    end
   // Aditional Music Author for Comments
   else if pos('<b>Compositor (música adicional):</b>', Line) <> 0 then
    begin
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     HtmlRemoveTags(Line);
     strComments := strComments + 'Compositor: ' + Line + #13#10;
    end
   //Director
   else if pos('<b>Director:</b>', Line) <> 0 then
    begin
     strDirectors := '';
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     EndDirectors := pos('</font></td></tr>', Line);
     while EndDirectors = 0 do
      begin
       HtmlRemoveTags(Line);
       if strDirectors = '' then
        strDirectors := Line
       else
        strDirectors := strDirectors + ' ' + Line;
       LineNr := LineNr + 1;
       Line := Page.GetString(LineNr);
       EndDirectors := pos('</font></td></tr>', Line);
      end
     SetField(fieldDirector, strDirectors);
    end
   //Photography for Comments
   else if pos('<b>Fotografía:</b>', Line) <> 0 then
    begin
     strPhotographers := '';
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     EndPhotographers := pos('</font></td></tr>', Line);
     while EndPhotographers = 0 do
      begin
       HtmlRemoveTags(Line);
       if strPhotographers = '' then
        strPhotographers := Line
       else
        strPhotographers := strPhotographers + ' ' + Line;
       LineNr := LineNr + 1;
       Line := Page.GetString(LineNr);
       EndPhotographers := pos('</font></td></tr>', Line);
      end
     strComments := strComments + 'Fotografía: ' + strPhotographers + #13#10;
    end
   //Screenplay Writer for Comments
   else if (pos('<b>Guionista:</b>', Line) <> 0) Or (pos('<b>Guión', Line) <> 0) then
    begin
     strWriters := '';
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     EndWriters := pos('</font></td></tr>', Line);
     while EndWriters = 0 do
      begin
       HtmlRemoveTags(Line);
       if strWriters = '' then
        strWriters := Line
       else
        strWriters := strWriters + ' ' + Line;
       LineNr := LineNr + 1;
       Line := Page.GetString(LineNr);
       EndWriters := pos('</font></td></tr>', Line);
      end
     strComments := strComments + 'Guionista: ' + strWriters + #13#10;
    end
   //Producer
   else if (pos('<b>Producción:</b>', Line) <> 0) Or (pos('<b>Productor', Line) <> 0) then
    begin
     strProducers := '';
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     EndProducers := pos('</font></td></tr>', Line);
     while EndProducers = 0 do
      begin
       HtmlRemoveTags(Line);
       if strProducers = '' then
        strProducers := Line
       else
        strProducers := strProducers + ' ' + Line;
       LineNr := LineNr + 1;
       Line := Page.GetString(LineNr);
       EndProducers := pos('</font></td></tr>', Line);
      end
     SetField(fieldProducer, strProducers);
    end
   // More Comments
   else if pos('<b>Notas de Producción</b>', Line) <> 0 then
    begin
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     strTemp := TextBetween(Line, '<FONT face=arial size=-1>', '<a href="');
     HtmlDecode(strTemp);
     strComments := strComments + '------------------------------';
     strComments := strComments + #13#10 + strTemp;
    end
   // More Comments
   else if pos('<b>Crítica</b>', Line) <> 0 then
    begin
     LineNr := LineNr + 2;
     Line := Page.GetString(LineNr);
     strTemp := TextBetween(Line, '<FONT face=arial size=-1>', '<a href="');
     HtmlDecode(strTemp);
     strComments := strComments + '------------------------------';
     strComments := strComments + #13#10 + strTemp;
    end
   else if Line = '</html>' then
    Fine := 1;
  until Fine = 1;
  SetField(fieldComments, strComments);
end;
//DisplayResults;
end;

procedure AddMoviesTitles(Page: TStringList);
var
LineNr: Integer;
NewLineNr: Integer;
Line: string;
MovieTitle, MovieAddress: string;
BeginPos, EndPos: Integer;
begin
TheMovieAddress := '*';
LineNr := 0;
LineNr := FindLine('<font face=arial,helvetica><b>Resultado de películas</b>',Page,LineNr);
LineNr := LineNr + 3;
PickTreeAdd('Resultados encontrados:','');
while LineNr > 2 do
begin
  Line := Page.GetString(LineNr);
  BeginPos := pos('<li><a href="',Line)+13;
  EndPos := pos('">',Line);
  MovieAddress := copy(Line,BeginPos,EndPos-BeginPos);
  Delete(Line,1,EndPos + 1);
  BeginPos := 1;
  EndPos := -1;
  MovieTitle := Line;
  HTMLRemoveTags(MovieTitle);
  HTMLDecode(Movietitle);
  PickTreeAdd(MovieTitle, MovieAddress);

  NewLineNr := FindLine('<li><a href="',Page,LineNr+1);
  if NewLineNr <> (LineNr + 1) then
   LineNr := 2
  else
   LineNr := NewLineNr;

  if TheMovieAddress='*' then
   TheMovieAddress := MovieAddress
  else
   TheMovieAddress := '';
end;
if TheMovieAddress='*' then TheMovieAddress := '';
end;

begin
if CheckVersion(3,5,0) then
begin
  MovieName := GetField(fieldTranslatedTitle);
  if MovieName = '' then
   MovieName := GetField(fieldOriginalTitle);
  if Input('Yahoo!Cinema España', 'Introduce el título de la película (enter movie title):', MovieName) then
  begin
   AnalyzePage('http://es.search.movies.yahoo.com/search/movies_db_es?mt='+UrlEncode(MovieName));
  end;
end else
  ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
end.

Posted: 2013-06-25 22:10:54
by otreux
Don't work :(

Posted: 2013-06-26 13:58:13
by antp
otreux wrote:Don't work :(
It is 8 years old, the site most likely changed since then...
You're doing forum archaeology there :lol: