', '
');
// réalisateur(s)
Value := TextBetween(memo.GetString(6), 'Un film de : ', '');
if Value = '' then
Value := TextBetween(memo.GetString(7), 'Un film de : ', '');
SetField(fieldDirector, UTF8Decode(FormatLine(Value)));
// acteurs (principaux) (sera revalorisé si 'tous les acteurs' demandé)
Value := Textafter(memo.GetString(6), 'Avec :');
Value := StringReplace(Value, '...', ''); // supprime les points de suspension
Value := StringReplace(Value, #13#10, ', ');
SetField(fieldActors, FormatText(UTF8Decode(Value)));
// (titre original) pays - année - durée -
Value := memo.GetString(4);
Value := TextBefore(Value, ' - ', ''); // pays
Value := StringReplace(Value, 'Us', 'USA');
Value := StringReplace(Value, 'Etats-Unis', 'USA');
Value := StringReplace(Value, 'Americain', 'USA');
Value := StringReplace(Value, 'Fr', 'France');
Value := StringReplace(Value, 'Franceance', 'France');
SetField(fieldCountry, UTF8Decode(FormatLine(Value)));
Value := RemainingText;
Value := TextBefore(Value, ' - ', ''); // année
SetField(fieldYear, FormatLine(Value));
Value := RemainingText;
if pos('-', Value) > 0 then
Value := TextBefore(Value, ' - ', ''); // durée heuresHminutes
if Value <> '' 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(memo.GetString(4), 'Genre : ', '
');
Value := UTF8Decode(FormatLine(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(UTF8Decode(Value))));
// Classification
Value := TextBetween(memo.GetString(4), '
', '
');
if (Value = '') and (pos('Genre', memo.GetString(4))= 0)then
Value := copy(TextBefore(memo.GetString(4), '
', ' - '), 5, Length(TextBefore(memo.GetString(5), '
', ' - '))); // durée heuresHminutes
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');
SetField(fieldComments, FormatLine(Trim(UTF8Decode(Value))));
// Producteur
Value := memo.GetString(8);
Value := TextBetween(memo.GetString(8), ' par : ', '
');
Value := FormatLine(Value);
SetField(fieldProducer, FormatLine(Trim(UTF8Decode(Value))));
// Description
Table := TextBetween(infos, '
SYNOPSIS', '
');
Table := TextBetween(Table, '
', '
');
if Table = '' then
begin
Table := TextBetween(infos, '
', '
');
Table := TextBetween(Table, '
', '...');
end;
if Table = '' then
begin
Table := TextBetween(infos, '
', '
', '');
end;
SetField(fieldDescription, FormatText3(UTF8Decode(FormatLine(Table)))+ '.');
// synthése Cinéfil
Table := Textbetween(infos, '
', '
');
if Table <> '' then
begin
Table := TextAfter(Table, '
'); // sauter l'entete
if GetField(fieldComments) <> '' then
temp := GetField(fieldComments) + #13#10;
SetField(fieldComments, temp + FormatText3(UTF8Decode(Table)));
end
// traitement des autres pages, donc revalorisation de entete, onglets et infos
// test s'il y a une affiche
Value := '' ;
Value2 := TextBetween(infos, '
'') and (Importpicture > 0) then
begin
// affiche: selon le mode demandé
if (Value2 <> '') and (Importpicture = 1) then
begin
// grand format demandé: 1ere image de l'onglet Photos
if Value2 <> '' then
begin
Value := StringReplace(Value2, 'grand', '400');// ident photo
if Value <> '' then
GetPicture(Value);
end;
end;
if Value = '' then
GetPicture(Value2);
end; {ImportPicture > 0}
extractActeurs; // liste complète acteurs
extractAvis; // avis de la presse
end;
//------------------------------------------------------------------------------
// extraction de la liste complète des acteurs
// pgacteurs = adresse de la page
// idacteurs = nom de l'onglet
//------------------------------------------------------------------------------
procedure extractActeurs;
var
memo: TStringList;
Table, Value, Value2, Value3: String;
begin
if (GetOption('Acteurs') = 0) or (pgacteurs = '') or (not CanSetField(fieldActors)) then exit;
infos := GetPage(pgacteurs);
memo := TStringList.Create;
Table := TextBetween(infos, '
Acteurs
', '
');
repeat
Value := TextBetween(Table, '
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 de la presse
// pgavis = adresse de la page
// idavis = nom de l'onglet
//------------------------------------------------------------------------------
procedure extractAvis;
var
memo: TStringList;
Value, Value2, temp: String;
note: Real;
begin
if (GetOption('AvisPresse') = 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, '>
', '');
infos := RemainingText;
if Value <> '' then
begin
if memo.Count > 0 then memo.Add(#13#10);
memo.Add(FormatText3(UTF8Decode(Value)));
// note (sur 5 par demi-point)
Value2 := TextBetween(Value, '
');
if Value2 <> '' then
begin
note := StrToFloat(Value2) * 2 / 10; // note sur 10
memo.Add('Note: '+FloatToStr(note));
end
end
until (Value = '') or (infos = '');
memo.Text := StringReplace(memo.Text, #13#10 + ' ', #13#10);
memo.Text := StringReplace(memo.Text, #13#10 + ' ', #13#10);
memo.Text := StringReplace(memo.Text, #13#10#13#10, #13#10);
if memo.Count > 0 then
begin
if GetField(fieldComments) <> '' then
temp := GetField(fieldComments) + #13#10#13#10;
SetField(fieldComments, temp + Left(memo.Text, Length(memo.Text)-2)); // sans le dernier crlf
end;
memo.Free;
end;
//------------------------------------------------------------------------------
// formatage texte spécial
//------------------------------------------------------------------------------
function FormatText3(str: string) :string;
begin
// break = crlf
str := StringReplace(str, '
', crlf);
str := StringReplace(str, '
', crlf);
// formattage 'classique'
result := FormatText(str);
end;
//------------------------------------------------------------------------------
// formatage du nom du film
//------------------------------------------------------------------------------
function FormatMovieName3(str: string) :string;
begin
// une petite édition avant de formater
str := StringReplace(str, ' & ', ' et ');
// remplacer les apostrophes, tirets et points par des blancs
str := StringReplace(str, '''', ' ');
str := StringReplace(str, '.', ' ');
str := StringReplace(str, '.', ' ');
str := StringReplace(str, ',', ' ');
str := StringReplace(str, ':', ' ');
result := FormatMovieName(str);
end;
//------------------------------------------------------------------------------
// Vérifie s'il existe une nouvelle version du script
// et propose de la télécharger
//------------------------------------------------------------------------------
procedure CheckScriptVersion();
var
Page, Script: TStringList;
Line, ScriptsDirectory, FileName, ScriptText, Fich: string;
LineNr, BeginPos, EndPos: Integer;
CurrentVersion, NewVersion: real;
begin
Page := TStringList.Create;
FileName := UrlEncode(ScriptName);
FileName := UrlEncode(SiteUrl) + FileName;
FileName := StringReplace(FileName, '%2E', '.');
FileName := StringReplace(FileName, '+', '%20');
FileName := StringReplace(FileName, '%3A', ':');
FileName := StringReplace(FileName, '%2F', '/');
Page.Text := GetPage(FileName);
ScriptsDirectory := GetStatic('path');
//SetStatic('path', ScriptsDirectory);
LineNr := FindLine('Version=', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('Version=', Line) + 8;
EndPos := pos(' du', Line);
CurrentVersion := StrToFloat(copy(VersionScript, 1, pos('du', VersionScript) - 2));
NewVersion := StrToFloat(copy(Line, BeginPos, EndPos - BeginPos));
if (NewVersion > CurrentVersion) then
begin
if ShowConfirmation('Une nouvelle version du script est disponible : ' + copy(Line, BeginPos, EndPos - BeginPos)+ #13#10#13#10 + '- Cliquez sur ''''Oui'''' pour effectuer la mise à jour.' + #13#10#13#10 + '- Cliquez sur ''''Non'''' dans le cas contraire.') = True then
begin
FileName := ScriptName;
Sleep(500);
ScriptText := Page.Text;
Script := TStringList.Create;
Script.Add(ScriptText);
FileName := StringReplace(FileName, '%20', ' ');
Script.SaveToFile(ScriptsDirectory + FileName);
ShowInformation('Vous avez mis à jour le script, quitter la fenêtre de scripts et relancez la.');
Script.Free;
end;
end else
end;
end;
//------------------------------------------------------------------------------
// traitement mode batch
//------------------------------------------------------------------------------
procedure CinefilBatch;
begin
SetField(fieldChecked, ''); // init film en traitement
initBatchLook; // test et init
if batchLookOK then
begin;
case BatchMode of
1: AnalysePageFilm(GetField(fieldUrl)); // recherche par url
2:
begin;
MovieName := GetMovieName;
AnalysePage; // recherche par nom
end;
end; {case}
if movieok then
SetField(fieldChecked, 'x'); // film ok
end;
// on attend un peu pour ne pas stresser le site et pouvoir arrêter le script
Sleep(500);
end;
//------------------------------------------------------------------------------
// traitement mode normal
//------------------------------------------------------------------------------
procedure CinefilNorm;
begin
MovieName := GetMovieName;
repeat
if not Input('cinefil.com Import', 'Entrez le titre du film', MovieName) or (MovieName = '') then exit;
AnalysePage;
until movieok;
end;
//------------------------------------------------------------------------------
// c'est ici que ça commence
//------------------------------------------------------------------------------
begin
if batchAbort <> '' then exit; // mode batch non confirmé
if firstcall <> 'done' then
begin
// 1er appel: init paramètres
firstcall := 'done';
if not CheckVersion(3,5,0) then
begin
ShowMessage('Ce script requiert une version plus récente de Ant Movie Catalog (au moins la version 3.5.0)');
batchAbort := 'y';
exit;
end;
batchCaller := id_Cinefil; // identifiants Cinefil
batchUrl := CinefilUrl;
batchField2 := fieldDirector;
// récupère les variables user (utilisées plus d'une fois)
BatchMode := GetOption('Mode');
ImportPicture := GetOption('Affiche');
if not CanSetPicture then
ImportPicture := 0; // champ image non modifiable: inutile de lire
//
if BatchMode > 0 then // mode batch: confirmer le choix
begin
initBatchLog('FR'); // init log
if batchAbort <> '' then exit;
end;
end;
// c'est parti
PMaj := PMaj+ 1;
movieok := False;
Maj := 0;
if (GetOption('Mise à jour du Script') = 1) and (PMaj = 1) then
begin
CheckScriptVersion();
if Maj = 1 then exit;
end;
if BatchMode = 0 then
CinefilNorm
else
CinefilBatch;
end.