(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=scorpion7552 (script original: Danone-Kid) modifié par Dedej
Title=Cinéfil
Description=infos de Cinéfil - mode normal/batch: voir l'onglet Commentaires
Site=http://www.cinefil.com/
Language=FR
Version=5.9 du 09/10/2014
Requires=3.5.0
Comments=mode batch: 2 modes possibles: d'après l'url mémorisée (Cinéfil) ou d'après le nom du film + réalisateur (résultats non garantis!)|N'oubliez pas de sauvegarder votre base actuelle avant de lancer le mode batch|Conseils: sélectionnez un nombre raisonnable de films et triez la liste des films par numéros|à la fin de chaque mise à jour, un fichier log est créé (informations et erreurs - attention ce fichier est recréé à chaque lancement du mode batch)
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
RequiresMovies=1
[Options]
Mise à jour du Script=1|1|0=Pas de mise à jour|1=Mise à jour du script
Mode=0|0|0=mode normal|1=mode batch (url)|2=mode batch (nom)
FormatTitre=0|0|0=laisser les titres des films tels quels|1=tout en minuscules|2=tout en majuscules|3=1ère lettre en majuscule le reste en minuscules|4=toutes les 1ères lettres en majuscules
Champs personnalisés=0|0|0=Ne pas utiliser de champs personnalisés|1=Utiliser des champs personnalisés
Affiche=2|2|0=aucune affiche|1=affiche petit format|2=affiche grand format
Acteurs=0|0|0=les acteurs principaux|1=tous les acteurs
Catégorie=0|0|0=1ère catégorie seule|1=toutes les catégories
Note=1|1|0=Aucune|1=presse|2=internautes|3=moyenne|4=Presse sinon celle des internautes
Garder commentaire=0|0|0=Ne pas garder les commentaires précédent|1=Garder les commentaires précédent
AvisInt=0|0|0=aucun avis|1=avis (Internautes)
Avis CSA=0|0|0=Sans Avis CSA|1=Avec Avis CSA
Bande Annonce=0|0|0=Sans Bande Annonce|1=Avec Bande Annonce
Extra : Photos du film=0|0|0=Pas d'extra|1=Récupération des photos en extra
[Parameters]
***************************************************)
// nécessite les modules suivants
// BatchCommon7552.pas (qui inclut StringUtils1.pas et StringUtils7552.pas)
// utilisation de BatchCommon7552.pas
program cinefil;
uses
BatchCommon7552, ScorEpioNCommonScript;
const
debug = False; // mode debug on/off
debugrep = 'c:\temp\'; // répertoire de stockage des fichiers
//
CinefilUrl = 'http://www.cinefil.com';
id_Cinefil = 'Cinefil'; // ident
VersionScript = '5.9 du 09/10/2014';
ScriptName = 'Cinefil (FR).ifs';
SiteUrl = 'http://joel.desseaux.free.fr/Cinefil/';
timetosleep = 500;
var
// note FormatUTF8 est déclaré dans StringUtils7552 (integer)
movieok, pageko: Boolean;
MovieName, firstcall, entete, onglets, infos: String;
pgacteurs, idacteurs, pgavis, idavis, pgphotos, idphotos, pgba, idba: String;
ImportPictures, Maj, PMaj, Nb : Integer;
//------------------------------------------------------------------------------
// recherche du film (cinéfil)
// MovieName = nom du film cherché (tel que saisi, cad non formaté)
//------------------------------------------------------------------------------
procedure AnalysePage;
var
Address, Page, PageNext, PagePrev, Line, Value, realisateur, PageFilm, urlfilm, Temp: string;
pagenum, filmnum, i, Count: integer;
memo: TStringList;
found, postp: Boolean;
begin
pagenum := 0; // compteur de pages
postp := True; // 1er appel = post
batchList := TStringList.Create; // init liste de mémo
// init adresse 1ere recherche
Address := CinefilUrl + '/recherche?';
PickTreeClear; // init list
PickTreeAdd('Films (Cinéfil)', '');
found := False;
repeat
pagenum := pagenum + 1;
// 1er appel, postpage
begin
if pagenum = 1 then
begin
PageNext := '';
PagePrev := '';
Sleep(500);
MovieName := FormatMovieName3(UTF8Encode(MovieName)); //
MovieName := StringReplace(MovieName, ' ', '+');
Page := PostPage(Address, 'KEYWORDS=' + MovieName + '&CAT=FILMS&idFILTER=0');
end else
Page := PostPage(Address, PageNext);
end;
if debug then
DumpPage(debugrep+id_Cinefil+' choix'+IntToStr(pagenum)+'.txt', Page); // debug
FormatUtf8 := 0;
if (Pos('réponse trouvée', Page) = 0) and (Pos('réponses trouvées', Page) = 0) and not found then
begin
LogMessage(id_Cinefil+': erreur lecture page de recherche '+IntToStr(pagenum)); // non trouvé = erreur
batchList.Free;
exit;
end;
if (Pos('
Aucune ré', TextBefore(Page, '
', '')) > 0) and not found then
begin
Page := ''; // rien du tout
MovieName := StringReplace(MovieName, '+', ' ');
LogMessage(id_Cinefil+': aucun film trouvé pour "'+UTF8Decode(MovieName)+'"');
batchList.Free;
exit;
end;
//if Temp <> '' then Page := Temp;
if Temp = '' then
begin
if (Pos('>Voir les', Page) > 0) and (Pos(' films
', Page) > 0) then
begin
Temp := Textafter(Page, ''); // infos utiles
Value := Address + Formatline(TextBetween(Page, 'Voir les '));
Page := Getpage(Address + Formatline(TextBetween(Page, 'Voir les ')));
temp := TextBetween(Page, '
');
end;
end;
// tester ici s'il existe des pages next et prev
PageNext := (TextBefore(Page,'" rel="nofollow">Suivant
','Précédent', ' 0 then
Page := TextBetween(Page, 'backgroundGradientCarteBlanc', '
');
//Page := StringReplace(Page, crlf, ''); // separe lignes
if PagePrev <> '' then
begin
Address := CinefilUrl + '/recherche?';
Value := Address + PagePrev;
PickTreeAdd('Page précédente', Value);
end;
memo := TStringList.Create;
memo.Text := Page;
Value := '';
PageFilm := '';
for filmnum := 0 to memo.Count -3 do
begin
Line := memo.GetString(filmnum);
if (PageFilm = '') or (Value = '') then
PageFilm := GetUrl(Line, urlfilm, CinefilUrl);
// extraire le nom et le réalisateur
if Value = '' then
Value := FormatLine(TextBetween(Line, 'title="', '" itemprop=')); // titre
realisateur := UTF8Decode(Value) + ' - ' + UTF8Decode(FormatLine(TextBetween(Line, '">de', ' - ')));
if (realisateur = UTF8Decode(Value) + ' - ') then
realisateur := '';
if realisateur = '' then continue; // pas de réalisateur = autre chose ou ligne vide
Line := realisateur;
if (AnsiLowerCase(Value) = AnsiLowerCase((StringReplace(StringReplace(FormatMovieName3(MovieName), '+', ' '), ' ', ' ')))) or (PageNext = '') then
found := True;
Value := '';
if BatchMode = 0 then
begin
PickTreeAdd(Line, PageFilm);
PageFilm := '';
end else
begin
// valorisation batchList : url + film + réalisateur
batchList.Add(PageFilm+sepchar1+Value+sepchar1+realisateur+sepchar1);
end;
end; {for filmnum}
memo.Free;
if not found and (PageNext = '') then
begin
MovieName:= UTF8Decode(MovieName);
MovieName := StringReplace(Value, '+', ' ');
LogMessage(id_Cinefil+': aucun film trouvé pour "'+ MovieName +'"');
batchList.Free;
exit;
end;
if BatchMode > 0 then
begin
// *** mode batch : recherche du meilleur poids pour les films trouvés
// 2 possibilités:
// 1) on reste avec cette liste
// 2) on continue à valoriser batchList
// pour l'instant, on travaille sur cette page uniquement
LookBest;
if bestWeight > 0 then // on a trouvé quelque chose
AnalysePageFilm(bestAddr); // page film
break; // on sort
end else
begin
// *** mode normal
if PageNext <> '' then
begin
Address := CinefilUrl + '/recherche?';
Value := Address + PageNext;
PickTreeAdd('Page suivante', Value);
if PickTreeExec(Address) then
begin
if (Address <> CinefilUrl + '/recherche?' + PageNext) and (Address <> CinefilUrl + '/recherche?' + PagePrev) then
begin
AnalysePageFilm(Address); // page film
break;
end else;
if Address = CinefilUrl + '/recherche?' + PagePrev then
PageNext := PagePrev;
PickTreeClear; // on sort
end else
LogMessage(id_Cinefil+': aucun film sélectionné');
end;
if found and (((Address <> CinefilUrl + '/recherche?' + PageNext) and (Address <> CinefilUrl + '/recherche?' + PagePrev)) or ((PagePrev = '') and (PageNext = ''))) then
begin
if PickTreeExec(Address) then
begin
AnalysePageFilm(Address); // page film
break; // on sort
end else
LogMessage(id_Cinefil+': aucun film sélectionné');
end;
end;
until (Address = '');
batchList.Free;
end;
//------------------------------------------------------------------------------
// analyse de la page du film
//------------------------------------------------------------------------------
procedure AnalysePageFilm(Address: string);
var
Table, Value, Value2, str, infos, temp, Nom, CSA, BA: string;
i, j, FormTitre: Integer;
notep, notei: Real;
memo: TStringList;
begin
FormTitre := GetOption('FormatTitre');
infos := GetPage(Address);
movieok := True; // ça y est, c'est bon
SetField(fieldURL, Address);
// mémorisation des adresses des autres pages (onglets)
// textes avec tags pour ne pas confondre avec des titres
pgacteurs := Address + '/casting';
pgba := Address + '/bande-annonce';
pgavis := Address + '/critiques';
pgphotos := Address + '/photos';
// titre original ou traduit
Value := TextBetween(infos, '', '
');
Value := Trim(TranslateText(UTF8Decode(Value), FormTitre));
Value2 := TextBetween(infos, 'Titre original : ', '
');
Value2 := TranslateText(UTF8Decode(Value2), FormTitre);
Value := FormatMovieName3(Value);
if (Value2 = '') then // 1er titre = original
begin
SetField(fieldOriginalTitle, Value);
SetField(fieldTranslatedTitle, Value);
end else
begin // traduit + original
SetField(fieldOriginalTitle, Value2);
SetField(fieldTranslatedTitle, Value);
end;
// note
notep := -1;
notei := -1;
Value := TextBetween(infos, 'Presse', '
');
Value := TextBetween(Value, '"ratingValue" content="', '">');
if Value = '' then
begin
Value := TextBetween(infos, 'Presse', '
');
Value := TextBetween(Value, 'class="c', ' greyStars');
if Value <> '' then notep := StrToFloat(Value) / 10 * 2;
end else
if Value <> '' then notep := StrToFloat(Value) * 2; // note sur 10
Value := TextBetween(infos, 'Internautes', '
');
Value := TextBetween(Value, '"ratingValue" content="', '">');
if Value = '' then
begin
Value := TextBetween(infos, 'Internautes', '
');
Value := TextBetween(Value, 'class="c', ' greyStars');
if Value <> '' then notei := StrToFloat(Value) / 10 * 2;
end else
if Value <> '' then notei := StrToFloat(Value) * 2; // note sur 10
case GetOption('Note') of
1: if notep <> -1 then SetField(fieldRating, FloatToStr(notep)); // note de la presse
2: if notei <> -1 then SetField(fieldRating, FloatToStr(notei)); // note des internautes
3: // moyenne
begin;
i := 0;
if notep = -1 then notep := 0
else i := i +1;
if notei = -1 then notei := 0
else i := i +1;
if i > 0 then SetField(fieldRating, FloatToStr((notep + notei) / i));
end;
4:
begin
if notep <> -1 then SetField(fieldRating, FloatToStr(notep));
if (notep = -1) and (notei <> -1) then SetField(fieldRating, FloatToStr(notei));
end;
end;
// réalisateur(s)
Value := TextBetween(infos, 'Un film de ', '
Distribu');
if Value = '' then
Value := TextBetween(infos, 'Un film de ', '
');
Value := FormatText(Value);
Value := StringReplace(Value, ' , ', ', ');
Value := StringReplace(Value, crlf, '');
if Value = '' then
Value := TextBetween(infos, 'itemprop="director">', '
');
if Value = '' then
Value := TextBetween(infos, '"name">', '');
SetField(fieldDirector, FormatLine(UTF8Decode(Value)));
// acteurs (principaux) (sera revalorisé si 'tous les acteurs' demandé)
Value := '';
Table := TextBetween(infos, '','
');
repeat
if Value <> '' then
Value := Value + ', ' + TextBetween(Table, '"name">','
')
else
Value := TextBetween(Table, '"name">','');
if copy(Value, length(Value)-1 , 2) = ', ' then
Value := copy(Value, 1 , length(Value)-2);
delete(Table, 1 ,pos('', Table));
until (pos('', Table)=0);
SetField(fieldActors, FormatText(UTF8Decode(Value)));
// Producteur
Value := TextBetween(infos, '');
Value := FormatLine(Value);
SetField(fieldProducer, FormatLine(Trim(UTF8Decode(Value))));
// (titre original) pays - année - durée -
Value := TextBetween(infos, '"/>',' - ',' - '); // année
SetField(fieldYear, FormatLine(Value));
Value := TextBetween(infos, '', ' '' then
begin
i := Pos('H', AnsiUpperCase(Value));
Value := IntToStr(StrToInt(Left(Value, i-1), 0) * 60 + StrToInt(Copy(Value, i+1, 2), 0));
SetField(fieldLength, Value);
end;
// genre
Value := TextBetween(infos, 'Genre : ', '
');
Value := FormatLine(UTF8Decode(Value));
if GetOption('Catégorie') = 0 then // 1 seule catégorie
begin
i := Pos(',', Value);
if i > 0 then Value := Left(Value, i-1);
end else
begin // toutes les catégories
Value := StringReplace(Value, ',', crlf); // séparer
Value := ReorderList(Value, ' , '); // et trier
end;
SetField(fieldCategory, FormatLine(Trim(Value)));
// Classification
if GetOption('Garder commentaire') = 0 then
SetField(fieldComments, '');
Value := TextBetween(infos, '
', '
');
Value := FormatLine(Value);
Value := StringReplace(Value, 'Tout public', 'Tous publics');
Value := StringReplace(Value, 'Accord Parental souhaitable', 'Accord parental');
Value := StringReplace(Value, 'Accord Parental indispensable', 'Interdit aux moins de 12 ans');
Value := StringReplace(Value, 'Interdit - 12 ans', 'Interdit aux moins de 12 ans');
Value := StringReplace(Value, 'Interdit - 16 ans', 'Interdit aux moins de 16 ans');
Value := StringReplace(Value, 'Interdit - 18 ans', 'Interdit aux moins de 18 ans');
if GetOption('Avis CSA') = 1 then
if (GetOption('Champs personnalisés') = 1) and (Value <> '') and (CheckVersion(4,0,0)) then // test s'il y a des champs personnalisés
begin
Nom := 'Avis C.S.A.';
if Nb = 0 then // Non répétition du choix lors d'une multisélection
CSA := CustomField(Nom);
if CSA <> 'Champs d''origine' then // choix en dehors des champs personnalisés
SetCustomField(CSA, Value)
else
if (CheckVersion(4,2,0)) then
SetField(fieldCertification, FormatLine(Trim(UTF8Decode(Value))))
else
if (GetField(fieldComments)<> '') and (GetOption('Garder commentaire') = 1) then
SetField(fieldComments, GetField(fieldComments) + #13#10 + FormatLine(Trim(UTF8Decode(Value))))
else
SetField(fieldComments, FormatLine(Trim(UTF8Decode(Value))));
end else
if (CheckVersion(4,2,0)) then
SetField(fieldCertification, FormatLine(Trim(UTF8Decode(Value))))
else
if (GetField(fieldComments)<> '') and (GetOption('Garder commentaire') = 1) then
SetField(fieldComments, GetField(fieldComments) + #13#10 + FormatLine(Trim(UTF8Decode(Value))))
else
SetField(fieldComments, FormatLine(Trim(UTF8Decode(Value))));
// Description
Table := TextBetween(infos, 'Synopsis', '
');
SetField(fieldDescription, FormatText3(FormatLine(UTF8Decode(Table)))+ '.');
// Bande annonce
if GetOption('Bande Annonce') = 1 then
if (GetOption('Champs personnalisés') = 1) and (CheckVersion(4,0,0)) and (pgba <> '') then // test s'il y a des champs personnalisés
begin
Nom := 'Bande Annonce';
if Nb = 0 then // Non répétition du choix lors d'une multisélection
BA := CustomField(Nom);
if BA <> 'Champs d''origine' then // choix en dehors des champs personnalisés
SetCustomField(BA, pgba)
else
Begin
if GetField(fieldComments) <> '' then
pgba := pgba + #13#10 + GetField(fieldComments);
SetField(fieldComments, pgba);
end;
end else
Begin
if GetField(fieldComments) <> '' then
pgba := pgba + #13#10 + GetField(fieldComments);
SetField(fieldComments, pgba);
end;
// test s'il y a une affiche
Value := '' ;
Value2 := TextBetween(infos, ' '') and (Importpictures = 1) then
GetPicture(Value2); //http://photos.cityvox.com/photos_gd/82/3/459602_164x225x16:22q90otop.jpg
Value2 := Textafter(Value2, 'photos_gd/'); // Nettoie le code pour récupérer les plus grandes images possibles
Value2 := Textbefore(Value2, '_', '/'); // Nettoie le code pour récupérer les plus grandes images possibles
Value2 := URLEncode('http://www.cinefil.com/PhotoCropeeAjax?numphoto=' + Value2 + '&ext=jpg&width=900&credphoto=+SND+');
infos := GetPage(Value2);
Value2 := Textbetween(infos, 'Acteurs', 'Biographie de');
Table := RemainingText;
if Value <> '' then
begin
Value2 := FormatLine(TextBetween(Value, '">', '')); // acteur
// + rôle éventuel
Value3 := TextBetween(Value, 'le dans ce film : ', '');
if Value3 <> '' then Value2 := Value2+' ('+FormatLine(Value3)+')';
memo.Add(UTF8Decode(Value2));
end
until (Value = '') or (Table = '');
memo.Text := StringReplace(memo.Text, #13#10, ', ');
if memo.Count > 0 then SetField(fieldActors, Left(memo.Text, Length(memo.Text)-4)); // sans le dernier crlf
memo.Free;
end;
//------------------------------------------------------------------------------
// extraction de l'avis des internautes
// pgavis = adresse de la page
// idavis = nom de l'onglet
//------------------------------------------------------------------------------
procedure extractAvis;
var
memo: TStringList;
Value, Value2, temp: String;
note: Real;
begin
if (GetOption('AvisInt') = 0) or (pgavis = '') or (not CanSetField(fieldComments)) then exit;
infos := GetPage(pgavis);
memo := TStringList.Create;
Value := '';
if Value <> '' then memo.Add(Value);
repeat
Value := TextBetween(infos, 'itemscope="" itemprop="review">', '
', Value) > 0 then
Value := TextBetween(infos, 'itemscope="" itemprop="review">', '
');
if pos('