Bon, j'ai testé sur quelques films donc il peut rester des erreurs. Merci de me les signaler (avec le nom du film)
Pour les pays voir un peu plus haut et la réponse de ScorEpion (faites gaffe, les p'tites bêtes attaquent
Une autre chose qui n'est pas terminée pour l'instant, c'est 'page précédente/page suivante' dans le menu de choix. ça viendra plus tard
Code: Select all
// GETINFO SCRIPTING
// Cinefil (FR) import avec grande Image
(***************************************************
* Script d'importation de film pour : *
* Cinéfil.com , http://www.cinefil.com *
* *
* correction suite à changement du site (v1) *
* (c) 2004 scorpion7552 *
* script original par *
* (c) 2003 Danone-KiD *
* *
* A utiliser avec Ant Movie Catalog 3.4.2 *
* www.antp.be/software/moviecatalog *
* *
* 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. *
***************************************************)
program cinefil;
const
CinefilUrl = 'http://www.cinefil.com/cinefil2005/';
crlf = #13#10;
ExternalPictures = False;
{ True: Les images seront stockées en tant que fichiers dans le même dossier que le catalogue
False: Les images seront stockées dans le catalogue (seulement pour les fichiers .amc) }
var
MovieName, Line: string;
BeginPos, EndPos: Integer;
filmok: Boolean;
//------------------------------------------------------------------------------
// RECHERCHE DU FILM (cinéfil)
//------------------------------------------------------------------------------
procedure AnalyzePageCinefil(Address: string);
var
Page: TStringList;
Value,page_film,titre_film, annee_film,PagePrev,PageNext: string;
begin
filmok := False;
PageNext := '';
PagePrev := '';
PickTreeClear; //vide la liste des films
PickTreeAdd('Films (Cinéfil)', '');
Line := GetPage(Address);
Value := ExtrStr(Line, '<B> Résultat ', '</B>');
if Value = '' then
begin
ShowMessage('Cinéfil: erreur lecture page'); // non trouvé = erreur
exit;
end;
if Copy(Value, 1, 1) = '0' then // 0 = aucun film
begin
ShowMessage('Cinéfil: aucun film trouvé pour "' + MovieName + '"');
exit;
end;
// mémo des films de cette page
Value := '<font class=noir>'; // séparateur de films
repeat
// cherche le lien de la page du film
BeginPos := Pos(Value, Line); // description film
if BeginPos > 0 then // 1 film trouvé
begin
Delete(Line, 1, BeginPos-1);
// url de la page
page_film := GetUrl('HREF=''../fichefilm.cfm?ref=', Line, CinefilUrl);
// année
annee_film := FormatTitre(ExtrStr(Line, Value, ' '));
// nom du film et réalisateur
BeginPos := Pos('TITLE="', Line);
Delete(Line, 1, BeginPos);
titre_film := ExtrStr(Line, '">', '</TD>');
titre_film := StringReplace(titre_film, '</a>', ','); // titre, réalisateur
titre_film := FormatTitre(titre_film);
// ajoute le film
PickTreeAdd(titre_film + ' ' + annee_film , page_film);
end;
until BeginPos = 0;
if PickTreeExec(Address) then
begin
if (Address = PageNext) or (Address = PagePrev) then
AnalyzePageCinefil(Address) // page suivante/précédente
else
begin
SetField(fieldURL, Address);
AnalyzePageFilmCinefil(Address); // page film
end;
end else
ShowMessage('Cinéfil: aucune page sélectionnée');
end;
//------------------------------------------------------------------------------
// ANALYSE DE LA PAGE DU FILM (Cinéfil)
//------------------------------------------------------------------------------
procedure AnalyzePageFilmCinefil(Address: string);
var
Value,Value2,Value3,img: string;
begin
filmok := True;
Line := GetPage(Address);
Line := ExtrStr(Line, 'Référence film cinefil', ''); // vire le début
// chargement des jaquettes on teste s'il y a un grand format
img := ExtrStr(Line, 'javascript:ZoomPhoto(''', '''');
if img = '' then // sinon on teste s'il y a un petit format
img := ExtrStr(Line, '<IMG class=photo SRC=''', '''');
if img <> '' then
GetPicture(img, ExternalPictures);
// pays année et durée
Value := ExtrStr(Line, '<font class="smallnoir">', '<BR>');
Value := StringReplace(Value, '- ', '|'); // sépare les champs par |
HTMLRemoveTags(Value);
HTMLDecode(Value);
BeginPos := Pos('|', Value);
Value2 := Copy(Value, 1, BeginPos-1); // pays
Delete(Value, 1, BeginPos);
if Value2 <> '' then
SetField(fieldCountry, FormatTitre(Value2));
BeginPos := Pos('|', Value);
Value2 := Copy(Value, 1, BeginPos-1); // année
Delete(Value, 1, BeginPos);
if Value2 <> '' then
SetField(fieldYear, FormatTitre(Value2));
BeginPos := Pos('|', Value);
Value2 := FormatTitre(Copy(Value, 1, BeginPos-1)); // durée
BeginPos := Pos('h', Value2);
Value2 := IntToStr(StrToInt(Copy(Value2, 1, BeginPos-1), 0) * 60 + StrToInt(Copy(Value2, BeginPos+1, 2), 0));
if Value2 <> '' then
SetField(fieldLength, FormatTitre(Value2));
// titre original ou traduit
Value3 := '<font class="noir"><font class="rouge16"><B>';
BeginPos := Pos(Value3, Line) + Length(Value3);
Value := ExtrStr(Line, Value3, '</B>');
// titre original éventuel
Value3 := '<BR>Titre original :<font class="smallrouge"> <B>';
Value2 := ExtrStr(Line, Value3, '</B>');
if Value2 = '' then // 1er titre = original
SetField(fieldOriginalTitle, FormatTitre(Value))
else
begin // traduit + original
BeginPos := Pos(Value3, Line) + Length(Value3);
SetField(fieldOriginalTitle, FormatTitre(Value2));
SetField(fieldTranslatedTitle, FormatTitre(Value));
end;
Delete(Line, 1, BeginPos-1);
EndPos := Pos('</B>', Line);
Delete(Line, 1, EndPos + 4);
// catégorie
Value := ExtrStr(Line, '<BR>', crlf);
// virer l'article (en espérant que c'est toujours un xxx ou une xxx)
Value := Trim(Value);
BeginPos := Pos(' ', Value);
Delete(Value, 1, BeginPos);
if Value <> '' then
SetField(fieldCategory, FormatTitre(Value));
// réalisateur
Value := ExtrStr(Line, '<B>', '</B>');
if Value <> '' then
SetField(fieldDirector, FormatTitre(Value));
// acteurs
BeginPos := Pos('avec', Line);
Delete(Line, 1, BeginPos);
Value := ExtrStr(Line, '<B>', crlf);
HTMLRemoveTags(Value);
HTMLDecode(Value);
if Value <> '' then
SetField(fieldActors, Value);
// description
Value := ExtrStr(Line, '<font class=smallnoir><BR><font class=noir>', '<BR>');
if Value <> '' then
SetField(fieldDescription, FormatText(Value));
//
if img = '' then // garder ou virer ???
ShowMessage('Cinéfil: pas d''affiche prévue pour "' + MovieName + '"');
end;
//------------------------------------------------------------------------------
// formatage d'un texte pour affichage
// suppression des tags html, remplacement des caractères bizarres
//------------------------------------------------------------------------------
function FormatText(str1: string) :string;
var
i: Integer;
begin
str1 := Trim(str1);
str1 := StringReplace(str1, #09, ''); // caractères parasites
// paragraphe = CRLF (cf 'avis de la rédaction')
str1 := StringReplace(str1, '<p>', crlf);
HTMLRemoveTags(str1); // vire les tags html
// supprimer les crlf et les blancs en début de texte
repeat
i := Pos(crlf,str1);
if i = 1 then
begin
Delete(str1, 1, 2);
str1 := Trim(str1); // si des blancs après le crlf
end;
until i <> 1;
HTMLDecode(str1); // caractères spéciaux
str1 := StringReplace(str1, 'œ', 'oe'); // caractères qui passent mal
str1 := StringReplace(str1, #150, '-'); // le vrai tiret
str1 := StringReplace(str1, #133, '...'); // les vrais points de suspension
str1 := StringReplace(str1, #147, '"'); // citation ouvrante ou #171
str1 := StringReplace(str1, #148, '"'); // citation fermante ou #187
result := str1;
end;
//------------------------------------------------------------------------------
// formatage d'un titre
//------------------------------------------------------------------------------
function FormatTitre(str1: string) :string;
begin
HTMLDecode(str1);
HTMLRemoveTags(str1);
str1 := StringReplace(str1, crlf, ''); // sur 1 seule ligne
str1 := StringReplace(str1, ' ', ''); // sans trop de blancs
str1 := Trim(str1);
str1 := AnsiLowerCase(str1); // en minuscules
str1 := AnsiUpFirstLetter(str1); // sauf 1ère lettre
result := str1;
end;
//------------------------------------------------------------------------------
// extraction d'une url contenue dans une chaine de caractères sans édition
// adr := GetUrl(texte_HREF_cherché,chaine,url_de_base)
//------------------------------------------------------------------------------
function GetUrl(from,str1,urlb: string) :string;
var
i: Integer;
delim: String;
begin
i := Pos(from, str1); // position href cherché
if i = 0 then // rien trouvé
begin
result := '';
exit;
end;
Delete(str1,1, i -1);
i := Pos('HREF=', UpperCase(str1)); // debut url: href=
delim := Copy(str1, i+5, 1); // fin = " ou '
Delete(str1,1, i +5);
i := Pos(delim, str1);
if i > 0 then
Delete(str1,i, Length(str1));
i := Pos('&mc=', str1);
if i > 0 then // supprime &mc= de l'url
Delete(str1, i, Length(str1));
str1 := StringReplace(str1, '../', ''); // cf adresse relative
str1 := StringReplace(str1, './', '');
str1 := urlb + str1; // ajoute url de base
result := Trim(str1);
end;
//------------------------------------------------------------------------------
// extraction de la chaine délimitée par from et to dans str1
//------------------------------------------------------------------------------
function ExtrStr(str1,strfrom,strto: string) :string;
var
i: Integer;
begin
if strfrom <> '' then // si from = '' on part du début
begin
i := Pos(strfrom, str1);
if i = 0 then // from non trouvé
begin
result := '';
exit;
end;
Delete(str1, 1, i + Length(strfrom) -1);
end;
i := Pos(strto, str1); // fin de la chaine
Delete(str1, i, Length(str1));
result := Trim(str1);
end;
//------------------------------------------------------------------------------
// écriture d'une chaine sur disque
// SavePage(chemin_du_fichier,chaine)
// chemin_du_fichier = chemin complet ex: 'c:\temp\monfichier.txt'
//------------------------------------------------------------------------------
procedure SavePage(fic, str1: string);
var
Page2: TStringList;
begin
page2 := TStringList.Create;
page2.Text := str1;
page2.SaveToFile(fic);
end;
//------------------------------------------------------------------------------
// c'est ici que ça commence
//------------------------------------------------------------------------------
begin
if CheckVersion(3,4,2) then
begin
// cinéfil préfère les titres en français
MovieName := GetField(fieldTranslatedTitle);
if MovieName = '' then
MovieName := GetField(fieldOriginalTitle);
if Input('cinéfil.com Import avec image', 'Entrez le titre du film :', MovieName) then
begin
AnalyzePageCinefil(CinefilUrl + 'CFM_Recherches/films.cfm?lachaine2=' + UrlEncode(MovieName));
if filmok then
DisplayResults;
end;
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.2)');
end.