(*************************************************** 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=4.7 du 16/02/2010 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 [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) Affiche=1|2|0=aucune affiche|1=affiche grand format|2=affiche petit format Acteurs=1|0|0=les acteurs principaux|1=tous les acteurs Catégorie=1|0|0=1ère catégorie seule|1=toutes les catégories Note=3|1|0=Aucune|1=presse|2=internautes|3=moyenne|4=Presse sinon celle des internautes AvisPresse=1|0|0=aucun avis|1=avis (presse) FormatTitre=3|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 ***************************************************) // nécessite les modules suivants // BatchCommon7552.pas (qui inclut StringUtils1.pas et StringUtils7552.pas) // utilisation de BatchCommon7552.pas program cinefil; uses BatchCommon7552; const debug = False; // mode debug on/off debugrep = 'c:\temp\'; // répertoire de stockage des fichiers // CinefilUrl = 'http://cinefil.com'; id_Cinefil = 'Cinefil'; // ident VersionScript = '4.7 du 16/02/2010'; ScriptName = 'Cinefil (FR).ifs'; SiteUrl = 'http://joel.desseaux.free.fr/Cinefil/'; var // note FormatUTF8 est déclaré dans StringUtils7552 (integer) movieok, pageko: Boolean; MovieName, firstcall, entete, onglets, infos: String; pgacteurs, idacteurs, pgavis, idavis, pgphotos, idphotos: String; ImportPicture, Maj, PMaj : 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 := TextBefore(CinefilUrl, '.com', '') + '.antisearch.net/cgi-bin/findall?'; PickTreeClear; // init list PickTreeAdd('Films (Cinéfil)', ''); found := False; repeat pagenum := pagenum + 1; // 1er appel, postpage // suivants getpage (pagenext/pageprev) begin if pagenum = 1 then begin MovieName := UrlEncode(FormatMovieName3(MovieName)); //MovieName := UTF8Encode(StringReplace(MovieName, '+', ' ')); Page := PostPage(Address, 'C=168&KEYWORDS=' + MovieName + '&SORT_ORDER=affiche|DESC&versionFILTER=') end else Page := GetPage(PageNext); PageNext := ''; PagePrev := ''; //Address :=TextBetween(Page, 'Aucune réponse', TextBefore(Page, '', '')) > 0) and not found then begin Page := ''; // rien du tout LogMessage(id_Cinefil+': aucun film trouvé pour "'+MovieName+'"'); batchList.Free; exit; end; Temp := Textafter(Page, '

Film'); // infos utiles if Temp <> '' then Page := Temp; if Temp <> '' then begin if Pos('>Plus de réponses', Page) > 0 then begin Page := PostPage(Address, FormatLine(TextBetween(Page, 'Plus de réponses'))); Page := Textafter(Page, '

Film' ); // infos utiles end; end; // tester ici s'il existe des pages next et prev PageNext := (TextBetween(Page, '
', 'class="texte_pages"')+'>'); if PageNext <> '' then PageNext := GetUrl(PageNext, '<', 'http://cinefil.antisearch.net/cgi-bin/'); PagePrev := (TextBetween(Page, '
', 'class="texte_pages"')+'>'); if PagePrev <> '' then PagePrev := GetUrl(PagePrev, '<', 'http://cinefil.antisearch.net/cgi-bin/'); if PageNext ='>' then PageNext ='' if PagePrev ='>' then PagePrev ='' // if PagePrev <> '' then // PickTreeAdd('<<< page précédente', PagePrev); // mémo des films de cette page urlfilm := 'href="'; if Pos('

Film', Page) > 0 then Page := TextBetween(Page, '

Film', '
', crlf); memo := TStringList.Create; memo.Text := Page; for filmnum := 0 to memo.Count -1 do begin Line := memo.GetString(filmnum); PageFilm := GetUrl(Line, urlfilm, CinefilUrl); if PageFilm = '' then continue; // pas d'url = autre chose ou ligne vide // extraire le nom et le réalisateur Value := FormatLine(TextBetween(Line, '">', '')); // titre realisateur := FormatLine(TextBetween(Line, 'de :', 'Avec :')); if realisateur = '' then realisateur := FormatLine(TextBetween(Line, 'class="texteVif">', '')); Line := Value + ' - ' + realisateur; if BatchMode = 0 then PickTreeAdd(Line, PageFilm) else begin // valorisation batchList : url + film + réalisateur batchList.Add(PageFilm+sepchar1+Value+sepchar1+realisateur+sepchar1); end; found := True; end; {for filmnum} memo.Free; if PageNext <> '' then Address := PageNext; // PickTreeAdd('>>> page suivante', PageNext); if not found and (PageNext = '') then begin 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 = '') and (PagePrev <> '')) or ((PageNext = '') and (PagePrev = '') and found) 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: string; i, j, FormatTitre: Integer; notep, notei: Real; memo: TStringList; begin FormatTitre := 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'; pgavis := Address + '/critiques-presse'; // titre original ou traduit Value := TextBetween(infos, '

', '

'); Value := TranslateText(FormatLine(Value), FormatTitre); Value2 := TextBetween(infos, 'Titre original : ', '
'); Value2 := TranslateText(FormatLine(Value2), FormatTitre); if (Value2 = '') then // 1er titre = original begin SetField(fieldOriginalTitle, UTF8Decode(Value)); SetField(fieldTranslatedTitle, UTF8Decode(Value)); end else begin // traduit + original SetField(fieldOriginalTitle, UTF8Decode(Value2)); SetField(fieldTranslatedTitle, UTF8Decode(Value)); end; // note notep := -1; notei := -1; Value := TextBetween(infos, 'Presse', ''); Value := TextBetween(Value, '
'' then notep := StrToFloat(Value) * 2 / 10; // note sur 10 Value := TextBetween(infos, 'CityReporters', ''); Value := TextBetween(Value, '
'' then notei := StrToFloat(Value) * 2 / 10; // 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; // extraire les lignes: memo := TStringList.Create; memo.Text := TextBetween(infos, '
', '
'); if memo.Text = '' then memo.Text := TextBetween(infos, '
', '
'); // 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.