[REL] [ITA] TrovaCinema Repubblica

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
mrobama
Posts: 85
Joined: 2009-04-03 12:34:34

[REL] [ITA] TrovaCinema Repubblica

Post by mrobama »

This is my first release and I have few minutes to do it. I hope you enjoy it.
Note: this release works fine with http, so you don't have to wait for next ANT release ...

By the way, if you have KwCinema.ifs in your scripts directory, you can delete it. "KwCinema" is dead and it redirects to "TrovaCinema Repubblica".

Code: Select all

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

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

[Infos]
Authors=MrObama (2018)
Title=TrovaCinema Repubblica
Description=Get movie info from TrovaCinema Repubblica
Site=http://trovacinema.repubblica.it
Language=IT
Version=1.0.0 - 17.02.2018
Requires=4.2.1
Comments=**First release**
License=*  The source code of the script can be used in   |*  another program only if full credits to              |*  script author and a link to Ant Movie Catalog  |*  website are given in the About box or in       |*  the documentation of the program               |
GetInfo=1
RequiresMovies=1

[Options]

[Parameters]

***************************************************)

program TrovaCinemaRepubblicaIt;

uses
  Stringutils7552;

var
  MovieNameInput: string;

const
  PATHLOG = 'c:\ProgramData\Ant Movie Catalog\Log\TrovaCinema\';

// --------------------------------------------------

// Analizza la pagina e ricava i dati
procedure AnalyzeFilmPage(htmlPage: string);
var
  json, value: string;
begin

// Titoli
  json := TextBetween(htmlPage, '<script type="application/ld+json">', '</script>');
  value := UTF8Decode(TextBetween(json, '"name": "', '"'));
  if value <> '' then SetField(fieldTranslatedTitle, value);
  if value <> '' then SetField(fieldOriginalTitle, value);
  value := TextBetween(json, '"url": "', '"');
  if value <> '' then SetField(fieldURL, value);
  value := TextBetween(json, '"director"', '}');
  value := UTF8Decode(TextBetween(value, '"name": "', '"'));
  if value <> '' then SetField(fieldDirector, value);
  value := TextBetween(json, '"image"', '}');
  value := TextBetween(value, '"url": "', '"');
  GetPicture(value);
  value := UTF8Decode(RemoveHTML(FullTrim(TextBetween(htmlPage, '<span class="mm-weight-500">Con</span>', '<span class="mm-weight-500">'))));
  if value <> '' then SetField(fieldActors, value);
  value := RemoveHTML(trim('<' + TextBetween(htmlPage, '<span class="mm-weight-500">Anno</span>: <', '<')));
  if value <> '' then SetField(fieldYear, value);
  value := UTF8Decode(FullTrim(RemoveHTML(TextBetween(htmlPage, '<div class="schedine-separa"></div>', '<div class="mm-container">'))));
  if value <> '' then SetField(fieldDescription, value);
  value := UTF8Decode(trim(TextBetween(htmlPage, '<span class="mm-weight-500">Nazione</span>:', '</li>')));
  if value <> '' then SetField(fieldCountry, value);
  value := trim(TextBetween(htmlPage, '<span class="mm-weight-500">Durata</span>: ', ' '));
  if value <> '' then SetField(fieldLength, value);
  value := TextBetween(htmlPage, '<li><span class="mm-weight-500">Titolo originale', '/li>');
  if value <> '' then
    begin
      value := UTF8Decode(trim(TextBetween(value, '>:', '<')));
      if value <> '' then SetField(fieldOriginalTitle, value);
    end;
  value := UTF8Decode(trim(TextBetween(htmlPage, '<span class="mm-weight-500">Produzione</span>:', '</li>')));
  if value <> '' then SetField(fieldProducer, value);
  value := UTF8Decode(RemoveHTML(trim(TextBetween(htmlPage, '<span class="mm-weight-500">Genere</span>:', '</a>'))));
  if value <> '' then SetField(fieldCategory, value);
end;


// Analizza il contenuto della pagina con i risultati di ricerca
procedure AnalyzeResultPage(MovieName: string);

var
  strPage, strHtmlMovie, MovieAddr, MovieTitle : string;
  TagPos: Integer;

begin
  // Riceve la pagina
  MovieAddr := 'http://trovacinema.repubblica.it/cerca/archivio/?dove=film&cosa='+ UrlEncode(MovieName);
  strPage := GetPage(MovieAddr);

  TagPos:= Pos('<span class="ucase">Cerca su TrovaCinema</span>', strPage);
  if TagPos > 0 then
    begin
      ShowMessage('Film non trovato !');
      exit;
    end;

  // Controllare che ci siano film o se siamo stati rediretti sulla pagina dell'unico film trovato
  TagPos:= Pos('<span>Risultato ricerca</span>', strPage);
  if (TagPos < 1) then AnalyzeFilmPage(strPage) // Ha trovato un unico film e sono già nella pagina di quel film
  else  // Lista di film
    begin
      PickTreeClear;
      PickTreeAdd('Risultati ricerca per "' + MovieName + '":', '');

      strPage := TextBetween(strPage, '<span>Risultato ricerca</span>', '</html>') + '</html>';
      TagPos := Pos('<div class="clear5"></div>', strPage);
      while TagPos > 0 do
        begin
          strHtmlMovie := TextBetween(strPage, 'href=', '<div class="clear5">');
          strPage := TextBetween(strPage, '<div class="clear5"></div>', '</html>') + '</html>';
          MovieAddr := TextBetween(strHtmlMovie, '"', '"');
          MovieTitle := trim(TextBetween(strHtmlMovie, '<div class="mm-left titolo-accordion">', '</div>'));

          // Add to listbox
          PickTreeAdd(MovieTitle, MovieAddr);

          // Restart the process
          TagPos := Pos('<div class="clear5"></div>', strPage);
        end;

      // Visualizza la lista e fa scegliere
      if (PickTreeExec(MovieAddr)) then
        begin
          strPage := GetPage(MovieAddr);
          AnalyzeFilmPage(strPage);
        end;
    end;
end;

// -------------------- main

begin
  if (CheckVersion(4,2,1)) and (StringUtils1_Version > 5) then
    begin
      MovieNameInput := GetMovieName();
      Input('TrovaCinema Import', 'Titolo del film:', MovieNameInput);
      if MovieNameInput <> '' then AnalyzeResultPage(MovieNameInput);
    end
  else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 4.2.1) and StringUtils1 version 6');
end.
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Re: [REL] [ITA] TrovaCinema Repubblica

Post by fulvio53s03 »

Provato con 3 titoli (Hondo, zombi, freezer) e funziona bene.
peccato che il sito trovacinema sia abbastanza scarno di informazioni (solo uno dei tre film conteneva l'elenco degli attori).
in compenso, nei due casi "senza attori" rimanda a mymovies.
Una volta modificato l'Agente di AMC intendi implementare lo script ?
grazie, mrobama.
:)
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Re: [REL] [ITA] TrovaCinema Repubblica

Post by antp »

Thanks, I added it and deleted the old KwCinema.
mrobama
Posts: 85
Joined: 2009-04-03 12:34:34

Re: [REL] [ITA] TrovaCinema Repubblica

Post by mrobama »

@fulvio53s03: vediamo se riesco a trovare un po' di tempo per farlo, ma dovrebbe essere semplice ...

Sto pensando ad un workaround per il problema dell'https in attesa della soluzione. E' una soluzione basata su un proxy. Ho provato simpleproxy ma sembra implementare volutamente sistemi che ne complichino l'utilizzo da script. Se metto su un file php che fa il giochino e te lo passo, tu avresti dove caricarlo su qualche hosting gratuito?

Provo a essere più dettagliato. Il file si chiamerebbe, ad esempio, proxy.php e sarebbe molto elementare (a meno dell'aggiunta di qualche controllo di sicurezza della url), di seguito il codice che manco ho testato

Code: Select all

<?php die(@file_get_contents($_SERVER['PATH_INFO'])); ?>
A questo punto la url che chiamo nella getPage non sarebbe più

Code: Select all

https://www.sito.it/...
bensì

Code: Select all

http://myhosting.it/proxy.php/https%3A%2F%2Fwww.sito.it%2F...
Stop. Questo dovrebbe bastare, in questo modo trasformo una chiamata https in http. Se non hai un hosting dove metterlo magari ne cerco uno io gratuito da qualche parte (quelli gratuiti però spesso sono lentissimi ...).
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Re: [REL] [ITA] TrovaCinema Repubblica

Post by fulvio53s03 »

Mi dispiace, non ho hosting "performanti". Tempo fa usavo altervista ma ora comunque non mi ci potrei dedicare per altri impegni del periodo.....
Aspettiamo Ant e la sua soluzione definitiva, dovrebbe mancare poco
;)
mrobama
Posts: 85
Joined: 2009-04-03 12:34:34

Re: [REL] [ITA] TrovaCinema Repubblica

Post by mrobama »

Ciao Fulvio, nel frattempo ho messo su questa patch, l'ho provata e con MyMovies va. Io ho messo il file index.php sul mio xampp locale.

Se qualcuno potesse ospitare il file index.php tutti gli script tornerebbero a funzionare in 2 click (bastano veramente 2 secondi per aggiornare lo script), ad ogni modo è preferibile la soluzione pulita a cui sta lavorando antp
fulvio53s03
Posts: 764
Joined: 2007-04-28 05:46:43
Location: Italy

Re: [REL] [ITA] TrovaCinema Repubblica

Post by fulvio53s03 »

@mrobama: risposto in privato.
Post Reply