|


|
Ant Movie Catalog
O
Script AdoroCinema.ifs
|
Este é o script original. Meus comentários estão em azul
As linhas comentadas pelo autor original do script estão em verde
O script já foi aperfeiçoado e está sendo discutido no meu fórum de testes, aqui:
http://ryan.com.br/smf/index.php?topic=5.0
O script usa funções embutidas que são explicadas no capítulo
"script files creation" do AMC Help e também funções de StringUtils1.pas.
O restante é basicamente Pascal.
Não sabe nem por onde começar? O início do programa é aqui
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=KeroCD (<link>kerocd2003@yahoo.com.br</link>)
Title=AdoroCinema
Description=Movie importation script for AdoroCinema
Site=www.adorocinema.com.br
Language=BR
Version=1.0
Requires=3.5.0
Comments=Script feito por KeroCD (kerocd2003@yahoo.com.br)
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]
***************************************************)
program Adorocinema;
uses
StringUtils1;
const
BaseAddress = 'http://www.google.com.br/search?hl=pt-BR&lr=&rls=GGLO,GGLO:2006-03,GGLO:pt-BR&q=+site:adorocinema.cidadeinternet.com.br+';
ManualPictureSelect = True;
ExternalPictures = False;
DescriptionToImport = 2;
var
MovieName: string;
MovieURL: string;
function HTMLRemove(Value: String): String;
begin
HTMLDecode(Value);
HTMLRemoveTags(Value);
Value := Trim(Value);
result := Value;
end;
//Esta função não é usada em lugar algum do script
function UpFirstLetterWord(texto:string):string;
var
espaco:integer;
sst:string;
begin
texto:=AnsiUpFirstLetter(AnsiLowerCase(texto));
repeat
espaco:=Pos(' ',texto);
sst:=AnsiUpperCase(Copy(texto,espaco+1,1));
texto:=Copy(texto,1,espaco-1)+'/|\'+sst+Copy(texto,espaco+2,length(texto));
until Pos(' ',texto)=0;
texto := StringReplace(texto, '/|\', ' ');
if Copy(texto,1,1)=' ' then
texto:=Copy(texto,2,length(texto));
result:=texto;
end;
procedure AnalyzeFilmPage(Address: String);
var
Page : TStringList;
Line, Value : string;
LineNr, BeginPos, EndPos: Integer;
AllTitles: TStringList;
url_imdb:string;
nome_orig:string;
nome_trad:string;
pais:string;
genero:string;
realizac:string;
Interpretes:string;
descricao:string;
capa:string;
begin
Page := TStringList.Create;
//value := 'http://216.247.85.101/images/'+Address+'.jpg';
// (it is working well)
//GetPicture(Value);
//Address:='http://dvdworld.com.br/dvdworld.hts?+'+Address+'+acha';
Page.Text := GetPage(Address);
SetField(fieldURL, Address);
//LineNr := FindLine('Título Original:', Page, 0);
if LineNr<>-1 then
begin
//Value := Page.GetString(LineNr);
value := Page.text;
BeginPos := pos('<em>Título Original:</em> ',value)+31;
EndPos := pos('<em>Gênero:</em>',value)-20;
nome_orig:=copy(value,BeginPos,EndPos-BeginPos);
nome_orig:=HTMLRemove(nome_orig);
SetField(fieldOriginalTitle, nome_orig);
end;
LineNr := FindLine('src="../transparente.gif" alt="transparente.gif (35 bytes)" width="70" height="5">', Page, 0);
if LineNr<>-1 then
begin
Value := Page.GetString(LineNr);
BeginPos := pos('width="70" height="5">',value)+22;
EndPos := pos('</font></td>',value);
nome_trad:=copy(value,BeginPos,EndPos-BeginPos);
nome_trad:=HTMLRemove(nome_trad);
SetField(fieldTranslatedTitle, nome_trad);
end;
LineNr := FindLine('<em>Direção:</em> ', Page, 0);
if LineNr<>-1 then
begin
Value := Page.GetString(LineNr);
BeginPos := pos('<em>Direção:</em> ',value)+23;
EndPos := pos('<br>',value);
realizac:=copy(value,BeginPos,EndPos);
realizac:=HTMLRemove(realizac);
SetField(fieldDirector, realizac);
end;
if LineNr<>-1 then
begin
Value := Page.Text;
BeginPos := pos('Elenco</font><br>',value)+28;
EndPos := pos('<a name="Sinopse"><font size="2" face="Arial, Helvetica, sans-serif">',value)-36;
Interpretes:=copy(value,BeginPos,EndPos-BeginPos);
Interpretes:=HTMLRemove(Interpretes);
SetField(fieldActors, Interpretes);
end;
LineNr := FindLine('<em>Gênero:</em> ', Page, 0);
if LineNr<>-1 then
begin
Value := Page.GetString(LineNr);
BeginPos := pos('<em>Gênero:</em> ',value)+22;
EndPos := pos('<br>',value); Value := Page.GetString(LineNr);
value:=copy(value,BeginPos,EndPos-BeginPos);
SetField(fieldCategory, value);
end;
LineNr := FindLine('Ano de Lançamento', Page, 0);
if LineNr<>-1 then
begin
Value := Page.GetString(LineNr);
BeginPos := pos(': </em>',value)+7;
EndPos := pos('<br>',value);
value:=copy(value,BeginPos,EndPos-BeginPos);
SetField(fieldYear, value);
end;
LineNr := FindLine('<em>Tempo de Duração:</em> ', Page, 0);
if LineNr<>-1 then
begin
Value := Page.GetString(LineNr);
BeginPos := pos('<em>Tempo de Duração:</em> ',value)+27;
EndPos := pos(' <em><br>',value)-8;
value:=copy(value,BeginPos,EndPos-BeginPos);
SetField(fieldLength, value);
end;
LineNr := FindLine('<em>Produção:</em>', Page, 0);
if LineNr<>-1 then
begin
Value := Page.GetString(LineNr);
BeginPos := pos('<em>Produção:</em> ',value)+19;
EndPos := pos('<br>',value);
value:=copy(value,BeginPos,EndPos-BeginPos);
SetField(fieldProducer, value);
end;
//LineNr := FindLine('<b>Sinopse:</b>', Page, 0);
if LineNr<>-1 then
begin
Value := Page.Text;
BeginPos := pos('Sinopse</font><br>',value)+39;
EndPos := pos('<a name="Pôsters">',value)-36;
descricao:=copy(value,BeginPos,EndPos-BeginPos);
descricao:=HTMLRemove(descricao);
SetField(fieldDescription, descricao);
end;
LineNr := FindLine('Ano de Lançamento', Page, 0);
if LineNr<>-1 then
begin
Value := Page.GetString(LineNr);
BeginPos := pos('(',value)+1;
EndPos := pos(')',value);
value:=copy(value,BeginPos,EndPos-BeginPos);
value:=HTMLRemove(value);
SetField(fieldCountry, value);
end;
begin
Value := Page.Text;
BeginPos := pos('Clique nos cartazes para vê-los ampliados em uma nova janela.<br>',value)+90;
EndPos := pos('.jpg" target="_blank"><img src="',value)+4;
capa:=copy(value,BeginPos,EndPos-BeginPos);
value := address;
value := TextBetween(value, 'http://adorocinema.cidadeinternet.com.br/filmes/', '/');
//value:=copy(value,BeginPos,EndPos-BeginPos);
capa := 'http://adorocinema.cidadeinternet.com.br/filmes/' + value + '/' + capa;
//ShowMessage(capa);
GetPicture(capa);
//SetField(fieldComments, value + capa);
end;
end;
//if LineNr<>-1 then
procedure AnalyzePage(Address: string);
var
Page: TStringList;
LineNr, StartPos, EndPos: Integer;
Line: string;
x:integer;
MovieAddress, findMovieName,linedown : string;
guardar,url, nome_filme:string;
begin
PickTreeClear;
//Preenche Page.Text com o conteúdo completo da primeira página de resposta do Google
Page := TStringList.Create;
Page.Text := GetPage(Address);
if (pos('FILMES - ', Page.Text)>0) and (pos('não encontrou nenhum documento correspondente', Page.Text) = 0) then
begin
//Esta seção analisa a página de resposta do Google procurando por items
//cujo título comece por 'FILMES - ', que é o título padrão de uma ficha de filme do Adorocinema
LineNr :=0;
repeat
//este bloco será repetido até chegar ao fim da página de resposta do Google
LineNr := FindLine('FILMES - ', Page, LineNr);//alterado
If LineNr >0 Then
Begin
//Início da procura pela URL
Line := Page.GetString(LineNr);
StartPos := pos('http://adorocinema.cidadeinternet.com.br/filmes/', Line)+0;
EndPos := pos('.asp">',Line)+4;
url:=(copy(line,StartPos,EndPos-StartPos));
//if url = '' then begin
// EndPos := pos('.htm">',Line)+4;
// url:=(copy(line,StartPos,EndPos-StartPos));
//end;
//Fim da busca da URL e início da procura pelo nome do filme
StartPos := pos('FILMES - ', Line)+9; //mudei 1 pr 28
EndPos := pos('</a><table cellpadding=0 cellspacing=0',Line)-0;
nome_filme := HTMLRemove(copy(Line, StartPos, EndPos-StartPos));
Line := Page.GetString(LineNr+1);
EndPos := pos(' ',Line)-1;
Line := copy(Line, 1, EndPos);
Line:= HTMLRemove(Line);
nome_filme:=Line+' - '+nome_filme;
//Aqui, cada par "nome_filme/url" é adicionado à lista
PickTreeAdd(nome_filme, url);
LineNr := LineNr + 1;
End; //if
until (LineNr<1); //é aqui que se fecha o loop iniciado em repeat
//Exibe a lista e espera que você faça uma escolha
if PickTreeExec(Address) then
begin
//Processa a página do filme escolhido
AnalyzeFilmPage(Address);
end;
Page.Free;
end
else
ShowMessage('Nada achado!')
end;
//É aqui que o programa realmente começa. Tudo acima são funções e variáveis usadas a a partir daqui
begin
//É desnecessário neste script, porque não estamos usando a PickList (usamos a PickTree)
PickListClear;
//Pega o nome original do filme, se houver, no item que você tem aberto
MovieName := GetField(fieldOriginalTitle);
//Cria a caixa de diálogo perguntando o nome do filme
if Input('Importar do AdoroCinema', 'Escreva o nome do filme:', MovieName) then
begin
//Substitui todos os espaços no nome pelo caractere '+'. "Robin Hood" fica "Robin+Hood";
//Mas para esse tipo de coisa é recomendável usar a função URLENCODE
MovieName := StringReplace(MovieName, ' ', '+');
//Chama a procedure que consulta o google
//O autor deveria ter usado a variável BaseAddress aqui
AnalyzePage('http://www.google.com.br/search?hl=pt-BR&lr=&rls=GGLO,GGLO:2006-03,GGLO:pt-BR&q=+site:adorocinema.cidadeinternet.com.br+'+MovieName);
end;
end.
|