Need help ... AMC is the Best !!!

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
Jordi

Need help ... AMC is the Best !!!

Post by Jordi »

How I modify this script.
I wont 1st movie found from FilmWeb (without Page display)
Thanx !

ps. sorry, my english is so so :-))

Code: Select all

// GETINFO SCRIPTING
// Filmweb (PL) import batch , made by Jordi

(***************************************************
 *  Filmweb movie information importation script   *
 *                           *
 *                                                 *
 *  For use with Ant Movie Catalog 3.2.1           *
 *  www.ant.be.tf/moviecatalog ··· www.buypin.com  *
 ***************************************************)

program FilmWeb;
var
  MovieName: 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;

procedure DelSpace(var Value: String);
var
  FullValue: String;
  Counter: Integer;
begin
  if Value <> '' then
  begin
    FullValue := FullValue + StrGet(Value, 1);
    for Counter := 2 to Length(Value) do
    begin
      if StrGet(Value, Counter) <> ' ' then
        FullValue := FullValue + StrGet(Value, Counter)
      else
        if StrGet(FullValue, Length(FullValue)) <> ' ' then
          FullValue := FullValue + ' ';
    end;
    Value := FullValue;
  end
end;

procedure DecodeHTML(var Value: String);
var
  FullValue, CharCode: String;
  Counter: Integer;
begin
  if Value <> '' then
  begin
    FullValue := '';
    Counter := 1;
    repeat
      if StrGet(Value, Counter) <> '&' then
        begin
          CharCode := copy(Value, Counter, 1);
          case CharCode of
            '±': CharCode := '?';
            '?': CharCode := '?';
            '?': CharCode := '?';
            '?': CharCode := '?';
            '¶': CharCode := '?';
            '¦': CharCode := '?';
          end;
          FullValue := FullValue + CharCode;
          Counter := Counter + 1;
        end
      else
        begin
          CharCode := copy(Value, Counter, 7);
          case CharCode of
            'ą': FullValue := FullValue + '±';
            'ć': FullValue := FullValue + '?';
            'ę': FullValue := FullValue + '?';
            'ł': FullValue := FullValue + '?';
            'ń': FullValue := FullValue + '?';
            'ó': FullValue := FullValue + 'ó';
            'ś': FullValue := FullValue + '¶';
            'ź': FullValue := FullValue + '?';
            'ż': FullValue := FullValue + '?';
            'Ą': FullValue := FullValue + '?';
            'Ć': FullValue := FullValue + '?';
            'Ę': FullValue := FullValue + '?';
            'Ł': FullValue := FullValue + '?';
            'Ń': FullValue := FullValue + '?';
            'Ó': FullValue := FullValue + 'Ó';
            'Ś': FullValue := FullValue + '¦';
            'Ź': FullValue := FullValue + '¬';
            'Ż': FullValue := FullValue + '?';   
          else
            FullValue := FullValue + CharCode;  
          end;
          Counter := Counter + 7;
        end;
    until Counter > Length(Value);
    HTMLDecode(FullValue);
    Value := FullValue;
  end
end;

procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
var
  Line,rozpoznanie: string;
  MovieTitle, MovieAddress: string;
  StartPos, EndPos: Integer;
begin
  LineNr := FindLine('>           [film]<', Page, LineNr);
  if LineNr > -1 then
  begin
    PickTreeAdd('Znaleziono strony dla filmu : ' + MovieTitle, '');
    Line := Page.GetString(LineNr);
    repeat
      repeat
        StartPos := pos('>           [film]<', Line) + 19;
        Line := copy(Line, StartPos, Length(Line) - StartPos);
        StartPos := pos('href="', Line) + 6;
	Line := copy(Line, StartPos, Length(Line) - StartPos); 
		rozpoznanie:=copy(Line,1,4);
       	MovieAddress := copy(Line, 1, pos('">', Line) - 1);
	 StartPos := pos('">', Line) + 2;
        Line := copy(Line, StartPos, Length(Line) - StartPos);
        MovieTitle := copy(Line, 1, pos('</a>', Line) - 1);
        DecodeHTML(MovieTitle);
        HTMLRemoveTags(MovieTitle);
	if rozpoznanie='http' then
	PickTreeAdd(MovieTitle, MovieAddress);
	if rozpoznanie<>'http' then	
  PickTreeAdd(MovieTitle, 'http://www.filmweb.pl/' + MovieAddress);

      until pos('>           [film]<', Line) = 0;
      LineNr := LineNr + 1;
      Line := Page.GetString(LineNr);
    until pos('>           [film]<', Line) = 0;
  end
  else
    break;
end;

procedure AnalyzePage(Address: string);
var
  Page: TStringList;
  LineNr: Integer;
begin
  Page := TStringList.Create;
  Page.Text := GetPage(Address);
  if pos('wyniki wyszukiwania [Filmweb.pl]', Page.Text) = 0 then
    AnalyzeMoviePage(Page)
  else
  begin
    PickTreeClear;
    LineNr := 0;
    AddMoviesTitles(Page, LineNr);
    if PickTreeExec(Address) then
      AnalyzePage(Address);
  end;
  Page.Free;
end;

procedure AnalyzeMoviePage(Page: TStringList);
var
  Line, Value, FullValue: string;
  LineNr, Counter: Integer;
  StartPos, EndPos: Integer;
begin

// Picture
  LineNr := FindLine('foto.gif', Page, 0);
  if LineNr < 0 then
    LineNr := FindLine('<img alt="cover" align="left" src="http://posters.imdb.com/', Page, 0);
  if LineNr < 0 then
    LineNr := FindLine('<img alt="cover" align="left" src="http://images.amazon.com/', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('foto', Line) - 60;
   Line := copy(Line, StartPos, Length(Line) - StartPos); 
   StartPos := pos('src="', Line)+5;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := copy(Line, 1, pos('"', Line) - 1);
    GetPicture(Value, False); // False = do not store picture externally ; store it in the catalog file
  end;

  // Tytul
  LineNr := FindLine('name="tytul"', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('name="tytul"', Line) + 12;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    StartPos := pos('>', Line) +1;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := copy(Line, 1, pos('</column>', Line) - 1);
    DecodeHTML(Value);  
    SetField(fieldTranslatedTitle, Value);         
  end


  // Tytul oryginalny  
  LineNr := FindLine('name="tytulorg"', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('name="tytulorg"', Line) + 15;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    StartPos := pos('>', Line) + 1;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := copy(Line, 1, pos('</column>', Line) - 1);
    DecodeHTML(Value);  
    SetField(fieldOriginalTitle, Value);         
  end  
  
  // Ocena  
  LineNr := FindLine('rednia ocena:', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('"toprate"', Line) + 9;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    StartPos := pos('>', Line) + 1;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := IntToStr(Round(StrToInt(StrGet(Line, 1), 0) + (StrToInt(StrGet(Line, 3), 0) / 10) + (StrToInt(StrGet(Line, 4), 0) / 100)));
    SetField(fieldRating, Value)        
  end
 
  // Gatunek
  LineNr := FindLine('>gatunek:</td>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('>gatunek:</td>', Line) + 14;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    StartPos := pos('class="text"', Line) + 12;
    Line := copy(Line, StartPos, Length(Line) - StartPos);    
    StartPos := pos('">', Line) + 2;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := copy(Line, 1, pos('</td>', Line) - 1);
    DecodeHTML(Value); 
    SetField(fieldCategory, Value)        
  end
    
  // Produkcja
  LineNr := FindLine('>produkcja:</td>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('>produkcja:</td>', Line) + 16;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    StartPos := pos('class="text"', Line) + 12;
    Line := copy(Line, StartPos, Length(Line) - StartPos);    
    StartPos := pos('">', Line) + 2;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := copy(Line, 1, pos('</td>', Line) - 1);
    DecodeHTML(Value); 
    SetField(fieldCountry, Value)        
  end    
  
  // Data produkcji
  LineNr := FindLine('>data produkcji:</td>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('>data produkcji:</td>', Line) + 21;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    StartPos := pos('class="text"', Line) + 12;
    Line := copy(Line, StartPos, Length(Line) - StartPos);    
    StartPos := pos('">', Line) + 2;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := copy(Line, 1, pos('</td>', Line) - 1);
    SetField(fieldYear, Value)        
  end    

  // Rezyseria
  LineNr := FindLine('yseria:</td>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('yseria:</td>', Line) + 12;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    Value := copy(Line, 1, pos('</a></td></tr>', Line) - 1);
    HTMLRemoveTags(Value);
    DecodeHTML(Value); 
    SetField(fieldDirector, Value)        
  end  

      // Opis
  LineNr := FindLine('name="opis"', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('name="opis"', Line) + 7;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    StartPos := pos('">', Line) + 2;
    Line := copy(Line, StartPos, Length(Line) - StartPos);  
    Value := copy(Line, 1, pos('<', Line) - 1);
    HTMLRemoveTags(Value);
    DecodeHTML(Value); 
    DelSpace(Value);
    SetField(fieldDescription, Value)
  end     
  
  // Obsada
  LineNr := FindLine('Obsada</b>', Page, 0);
  if LineNr > -1 then
  begin
    Line := Page.GetString(LineNr);
    StartPos := pos('Obsada</b>', Line) + 10;
    Line := copy(Line, StartPos, Length(Line) - StartPos);
    Value := '';
    repeat
      if (pos('<a clas', Line) > 0) AND (pos('<a clas', Line) < pos(':</a></td>', Line)) then
      begin
        StartPos := pos('<a clas', Line) + 7;
        Line := copy(Line, StartPos, Length(Line) - StartPos);  
        StartPos := pos('">', Line) + 2;
        Line := copy(Line, StartPos, Length(Line) - StartPos);  
        Value := Value + copy(Line, 1, pos(':</a></td>', Line) - 1) + ', ' ; 
        StartPos := pos(':</a></td>', Line) + 10;
        Line := copy(Line, StartPos, Length(Line) - StartPos);         
      end;
    until (pos('<a clas', Line) = 0) OR (pos('<a clas', Line) > pos(':</a></td>', Line));
    Value := copy(Value, 1, Length(Value) - 2);
    DecodeHTML(Value); 
    SetField(fieldActors, Value)
  end

  //DisplayResults;
end;




begin
  if CheckVersion(3,2,1) then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    if MovieName = '' then
      MovieName := Input('IMDb Import', 'Enter the title of the movie:', MovieName);
    if MovieName <> '' then    begin
      AnalyzePage('http://www.filmweb.pl/searchtopic.xml?gdzie=1&key='+UrlEncode(MovieName));
    end;
  end else
    ShowMessage('Skrypt wymaga programu Ant Movie Catalog w wersji 3.2.1 lub nowszej');
end.
??:
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I added

Code: Select all

 tags around the script, it makes the text easier to read.
What do you want exactly ? That the script always takes the first movie found instead of showing the list ?
Jordi

Post by Jordi »

yes , first found on the site exactly the same name
ex. MovieTitle "I Spy" found and get "I Spy" from site
oder MovieTitle = MovieName from site between () ex.
Bezsennosc (Insomnia)
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

So what you want :
- Take the movie that has exactly the same title as what was typed,
- If not found, take the has what you typed between "( ... )",
- If still not found, display the list
correct?

This option would be easy to add...
Jordi

Post by Jordi »

hello,
..... If not found, take the has what you typed between "( ... )",......
not I typed between (), on the site is typed
MovieNameTranslated (MovieNameOriginal)

thanx :(
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

So either the thing before the ( ... ) or the thing inside...
ok, when I've few minutes I'll make this
Post Reply