[FR] Script pour edonkeydivx-fr
Posted: 2003-06-29 16:44:06
Leur base de données n'est pas très importante, mais elle risque de le devenir...
[/code]
Code: Select all
// GETINFO SCRIPTING
// edonkeydivx-fr.com
program edonkeydivx;
var
MovieName: string; // nom du film à rechercher
// get a copy of the string from position "from" to position "to" included
function copyFromTo(theString : String; fromPos : integer; toPos : integer) : String;
begin
result := copy(theString,fromPos,toPos-fromPos+1);
end;
// copy from "fromString" to "toString". It includes "fromString" and "toString" if "exclude" is false
// if fromString is '', copy from the beginning of the string
// if toString is '', copy up to the end of the string
function copySubString(theString : String; fromString : String; toString : String; exclude : boolean; caseSensitive : boolean) : String;
var
fromPos,toPos : integer;
tmp : String;
begin
result := '';
tmp := theString;
if (caseSensitive = false) then
begin
fromString := AnsiLowerCase(fromString);
toString := AnsiLowerCase(toString);
tmp := AnsiLowerCase(tmp);
end;
if (fromString <> '') then
fromPos := Pos(fromString, tmp)
else
fromPos := 1;
if (fromPos > 0) then
begin
delete(tmp, 1,fromPos-1);
if (toString <> '') then
toPos := pos(toString,tmp)+fromPos-1
else
toPos := length(tmp)+fromPos;
if (toPos > 0) then
begin
if exclude then
result := copyFromTo(theString,fromPos+length(fromString),toPos-1)
else
result := copyFromTo(theString,fromPos,toPos+length(toString)-1);
end;
end;
end;
procedure debug(str : String);
begin
input('debug','debug message', str);
end;
procedure AnalyseMoviePage(PageContents : String);
var
Table : string;
Row : string;
Value : string;
Cmnts : string;
Temp : string;
Link : string;
begin
Table := Trim(copySubString(PageContents,'<table width=''440'' border=''0'' cellspacing=''0'' cellpadding=''0'' class=''principal''>','</table>', true,true));
// Image
Row := copySubString(Table,'<tr>', '</tr>', false,true);
Value := copySubString(Row,'<img src=''affiche/',''' border=''0'' alt=''',true,true);
if Value <> '' then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := StringReplace(Value, ' ', '%20');
GetPicture('http://www.edonkeydivx-fr.com/divx/affiche/' + Value, False);
end;
// Titre
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Titre</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
SetField(fieldTranslatedTitle, Value);
end;
// Titre original
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Titre Original </strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
SetField(fieldOriginalTitle, Value);
end;
// Categorie
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Categorie</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
SetField(fieldCategory, Value);
end;
// Realisateur
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Realisateur</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
SetField(fieldDirector, Value);
end;
// Année
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Année</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
SetField(fieldYear, Value);
end;
// Durée
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Durée</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
Value := Copy(Value, 1, Pos(' ', Value)-1);
SetField(fieldLength, Value);
end;
// Taille
Row := copySubString(Table,'<tr>', '</tr>', false,true);
Cmnts := 'DivX Info:';
//if Pos('<strong>Taille</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
Value := Copy(Value, 1, Pos(' ', Value)-1);
SetField(fieldSize, Value);
Cmnts := Cmnts+#13#10+Value+' Mo';
end;
// Disque(s)
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Disque(s)</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
SetField(fieldDisks, Value);
Cmnts := Cmnts+#13#10+Value+' disque(s)';
end;
// Liens EDK
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Télécharger</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td width=''180''>','</td>',true,true);
Temp := Copy(Value, 1, Pos('</a>', Value)+3);
while Temp <> '' do
begin
Delete(Value, 1, Length(Temp));
Link := copySubString(Temp,'<a href=''',''' target=''_blank''>',true,true);
HTMLRemoveTags(Temp);
Cmnts := Cmnts+#13#10+Trim(Temp)+' '+Link;
Temp := Copy(Value, 1, Pos('</a>', Value)+3);
end;
end;
SetField(fieldComments, Cmnts);
// Description
Row := copySubString(Table,'<tr>', '</tr>', false,true);
//if Pos('<strong>Description</strong>', Row) > 0 then
begin
Delete(Table, 1, Length(Row));
Table := Trim(Table);
Value := copySubString(Row,'<td colspan=''2''>','</td>',true,true);
HTMLDecode(Value);
SetField(fieldDescription, Value);
end;
SetField(fieldUrl, '');
{
SetField(fieldCountry, );
SetField(fieldActors, );
}
end;
// returns true if movie has been found
// add movies to picktree
function AnalyzeSearchPage(PageContents : String) : boolean;
var
Page: TStringList;
MovieTitle: string;
BeginPos : Integer;
UrlPage : String;
begin
BeginPos := Pos('Film(s) trouvé(s) contenant(s)', PageContents);
if BeginPos > 0 then
begin
Delete(PageContents, 1, BeginPos);
PickTreeClear;
BeginPos := pos('<div align=''left''>', PageContents);
while (BeginPos > 0) do
begin
Delete(PageContents, 1, BeginPos+17);
MovieTitle := copy(PageContents, 1, pos('</div>', PageContents)-1); // ex : <div align='left'><a href="liste.php?mode=solo&nb=10"><img src='../images/triangle.gif' border='0'><b>Cube</b> (Fantastique - SF)</a></div>
UrlPage := 'http://www.edonkeydivx-fr.com/divx/' + copyFromTo(MovieTitle,pos('liste.php',MovieTitle),pos('">',MovieTitle)-1);
HTMLRemoveTags(MovieTitle);
HTMLDecode(MovieTitle);
PickTreeAdd(Trim(MovieTitle), UrlPage);
BeginPos := pos('<div align=''left''>', PageContents);
end;
result := true;
end
else
result := false;
end;
// search the given movie
procedure Search(movie : String);
var
PageContents : String;
UrlPage : String;
begin
PageContents := GetPage('http://www.edonkeydivx-fr.com/divx/liste.php?mode=search&mot='+URLEncode(movie));
if (AnalyzeSearchPage(PageContents)) then
begin
if PickTreeExec(UrlPage) then
begin
PageContents := GetPage(UrlPage);
SetField(fieldURL, UrlPage);
AnalyseMoviePage(PageContents);
DisplayResults;
end;
end;
end;
begin
if CheckVersion(3,4,1) then
begin
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if Input('edonkeydivx-fr', 'Entrez le titre du film :', MovieName) then
begin
Search(MovieName);
end;
end else
ShowMessage('Ce script requiert la version 3.4.1 ou supérieure de Ant Movie Catalog.');
end.