Page 1 of 1

[REL][IT] Wikipedia.it

Posted: 2020-11-25 07:13:58
by fulvio53s03
New release!
L'estrazione dati per le stagioni delle serie TV non è ancora implementata.

Code: Select all

(***************************************************

Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/

[Infos]
Authors=Fulvio53s03
Title=wikipedia.it
Description=import film e serie TV
Site=http://www.wikipedia.it
Language=IT
Version=1.0
Requires=4.2.1
Comments=puo' essere usato per ricerca informazioni (mode=0) oppure per estrarle direttamente da wikipedia.it (mode=1) inserendo l'URL direttamente. |Inserire il termine (Stagione....) nel titolo tradotto riduce i risultati della ricerca (serie TV)
License=*  The source code of the script can be used in   |*  another program only if full credits to Fulvio53s03*
GetInfo=1
RequiresMovies=1

[Options]
Mode=0|0|0=normal mode|1=batch mode (url)

[Parameters]
***************************************************)
program wiki;
uses
   StringUtils7552;
   
const
   UrlBase = 'https://it.wikipedia.org';                  // base url
   bing_Base  = 'https://www.bing.com/images/search?q=';
   debug_search = false;                                   // debug mode on/off su ricerca files
   debug_film_o_serie = false;                            // debug mode on/off su estrazione dati film_o_serie
   folder = 'f:\prova\';                                  // directory where to save files
   apice  = #39;
   CRLFspace = CRLF + ' ';
   tappo_fine_ricerca = '<div class="g">Tappodifinericercadaticongoogle</div><div class="g">';    //2016-02-10
   MaxItems = 50;
var
   found: boolean;
   i, lgth_dati_album: integer;
   album, albumtest, genre: String;
   Title_album, indir_album, indir_title_album: String;
   dati_album, riga_li, init_li, end_li: String;
   strtmp: String;
   ctr_loop: integer;
   nuovo_anno, mese_anno, solo_anno, data_rilascio, label, stagione: String;
   Address, Save_address, Credit_address, Readdress, Pagestr, save_pagestr: String;
   film_o_serieName, ArtistName, firstcall, name, autori: String;
   Formato, Releases, artista: String;
   file_name, campo_URL: String;
   tipo_ricerca, pag_ricerca, save_value, ordine_lista, Salva_autore: String;
   value, episodi, lista_episodi, riquadro: string;
   CharNormal, CharAbNormal: string;
   film_o_serie_ok: boolean;
   BatchMode, giri, anno_int: Integer;
   pos_chr, lgth_file_name: Integer;
   titolo_e_autore, titolo, autore, durata, cover: String;
   pre_comments, save_comments, commento_episodi, commento_skeda: String;
   batchlog, Page: TstringList;
   save_pag, artist, initchar, endchar: string;
   film_o_serieok: boolean;
   stagione_special: string;
   init_wikinote, end_wikinote, wikinote: string;
   posizione: integer;

//------------------------------------------------------------------------------
// list of film_o_series
//------------------------------------------------------------------------------
procedure GetList;   
begin
   PickTreeClear;                                                    // clear list
   crea_lista;
   if not found then
   begin
      LogMessage('No album found for ' + file_name);
      exit;
   end;
  if PickTreeExec(Address) then
     begin
       film_o_serieName := Address;
       AnalyzeMoviePage;                                    // Album page
     end
     else
       LogMessage('No serie/film selected');
end;


procedure crea_lista;
var
position_li: integer;
length_pag_ricerca: integer;
save_riga_li: string;
begin;
//   Address := 'https://www.google.it/search?num=20&as_q=' + film_o_serieName;            //fs2017.01.30
//   Address := Address + '&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all';
//   Address := Address + '&as_sitesearch=it.wikipedia.org&as_occt=any&safe=images&as_filetype=&as_rights=';
//   Address := UrlEncode(Address);
   Address := stringreplace(film_o_serieName, ' ', '+');
   Address := 'https://it.wikipedia.org/w/index.php?search=' + Address;            //fs2017.01.30
   Address := Address + '&title=Speciale%3ARicerca&profile=advanced&fulltext=1&advancedSearch-current=%7B%7D&ns0=1';
   Page.Text := GetPage(Address);
   pagestr := Page.Text;
   PageStr := UTF8Decode(PageStr);
   Save_address := Address;
   SetField(fieldURL, Address);
   HTMLdecode(Pagestr);
   if debug_search then
      DumpPage(folder+'googleListPage.html', Pagestr);                // debug

   found := True;
//   PickTreeAdd('List of albums found for' + '"' + AlbumName + '"', '');
   file_name := 'Lista articoli trovati per  "' + film_o_seriename + '"';
   PickTreeAdd(file_name, '"');
   if debug_search then
      DumpPage(folder+'wikiList.html', Pagestr);                // debug
   if Pos('find anything', Pagestr) <> 0 then
   begin
      LogMessage('Error while reading selection page - no results found for ' + file_name);
      Found := False;
      exit;
   end;

   init_li := '<div class="searchresults mw-searchresults-has-iw">';                        //2015-11-25
   end_li  := '<div class="mw-search-visualclear">';                           //2015-11-25
   pag_ricerca := TextBetween(Pagestr, init_li, end_li) + tappo_fine_ricerca + end_li;  //elenco titoli richiesti e tappo ricerca
   if debug_search then
      DumpPage(folder+'wikiricerca.html', pag_ricerca);                // debug

// inizio pulizia wiki collaterali
//   pulisci_wiki_collaterali;
   init_wikinote := '<div id="mw-interwiki-results">';
   end_wikinote  := '<div class="g">Tappodifinericercadaticongoogle';
   wikinote := textbetween(pag_ricerca, init_wikinote, end_wikinote);
   wikinote := init_wikinote + wikinote;
   pag_ricerca := stringreplace(Pag_ricerca, wikinote, '');
   if debug_search then
      DumpPage(folder+'wikiricerca_li.html', pag_ricerca);                // debug
// fine   pulizia wiki collaterali

   init_li := 'mw-search-result';                  //2020-11-19
   end_li  := '</li>';                                          //2020-11-19
   position_li := pos(init_li, pag_ricerca);

   while position_li > 0 do          //estraggo fino al tappo di fine ricerca
      begin
      riga_li := textbetween(pag_ricerca, init_li, end_li) + end_li;
      save_riga_li := riga_li;
      riga_li := '<div>' + textbetween(riga_li, '>', 'mw-search-result-data');
      initchar := '<a href="';
      endchar  := '"';
//debug      Address  := 'xyz' + apice + '---------' + apice + 'xyz';   //per  visualizzare caratteri
      Address  := textBetween(riga_li, initchar, endchar);
      Address := UrlBase + Address;
//******************************* fin qui OK ****************************
      initchar := 'title="';
      endchar  := '"';
      Title_album  := textBetween(riga_li,initchar, endchar);              //titolo del link
      riga_li := stringReplace(riga_li, Title_album, '');
      HTMLRemoveTags(riga_li);
      Title_album := Title_album + ' - ' + copy(riga_li, 1, 80);
      PickTreeAdd(Title_Album, Address);
      found := True;

      init_li := 'mw-search-result';                  //2020-11-19
//      init_li := '<li class=' + apice + 'mw-search-result' + apice + '>';                  //2020-11-19
      end_li  := '</li>';
      pag_ricerca := stringreplace(pag_ricerca, save_riga_li, '');                                           //2020-11-19
      length_pag_ricerca := length(pag_ricerca);
      position_li := pos(init_li, pag_ricerca);
      if length(riga_li) = 0 then               //FS2020-11-23
         position_li := 0;                      //FS2020-11-23
      end;
end;

// elimina risulatati dei wiki collaterali (wikibooks, wiktionary ecc.)
procedure pulisci_wiki_collaterali;
begin
   init_wikinote := '<li class="iw-resultset"';
   end_wikinote  := '</li>';
   wikinote := textbetween(pag_ricerca, init_wikinote, end_wikinote);
   wikinote := init_wikinote + wikinote + end_wikinote;
   posizione :=  pos(init_wikinote, pag_ricerca);
   while posizione > 0 do
       begin
       pag_ricerca := stringreplace(pag_ricerca, wikinote, '');
       wikinote := textbetween(pag_ricerca, init_wikinote, end_wikinote);  //elimina note wiki da trama
       wikinote := init_wikinote + wikinote + end_wikinote;
       pag_ricerca := stringreplace(pag_ricerca, wikinote, '');
       posizione :=  pos(init_wikinote, pag_ricerca);
       end                                                          //fine   pulizia  [......]
end;

//------------------------------------------------------------------------------
// ANALYZE Movie PAGE
//------------------------------------------------------------------------------
procedure AnalyzeMoviePage;
var
   Lenght, Pays: String;
   Autore, style, Commenti, str_min, campo_note: String;
   minu, minuti, ore, lgth_comm, save_lgth_comm, i: integer;
   j: Real;
begin
   save_comments    := '';
   commento_episodi := '';
   commento_skeda   := '';
   Address := film_o_serieName;                        //2019.10.19
   estrazione_scheda;
//   if  pos('(serie_televisiva)', Address) > 0 then
//       estrazione_episodi(Address);
   if  pos('_stagione)', Address) > 0 then
       estrazione_episodi;

//fs2020-11-15   save_comments := commento_skeda + CRLF + commento_episodi;
//fs2020-11-15   SetField(fieldcomments, save_comments);     // commenti + elenco episodi           end
end;

//------------------------------------------------------------------------------
// ESTRAE LISTA EPISODI DA SCHEDA
//------------------------------------------------------------------------------
procedure estrazione_episodi;
var
   save_description, anno: String;
begin
end;
//------------------------------------------------------------------------------
// ESTRAE INFORMAZIONI DA SCHEDA
//------------------------------------------------------------------------------
procedure estrazione_scheda;
var
   save_description, anno: String;
   cancel_img: string;
   init_comments, end_comments: string;
begin
   Page.Text := GetPage(Address);
   pagestr := Page.Text;

// elimina_wikinote
   init_wikinote := '<span class="mw-editsection">';
   end_wikinote  := '</span></span>';
   wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //individua note wiki
   wikinote := init_wikinote + wikinote + end_wikinote;
   posizione :=  pos(init_wikinote, pagestr);
   while posizione > 0 do                                                       //inizio loop pulizia note [......]
       begin
       pagestr := stringreplace(pagestr, wikinote, '');
       wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //individua note wiki
       wikinote := init_wikinote + wikinote + end_wikinote;
       posizione :=  pos(init_wikinote, pagestr);
       end                                                                      //fine loop pulizia  [......]

// elimina_link interni wiki
   init_wikinote := '<sup id="cite_';
   end_wikinote  := '</sup>';
   wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //individua note wiki
   wikinote := init_wikinote + wikinote + end_wikinote;
   posizione :=  pos(init_wikinote, pagestr);
   while posizione > 0 do                                                       //inizio loop pulizia note [......]
       begin
       pagestr := stringreplace(pagestr, wikinote, '');
       wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //individua note wiki
       wikinote := init_wikinote + wikinote + end_wikinote;
       posizione :=  pos(init_wikinote, pagestr);
       end                                                                      //fine loop pulizia  [......]

// elimina_immagini destre interne al testo
   init_wikinote := '<div class="thumb tright">';
   end_wikinote  := '</div></div>';
   wikinote := textbetween(pagestr, init_wikinote, end_wikinote);
   wikinote := init_wikinote + wikinote + end_wikinote;
   posizione :=  pos(init_wikinote, pagestr);
   while posizione > 0 do
       begin
       pagestr := stringreplace(pagestr, wikinote, '');
       wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //elimina note wiki da trama
       wikinote := init_wikinote + wikinote + end_wikinote;
       posizione :=  pos(init_wikinote, pagestr);
       end                                                          //fine   pulizia  [......]

// elimina_immagini sinistre interne al testo
   init_wikinote := '<div class="thumb tleft">';
   end_wikinote  := '</div></div>';
   wikinote := textbetween(pagestr, init_wikinote, end_wikinote);
   wikinote := init_wikinote + wikinote + end_wikinote;
   posizione :=  pos(init_wikinote, pagestr);
   while posizione > 0 do
       begin
       pagestr := stringreplace(pagestr, wikinote, '');
       wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //elimina note wiki da trama
       wikinote := init_wikinote + wikinote + end_wikinote;
       posizione :=  pos(init_wikinote, pagestr);
       end                                                          //fine   pulizia  [......]

// elimina_citazioni interne al testo
   init_wikinote := '<table class="citazione-table">';
   end_wikinote  := '</table>';
   wikinote := textbetween(pagestr, init_wikinote, end_wikinote);
   wikinote := init_wikinote + wikinote + end_wikinote;
   posizione :=  pos(init_wikinote, pagestr);
   while posizione > 0 do
       begin
       pagestr := stringreplace(pagestr, wikinote, '');
       wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //elimina note wiki da trama
       wikinote := init_wikinote + wikinote + end_wikinote;
       posizione :=  pos(init_wikinote, pagestr);
       end                                                          //fine   pulizia  [......]

// elimina_formattazioni interne al testo
   init_wikinote := '<style data-mw-deduplicate=';
   end_wikinote  := '</style>';
   wikinote := textbetween(pagestr, init_wikinote, end_wikinote);
   wikinote := init_wikinote + wikinote + end_wikinote;
   posizione :=  pos(init_wikinote, pagestr);
   while posizione > 0 do
       begin
       pagestr := stringreplace(pagestr, wikinote, '');
       wikinote := textbetween(pagestr, init_wikinote, end_wikinote);  //elimina note wiki da trama
       wikinote := init_wikinote + wikinote + end_wikinote;
       posizione :=  pos(init_wikinote, pagestr);
       end                                                          //fine   pulizia  [......]

   save_pagestr := pagestr;
   SetField(fieldURL, Address);
   Pagestr := UTF8decode(Pagestr);
   HTMLdecode(Pagestr);
   if debug_film_o_serie  then
      DumpPage(folder+'wikiPageDetail.html', Pagestr);                         // debug_film_o_serie

   if (BatchMode = 0)  and (tipo_ricerca = 'sk ep') then
      SetField(fieldURL, Address);
   campo_URL := getfield(fieldurl);

   SetField(fieldDate, DateToStr(Date));
   Normalizza_Page(pagestr);
   if debug_film_o_serie  then
      DumpPage(folder+'wikiPageDetailHTMLdecode.html', pagestr);               // debug_film_o_serie
//   Page := UTF8Decode(pagestr);                                              //fs2015-01-15
   film_o_serieok := True;
   Value := Pagestr;
//fs 2017.01.28   riquadro := textbetween(Value, '<div id="mw-content-text"', '</div>');
   riquadro := textbetween(Value, '<table class="sinottico"', '</table>');        //fs 2017.01.28
   if debug_film_o_serie  then
      DumpPage(folder+'wikiriquadro.html', riquadro);

//*** titolo tradotto
   initchar := '<title>';        //fs2016-06-26
   endchar :=  '</title>';
   label := textbetween(Value, initchar, endchar);
   label := stringreplace(label, ' - Wikipedia', '');
   label := fulltrim(label);
   if getfield (fieldtranslatedTitle) = '' then
      begin
      label := fulltrim(label);
      SetField(fieldtranslatedTitle, label);
   end;
   
//*** Descrizione (trama)
   label := textbetween(value, '<h2><span class="mw-headline" id="Trama">Trama</span>', '<h2>');
   cancel_img := textbetween(label, '<div class="thumb tleft">', '</div></div>');  //elimina immagine se presente
   label := stringreplace(label, cancel_img, '');
//   cancel_img := textbetween(label, init_wikinote, end_wikinote);  //elimina "modifica" note wiki" ripetute
//   label := stringreplace(label, cancel_img, '');
       
   HTMLRemoveTags(label);
   label := fulltrim(label);
   label := stringreplace(label, (CRLF + CRLF), '');
   SetField(fielddescription, label);
   save_description := Label;

//*** commento (descrizione generale)
   init_comments := '<span class="mw-headline" id="Produzione">Produzione</span>';
   end_comments  := '<span class="mw-headline" id="Note">Note</span>';
   commento_skeda := textbetween(pagestr, init_comments, end_comments);
   if length(commento_skeda) = 0 then
      begin
      end_comments  := '<span class="mw-headline" id="Altri_progetti">Altri progetti</span>';
      commento_skeda := textbetween(pagestr, init_comments, end_comments);
      end;
      
   HTMLRemoveTags(commento_skeda);
   commento_skeda := fulltrim(commento_skeda);
   setField(fieldcomments, commento_skeda);

//   *** dati estratti dal riquadro sinottico ***
//*** country
   initchar := '>Paese';      endchar :=  '</tr>';
   label := TextBetween(riquadro, initchar, endchar);
   HTMLRemoveTags(label);
   label := stringReplace(label, 'di produzione', '');
   label := stringReplace(label, 'Stati Uniti d''America', 'USA');
   label := fulltrim(label);
   SetField(fieldcountry, label);

   pagestr := save_pagestr;
   Findcover;

//*** Titolo Originale
   label := textbetween(riquadro, '>Titolo originale<', '</td>');
   initchar := '<td';           endchar :=  '</td>';
   label := initchar + textbetween(label, initchar, '</i>');
   label := FormatText(label);
   SetField(fieldoriginalTitle, label);

//*** genere
   initchar := '>Genere<';
   label := textbetween(riquadro, initchar, '</tr>');
   initchar := '<td';           endchar :=  '</td>';
   label := initchar + textbetween(label, initchar, endchar);
   HTMLRemoveTags(label);
   label    := AnsiMixedCase(AnsiLowerCase(label), ' ');
   SetField(fieldcategory, label);

//*** regia
   initchar := '>Regia</a>';     endchar :=  '</td>';
   label := TextBetween(riquadro, initchar, endchar);
   HTMLRemoveTags(label);
   label := FormatText(label);
   SetField(fieldDirector, label);

//*** personaggi e interpreti
   initchar := '<ul>';
   endchar :=  '</ul>';
   label := initchar + TextBetween(riquadro, initchar, endchar) + endchar;
   initchar := '<li>';
   label := initchar + TextBetween(riquadro, initchar, endchar) + endchar;
   HTMLRemoveTags(label);
   SetField(fieldactors, label);

//*** anno
   anno := textbetween (riquadro, '<th style="">Anno</th>', '</tr>');
   anno := stringReplace(anno, '– in produzione', ' ');
   HTMLRemoveTags(anno);
   anno := fulltrim(anno);
   if pos('-', anno) > 0 then      //serie in corso
      anno := textbefore(anno, '-', '');
   if anno = '' then                     //serie animazione
      begin
      anno := textbetween (riquadro, 'TV</th>', '</tr>');
      HTMLRemoveTags(anno);
      anno := fulltrim(anno);
      end;
   SetField(fieldyear, anno);
   anno:= getfield(fieldyear);
   if anno = '' then                     //serie animazione
      begin
      anno := textbetween (riquadro, '<span title="italiana">it.</span>', '</tr>');
      HTMLRemoveTags(anno);
      anno := fulltrim(anno);
      end;
   SetField(fieldyear, anno);

//*** produttore
   initchar := '>Casa di produzione<';    endchar:= '</tr>';
   label := textbetween(riquadro, initchar, endchar);
   label := '<' + stringReplace(label, '<br />', ', ');
   HTMLRemoveTags(label);                        //   label := stringReplace(label, ' - in produzione', '');
   SetField(fieldproducer, label);

//*** writer (ideatore della serie TV)  -  soggetto (film)
   initchar := '>Soggetto';                   //film
   label := textbetween(value, initchar, '</tr>');
//   label := textbetween(label, '<td>', '</td>');
   HTMLRemoveTags(label);
   SetField(fieldwriter, label);
   if label = '' then
      begin
      initchar := '<th>Ideatore</th>';           //serie
      label := textbetween(value, initchar, '</tr>');
//    label := textbetween(label, '<td>', '</td>');
      HTMLRemoveTags(label);
      SetField(fieldwriter, label);
   end;

//*** compositore
   initchar := '>Musiche';    endchar:= '</tr>';
   label := textbetween(riquadro, initchar, endchar);
   label := '<' + stringReplace(label, '<br />', ', ');
   HTMLRemoveTags(label);                        //   label := stringReplace(label, ' - in produzione', '');
   SetField(fieldcomposer, label);

end;

Procedure Normalizza_page(Pagina: string);    // elimina i crlf, trasforma delimiters maiuscoli in minuscoli
begin
  pagina := RegExprSetReplace('<([^>]+)>', pagina, '<\L\1>', true);
  CharAbNormal := crlf;   CharNormal := ' ';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<B';   CharNormal := '<b';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</B';  CharNormal := '</b';
  pagina := StringReplace(Value, CharAbNormal, CharNormal);
  CharAbNormal := '<FONT';  CharNormal := '<font';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</FONT';   CharNormal := '</font';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<TR';   CharNormal := '<tr';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</TR';   CharNormal := '</tr';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<TD';     CharNormal := '<td';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</TD';    CharNormal := '</td';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<DIV';   CharNormal := '<div';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</DIV';   CharNormal := '</div';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '<Ol';    CharNormal := '<ol';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
  CharAbNormal := '</Ol';   CharNormal := '</ol';
  pagina := StringReplace(pagina, CharAbNormal, CharNormal);
//  >modifica wikitesto<
end;

//------------------------------------------------------------------------------
// set show warning (normal mode) or add to log (batch mode)
//------------------------------------------------------------------------------
procedure LogMessage(m: string);
begin
   if BatchMode > 0 then
      AddToLog('item '+GetField(fieldNumber)+': '+m)
   else
      ShowWarning(m);
end;

//------------------------------------------------------------------------------
// add a message in the batch log and save to disk
// (because I don't know when it's finished...)
//------------------------------------------------------------------------------
procedure AddToLog(m: string);
begin
//fs2016-12-31    batchlog.Add(m);
//fs2016-12-31    batchlog.SaveToFile(batchlogfic);
end;

//------------------------------------------------------------------------------
// process batch mode
//------------------------------------------------------------------------------
procedure wikiBatch;
var
   pos_url: integer;
begin
   film_o_serieName := GetField(fieldUrl);                      // if no url or another site then ignore
   pos_url := Pos(UrlBase, film_o_serieName);
   if pos_url = 0 then
      begin
      film_o_serieName := stringreplace(film_o_serieName, 'http://', 'https://');
      pos_url := Pos(UrlBase, film_o_serieName);
      end;
   if (film_o_serieName <> '') and (pos_url > 0) then
      AnalyzeMoviePage
   else
      LogMessage('ignored url="'+film_o_serieName+'"');
end;   

//------------------------------------------------------------------------------
// process normal mode
//------------------------------------------------------------------------------
procedure wikiNorm;
begin
   file_name:= getField(fieldfilepath);
   if (GetField(fieldTranslatedTitle) <> '') then
      film_o_serieName := GetField(fieldTranslatedTitle)          // get film_o_serie name
   else
      film_o_serieName := GetField(fieldOriginalTitle);							//mrobama           
   if film_o_serieName = '' then
      film_o_serieName := file_name;
   repeat
      if not Input('cerca: ' + film_o_serieName, 'Scrivi il nome del film o della serie:'
          + crlf, film_o_serieName) or (film_o_serieName = '') then exit;
      formato := getfield(FieldOriginalTitle);
      GetList;
   until film_o_serieok;
end;

procedure FindCover;
var
  pict_dim: Double;
  Page_cover: TStringList;
  trova_cover, cover_ok, url_img, new_url_img, commenti: string;
  pos_locandina, lgth_comm: integer;
  locandina_da: string;
begin                    // Picture
  Page_cover := TStringList.Create;
  url_img := '';
  new_url_img := '';
  cover_ok := 'no';
  pict_dim := 0;
  save_pagestr := pagestr;
  locandina_da := 'Locandina: ';


//AntonioGenna
  initchar := 'https://www.antoniogenna.net/';
  strtmp := TextBetween(Pagestr, initchar, '">');
  if length(strtmp) > 0   then
    begin
    strtmp := initchar + strtmp;
    pagestr := getpage(strtmp);
    if debug_film_o_serie then
       DumpPage(folder+'Antonio_Genna.html', Pagestr);                // debug
    pos_locandina := pos('alt="Il mondo dei doppiatori - Zona Cinema', pagestr);           //film
    if pos_locandina = 0 then
       pos_locandina := pos('alt="Il mondo dei doppiatori - Zona Animazione"', pagestr);        //animazione
    if pos_locandina > 0 then
       begin
       strtmp := stringreplace(strtmp, '.html', '.jpg');         //eventuali cambi html <---> htm
       strtmp := stringreplace(strtmp, '.htm', '.jpg');
       url_img := locandina_da + strtmp;
       GetPicture (strTmp);
       Pict_dim	 := GetPictureSize;
       if Pict_dim > 22000  then
          cover_ok := 'yes_AntonioGenna';
       end;
       pagestr := save_pagestr;
    end

//IMDB
  if cover_ok = 'no' then
    begin
    initchar := 'https://www.imdb.com/';
    strtmp := TextBetween(Pagestr, initchar, '">');
    if length(strtmp) > 0   then
      begin
      strtmp := initchar + strtmp;
      pagestr := getpage(strtmp);
      if debug_film_o_serie then
         DumpPage(folder+'IMDB.html', Pagestr);                // debug
      pos_locandina := pos('<div class="poster">', pagestr);   // cerco sulla pagina IMDB
      if pos_locandina > 0 then
         begin
         strtmp := TextBetween(pagestr, '<div class="poster">', '<img alt="');
         strtmp := TextBetween(strtmp, '<a href="/', '"');
         strtmp := initchar + strtmp;
         pagestr := getpage(strtmp);            //pagina della locandina grande
         strtmp := TextBetween(Pagestr, '<meta property="og:image" content="', '"/>');
         url_img := locandina_da + strtmp;
         GetPicture (strTmp);
         Pict_dim	 := GetPictureSize;
         if Pict_dim > 22000  then
            cover_ok := 'yes_IMDB';
         end;
       pagestr := save_pagestr;
    end;
  end

//*** cover       locandina da wikipedia  ------------------
  if cover_ok = 'no' then
    begin
    url_img := locandina_da + getfield(fieldUrl);
    pagestr := save_pagestr;
    cover := 'https:' + TextBetween(riquadro, 'src="', '"');
//    if cover <> 'http:' then
    cover := StringReplace(cover, 'http:', 'https:');
    if length(cover) > length('https:') then
       GetPicture(cover);
    if Pict_dim > 4000  then
       cover_ok := 'yes_Wiki';
//       end;
  end;

//   cancel_img := '123456781234567812345678';                  //Prova
//   cancel_img := stringreplace(cancel_img, '1', '   ');       //tutte le ricorrenze sono modificate!

  if url_img <> '' then
     begin
     commenti := getfield(fieldcomments);
     if pos(locandina_da, commenti) > 0 then
        commenti := textbefore(commenti, (locandina_da + 'https://'), '');   // evito doppio indirizzo locandina nel caso di
                                                                          // aggiornamento informazioni
     lgth_comm := length(commenti);
     if commenti <> '' then
        commenti := pre_comments + CRLF + commenti + CRLF + url_img;
     if commenti = '' then
        commenti := pre_comments + CRLF + url_img;
     if pos(CRLF, commenti) = 1 then
        delete(commenti, 1, 1);
     commenti := fulltrim(stringreplace(commenti, (CRLF + CRLF), CRLF));
     commenti := fulltrim(stringreplace(commenti, (CRLF + CRLF), CRLF));
     setfield(fieldcomments, commenti);
     end
end;
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//  start here
//------------------------------------------------------------------------------                                             
begin
      if not CheckVersion(4,2,1) then
      begin
         ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 4.2.1)');
         exit;
      end;   
// get user's parms (used more than once)
      BatchMode := GetOption('Mode');
      Page := TStringList.Create;
// *********************************************************************
      if BatchMode = 1 then                                
          wikiBatch;
      if BatchMode = 0 then
          wikiNorm;

end.

Re: [REL][IT] Wikipedia.it

Posted: 2020-11-27 07:16:21
by antp
Thanks