Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Luis Henrique Carneiro
Title=AdoroCinema
Description=Movie importation script for AdoroCinema
Site=www.adorocinema.com
Language=BR
Version=1.0 (27 Janeiro 2010)
Requires=3.5.1
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]
Link do site Oficial=0|0|0=Não|1=Sim
***************************************************)
program AdoroCinema;
uses StringUtils1,StringUtils7552;
var nomeFilme: string;
// simple string procedures
function ra(S : string) : string;
Begin
S:=StringReplaceAll(S,'ç','c');
S:=StringReplaceAll(S,'ã','a');
S:=StringReplaceAll(S,'é','e');
S:=StringReplaceAll(S,'Ã','i');
S:=StringReplaceAll(S,'acute;','');
S:=StringReplaceAll(S,'tilde;','');
S:=StringReplaceAll(S,'cedil;','');
S:=StringReplaceAll(S,'&','');
Result := S;
End;
function StringReplaceAll(S, Old, New: string): string;
begin
while Pos(Old, S) > 0 do
S := StringReplace(S, Old, New);
Result := S;
end;
Function ConvertNum(s: string) : string;
var
i: Integer;
s2, ch: string;
begin
s := AnsiLowerCase(s);
s2 := '';
For i := 1 To Length(s) do
begin
ch := copy(s, i, 1);
if ((ch >= '0') and (ch <= '9')) then
s2 := s2 + ch;
end;
result := s2;
end;
procedure CutBefore(var Str: string; Pattern: string);
begin
Str := Copy(Str, Pos(Pattern, Str), Length(Str));
end;
procedure CutAfter(var Str: string; Pattern: string);
begin
Str := Copy(str, Pos(Pattern, Str) + Length(Pattern), Length(Str));
end;
// Loads and analyses page from internet
procedure AnalyzePage(Address: string);
var
Page: TStringList;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if Pos('>nome original:<', Page.Text) = 0 then
begin
ShowMessage('Nothing found.');
Exit;
end
else
begin
PickTreeClear;
PickTreeAdd('Search results:', '');
AddMoviesTitles(Page);
if PickTreeExec(Address) then
AnalyzeMoviePage(Address);
end
end;
procedure AnalyzeMoviePage(Address: String);
var
Page: TStringList;
LineNr, BeginPos: integer;
value, value2: string;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
value2:=Address;
value:=TextBetween(Page.Text,'site oficial</strong>:<a href="','" ');
SetField(fieldURL, value + ' (' + value2 + ')' );
value:=ra(TextBetween(Page.Text,'<title>',' - '));
SetField(fieldTranslatedTitle, value);
value:=ra(TextBetween(Page.Text,'original</strong>:','</'));
SetField(fieldOriginalTitle, trim(value));
value:=TextBetween(Page.Text,'amento</strong>:','</');
SetField(fieldYear, trim(value));
value:=TextBetween(Page.Text,' </strong> ','</p>');
value:=TextBetween(value,'(',')');
SetField(fieldCountry, trim(value));
value:=TextBetween(Page.Text,'nero</strong>:','</');
value:=ra(value);
SetField(fieldCategory, trim(value));
value:=TextBetween(Page.Text,'dura','/p>');
value:=ConvertNum(TextBetween(value,'>','<'));
SetField(fieldLength, trim(value));
value:=TextBetween(Page.Text,'<strong>produ','/li');
value:=ra(TextBetween(value,'>:','<'));
SetField(fieldProducer, FullTrim(value));
value:=TextBetween(Page.Text,'<li><strong>dire','/li');
value:=ra(TextBetween(value,'>:','<'));
SetField(fieldDirector, trim(value));
value:=TextBetween(Page.Text,'elenco:','id="ficha_noticias"');
value:=FormatText2(value);
SetField(fieldActors, value);
value:=TextBetween(Page.Text,'sinopse:</h4></div>','</p></div>');
value:=ra(FormatText2(value));
SetField(fieldDescription, value);
value:=TextBetween(Page.Text,'tica do adorocinema</h4>','src="');
value:=TextBetween(value,'Rate','"');
SetField(fieldRating, value);
value:=TextBetween(Page.Text,'thumb" src="','" width=');
if (value <> '') and CanSetPicture then GetPicture(value);
GetPicture(value);
end;
procedure AddMoviesTitles(ResultsPage: TStringList);
var
Page: string;
MovieTitle, MovieAddress : String;
begin
Page := ResultsPage.Text;
while Pos('>nome original:<', Page) > 0 do
begin
CutBefore(Page, '>nome original:<');
MovieAddress := 'http://www.adorocinema.com/filmes' + TextBetween(Page, '<a href="http://www.adorocinema.com/filmes', '/#');
CutBefore(Page, '<a href="http://www.adorocinema.com/filmes');
MovieTitle := TextBetween(Page, 'title="', '">');
MovieTitle := ra(MovieTitle);
CutAfter(Page, '<span class="favoritos">');
PickTreeAdd(MovieTitle, MovieAddress);
end;
end;
begin
PickListClear;
nomeFilme := GetField(fieldTranslatedTitle);
if (length(nomeFilme)=0) then
nomeFilme := GetField(fieldOriginalTitle);
if Input('Importar do Adorocinema', 'Escreve o nome do filme:', nomeFilme) then
begin
nomeFilme:=stringreplace(nomeFilme,' ','+');
AnalyzePage('http://www.adorocinema.com/busca/?criteria='+nomeFilme);
end;
end.