[Cz] CSFD.CZ - Working script

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.
zena52
Posts: 8
Joined: 2011-04-14 09:11:25

Řazení dle abecedy - přeložený název

Post by zena52 »

Zdravím uživatele AMC a prosím o radu (netuším ale zda to má souvislost se skriptem). Při přečíslování filmů dle přeloženého názvu nemůžu docílit, aby "ch" bylo za "h", seřadí se mi někam mezi "c". Mám verzi 4.2.0, nejnovější skript 4.7. U starší verze AMC se to řadilo správně.
Díky za radu :)
soulsnake
Posts: 756
Joined: 2011-03-14 15:42:20
Location: France

Post by soulsnake »

Hi,

The "natural comparison" to sort strings does not work properly when you should compare a single character with a double character (comparison is only done character by character).
I will try to fix this for the next version of AMC 4.2.1.
For now, you can deactivate the "natural comparison" in preferences :
Tools -> Preferences -> General Display -> uncheck "Use natural comparison to sort strings".

Soulsnake.
Last edited by soulsnake on 2014-11-02 09:08:40, edited 1 time in total.
zena52
Posts: 8
Joined: 2011-04-14 09:11:25

Post by zena52 »

Thank you very much, it´s OK now :) :) :)
zena52
Posts: 8
Joined: 2011-04-14 09:11:25

ČSFD

Post by zena52 »

Zdravím,
aktualizovala jsem script ČSFD na poslední verzi 4.16 (když ho otevřu, je tam, i když v programu se píše, že je tam 4.5), aktualizovala jsem obě potřebná .exe (curl a quiet). Při snaze přidat nový film mě program tvrdošíjně nabízí pouze film Nesnesitelná krutost animated grin . Netuším, v čem je problém, ale neaktualizovala jsem poprvé... Poradíte někdo?
Díky.
Bruttus
Posts: 1
Joined: 2017-10-10 09:43:53

Post by Bruttus »

Hello,
I updated the CSFD script to the latest version 4.16, I updated both the curl.exe and curl quiet.exe. When I try to add a new movie, the program hardly offers me only the movie I have in the database under the serial number 1. And even if I mark any movie in the database, it will download the movie data number 1. Do anybody know where the bug is?
Thanks.
zena52
Posts: 8
Joined: 2011-04-14 09:11:25

Post by zena52 »

Zdravím,
zřejmě po nějaké aktualizaci Avastu mi tento program při pokusu o přidání nového filmu do AMC tvrdošíjně přesouvá curl quiet do virové truhly a hlásí nějaké zavirování. Nepomůže ani "ignorovat", dokonce se mi "přeruší spojení" při pokusu o nové stažení tohoto exe. Má někdo stejný problém?
Roxik
Posts: 1
Joined: 2025-12-21 07:58:22

Re: [Cz] CSFD.CZ - Working script

Post by Roxik »

Po drobné změně v HTML bylo potřeba skript opět trochu upravit.

Code: Select all

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

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

[Infos]
Authors=Ike Blaster, MadMaxx, Dmitry501, Inteline, Kalten, kecinzer, MI'RA
Title=csfd.cz
Description=Import dat ze serveru csfd.cz
Site=https://amc.thez.info
Language=CZ
Version=5.5
Requires=4.2.3
Comments=- Update 6. 12. 2025 - drobná úprava kvůli změně HTML|- Update 2.10.2022 - Oprava načítání stránek s emoji v komentářích|- Update 13.3.2022 - Oprava načítání hodnocení, oprava načítání stránek s emoji v komentářích|- Update 12.12.2021 - Oprava v čištění textů (mizející z), oprava délky seriálů|- Update 11.12.2021 - Oprava načítání, úravy v čištění textů|- Update 25.5.2021 - Komplexní oprava (změna designu ČSFD)|- Update 27.7.2019 - Oprava hledání filmů s diakritikou v názvu|- Update 22.9.2018 - Oprava kódování odkazu na profil filmu|- Update 21.1.2018 - Přidána možnost stahovat data skrze HTTP proxy (může být nespolehlivé!)|- Update 26.5.2017 - Oprava, curl SSL revoke na některých systémech|- Update 24.5.2017 - Změněna ČSFD URL na https - vyžaduje curl w/SSL|- Update 17.9.2016 - Přidáno načítání producentů, volba velikosti obrázku, oprava názvů|- Fix 15.5.2016 - Oprava dekódování některých stránek, oprava neexistujících posterů|- Fix 22.11.2015 - Oprava načítání CZ/SK názvů filmů|- Fix 23.9.2015 - Oprava stahování přes curl (nyní výchozí možnost), oprava názvů filmů|- Update 12.9.2015 - Možnost stahovat informace pomocí curl (řešení gzip komprese)|- Fix 22.8.2015 - Opraveno načítání informací o filmu|- Fix 5.3.2015 - Opraveno načítání informací o filmu|- Fix 23.10.2014 - Opraveno načítání hodnocení, přidáno načítání scénáristů a skladatelů|- Fix 25.1.2014 - Opraveno načítání hodnocení, možnost více názvů u jednoho filmu, drobné opravy|- Fix 21.6.2013 - Opraveno načítání obalů|- Fix 16.4.2011 - Opraveno načítání herců a režisérů|- Fix 24.2.2011 - Upraveno přiřazování názvů, možnost vynucení CZ|- Add 15.2.2011 - Přidán rok ve výsledcích vyhledávání|- Fix 13.2.2011 - Pár oprav (URL, obsahy)|- Update 13.2.2011 - Skript celý přepsán||- Fix 17.12.2010 - Opraveno stahování celých popisů|- Add 16.12.2010 - Přidána možnost automat. aktualizace dle URL|- Fix 16.12.2010 - Opraveno stahování údajů|- Fix 16.6.2010 - Opraveno stahování popisu pro filmy bez popisu|- Add 16.6.2010 - Přidána možnost nahrazení oddělovače zemí za "/"|- Fix 12.5.2010 - Opravena chyba nestahování popisů|- Add 9.2.2009 - Možnost zadat URL filmu na ČSFD pro přímé získání informací|- Fix 16.9.2008 - Jedna malá chybka při hledání filmu s jedním výsledkem |- ReUpdate 8.9.2008 - Za pomoci zkušenějšího předěláno rozřezávání|- Update 28.8.2008 - implentace rozřezání do kategorií - byl to boj :D|- Fix 6.8.2008 - Oprava chyby ve výsledcích|- Update 30.7.2008 - oprava kódování|- Update 10.8.2007 - Jiné řazení výsledků (jako na webu), opraveno stahování popisu (více řádků), přesunutí La před film|- Info 5.3.2007 - Proběhlo hodně úprav, chyba u odkazu na film (z csfd) u filmů s jedním výsledkem ve vyhledávání|- Update 3.1.2007 - opraveno zobrazování filmů s jedním výsledkem ve vyhledávání|- Update 31.12.2006 - opraveny vsechny pole |- Update 4.12.2006 - zmena podle noveho csfd, vcetne importu hodnoceni
License=This file is standalone part of Ant Movie Catalog (AMC).||   AMC 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 3 of the License, or|    (at your option) any later version.||    AMC is distributed in the hope that it will be useful,|    but WITHOUT ANY WARRANTY; without even the implied warranty of|    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the|    GNU General Public License for more details.||    You should have received a copy of the GNU General Public License|    along with this program.  If not, see http://www.gnu.org/licenses/
GetInfo=1
RequiresMovies=1

[Options]
allowDuplicateNames=0|0|0=Pokud je originalni nazev stejny jako prelozeny - prelozeny se nedoplni.|1=Prelozeny nazev se doplni i v pripade, ze je stejny jako originalni nazev.|2=To samé jako 1. Pokud existuje jen originální název, tak se překopíruje do přeloženého.
AutoUpdateFromURL=1|1|0=Neaktualizovat automaticky|1=Pokud existuje URL, tak automaticky aktualizovat; jinak se zeptá
DetailniVysledky=0|0|0=Nezobrazovat více informací v seznamu výsledků|1=Zobrazovat více informací v seznamu výsledků
getPicture=1|1|0=Nestahovat obrázky|1=Stahovat obrázky
hodnoceni=1|1|0=Nestahovat hodnoceni|1=Stahovat hodnoceni
NahraditLomeno=1|1|0=Nenahrazovat "/" u kategorie a země filmu|1=Nahrazovat "/" u kategorie a země filmu
OpravovatNazvyCeskychFilmu=1|1|0=Neopravovat|1=Odhadnout původní český název, pokud existuje přeložený název
theEnd=1|1|0=Zachovat "The" na konci nazvu filmu|1=Presunout "The" z konce nazvu filmu na zacatek
UlozitVsechnyNazvyFilmu=0|0|0=Uložit pouze hlavní název (výchozí)|1=Uložit všechny názvy oddělené středníkem|2=Uložit všechny názvy oddělené lomítkem
VelikostObrazku=0|0|0=Výchozí - malé (180px)|1=Střední (420px)|2=Velké (720px)|3=Originální obrázek
VynutitCeskeNazvy=0|0|0=Nevynucovat (výchozí)|1=Vynucovat (jen v případě vkládání slovenských překladů)

[Parameters]
Počet výsledků hledání=|14|Násobky sedmi

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

program Csfd_cz;
const
  BaseAddress = 'https://www.csfd.cz/';
    /////////////////////////////////////////////
   //          Aktualni spravce :)            //
  //       Ike Blaster ike@thez.info         //
 //          http://amc.thez.info           //
/////////////////////////////////////////////

var
  MovieName: string;
  SearchPages: string;


function iPos(Substr: String; S: String): Integer;
begin
  Substr := AnsiLowerCase(Substr);
  S := AnsiLowerCase(S);
  Result := Pos(Substr, S);
end;

function ntrim(Value: string): string;
begin
  Value := RegExprSetReplace('\s+', Value, ' ', false);
  Value := trim(Value);
  Result := Value;
end;

function linetrim(Value: string): string;
begin
  Value := RegExprSetReplace('\A\s+', Value, '', false); // beginning of str
  Value := RegExprSetReplace('\s+\Z', Value, '', false); // end of str
  Value := RegExprSetReplace('^[ ]+', Value, '', false); // beginning of each line
  Value := RegExprSetReplace('[ ]+$', Value, '', false); // end of each line
  Result := Value;
end;


///////////////////////////// MAIN FUNCTIONS ///////////////////////////////////

// analyzuje stranku s vysledky hledani
procedure AnalyzeSearchPage(Address: String);
var
  Page, Line, MovieTitle, MovieAddress : String;
  BeginPos, EndPos, Section : Integer;
begin

  Page := GetPage(Address);
  Page := UTF8Decode(Page);


  BeginPos := Pos('snippet--containerFilms', Page);
  if(BeginPos = 0) then
  begin
    AnalyzeMoviePage(Address);
    Exit;
  end;


  BeginPos := Pos('snippet--containerFilms', Page);
  EndPos := Pos('snippet--moreSeries', Page);
  Page := Copy(Page, BeginPos, EndPos - BeginPos);
  

  // vycisti strom okna se seznamem filmu
  PickTreeClear;
  PickTreeAdd('Hledaný výraz: ' + MovieName, '');
  
  Section := -1;

  while (true) do
  begin
    BeginPos := Pos('<h3', Page);
    if BeginPos = 0 then
      break;

    EndPos := Pos('</h3>', Page) + 5;
    
    if(getOption('DetailniVysledky') = 1) then
      EndPos := Pos('</article>', Page) + 10;

    Line := Copy(Page, BeginPos, EndPos - BeginPos); // cast s filmem
    Page := Copy(Page, EndPos, Length(Page)); // vse za </h3>

    if (Pos('snippet--moreFilms', Page) <> 0) and (Section <> 0) then
    begin
      PickTreeAdd('Filmy', '');
      Section := 0;
    end;
    if (Pos('snippet--moreFilms', Page) = 0) and (Section <> 1) then
    begin
      PickTreeAdd('Seriály', '');
      Section := 1;
    end;
    

    // title
    MovieTitle := Line;
    
    if(getOption('DetailniVysledky') = 1) then
    begin
      MovieTitle := ntrim(MovieTitle);
      MovieTitle := StringReplace(MovieTitle, '</header>', ' ... ');
      MovieTitle := StringReplace(MovieTitle, '<p class="search-name">(', ' / ');
      MovieTitle := StringReplace(MovieTitle, ')</p>', '</p>');
      MovieTitle := StringReplace(MovieTitle, '<p class=', ' ... <p');
      MovieTitle := StringReplace(MovieTitle, '<a', ' <a');
    end;

    HTMLRemoveTags(MovieTitle);


    // url
    BeginPos := Pos('href="/', Line) + 7;
    MovieAddress := Copy(Line, BeginPos, Length(Line));
    
    EndPos := Pos('"', MovieAddress) - 1;
    MovieAddress := Copy(MovieAddress, 0, EndPos);


    if (MovieTitle <> '') and (MovieAddress <> '') then
      PickTreeAdd(MovieTitle, BaseAddress + MovieAddress + 'prehled/');
  end;

  if PickTreeExec(Address) then
    AnalyzeMoviePage(Address);
end;


// analyzuje stranku s detaily filmu
procedure AnalyzeMoviePage(Address: string);
var
  LineNr : Integer;
  listNames, listValues: TStringList;
  HTML, Page, Line, Value, Value2 : String;
  BeginPos, EndPos, i : Integer;
begin
  listNames := TStringList.Create;
  listValues := TStringList.Create;

  Address := StringReplace(Address,'http:','https:');
  Address := RegExprSetReplace('(^.*csfd.cz/film/\d+\-[^/]+).*', Address, '$1', true) + '/diskuze/?q=\§§§§§\§';
  
  HTML := GetPage(Address);
  HTML := UTF8Decode(HTML);

  BeginPos := Pos('<div class="main-movie">', HTML);
  Page := Copy(HTML, BeginPos, Length(HTML));


  HTMLDecode(Page);

  // hleda radek na kterem se nachazi zacatek informaci o filmu
  BeginPos := iPos('<div class="film-header-name"', Page);

  // pokud ho nasel
  if (BeginPos <> 0) then
  begin
    // nazvy
    SetField(fieldOriginalTitle, '');
    SetField(fieldTranslatedTitle, '');
    
    // hlavni nazev
    BeginPos := Pos('<h1', Page);
    EndPos := Pos('</h1>', Page);
    Value := Copy(Page,BeginPos,EndPos-BeginPos);
    BeginPos := Pos('>', Value)+1;
    Value := Copy(Value,BeginPos,EndPos);
    HTMLRemoveTags(Value);
    Value := ntrim(Value);
    
    listNames.Add('h1');
    listValues.Add(Value);
    // END // hlavni nazev

    // nazev - alternativni
    BeginPos := Pos('<ul class="film-names">', Page);
    if (BeginPos <> 0) then
    begin
      Line := Copy(Page,BeginPos,Length(Page));
      EndPos := Pos('</ul>', Line);
      Line := Copy(Line, 0, EndPos-1);

      while (true) do
      begin
        BeginPos := Pos('<li', Line);
        EndPos := Pos('</li>', Line) + 5;
        
        Value := Copy(Line, BeginPos, EndPos - BeginPos);
        Line := Copy(Line, EndPos, Length(Line));
        
        if BeginPos = 0 then
          break;


        Value2 := Value;
        EndPos := Pos('<span', Value2);
        if EndPos = 0 then
          EndPos := Pos('</li>', Value2);
        Value2 := Copy(Value2, 0, EndPos);
        HTMLRemoveTags(Value2);
        Value2 := ntrim(Value2); // alternativni nazev

        BeginPos := Pos('class="flag" title="', Value) + 20;
        EndPos := Pos('" alt="', Value);
        Value := Copy(Value, BeginPos, EndPos - BeginPos); // cast s vlajeckou

        if (iPos('Slovensk', Value) <> 0) then begin
          listNames.Add('sk'); listValues.Add(Value2);
          continue;
        end;

        if (iPos('Česk', Value) <> 0) then begin
          listNames.Add('cz'); listValues.Add(Value2);
          continue;
        end;

        listNames.Add('orig'); listValues.Add(Value2);
        continue;

      end;
    end; // END // nazev - alternativy
    
    Value2 := '; ';
    if (getOption('UlozitVsechnyNazvyFilmu') = 2) then
      Value2 := ' / ';
    

    // Prochazim jazyky a nastavim podle potreby
    for i := 0 to listNames.Count-1 do
    begin
      if ((getOption('theEnd') = 1) and (iPos(', The', listValues.GetString(i)) > 0)) then // jestli na konci nazvu filmu je clen The -> presune se na zacatek nazvu filmu
        listValues.SetString(i, 'The ' + Copy(listValues.GetString(i), 0, iPos(', The', listValues.GetString(i))-1));

      if ((getOption('theEnd') = 1) and (iPos(', A', listValues.GetString(i)) > 0)) then // ...
        listValues.SetString(i, 'A ' + Copy(listValues.GetString(i), 0, iPos(', A', listValues.GetString(i))-1));

      if ((getOption('theEnd') = 1) and (iPos(', Die', listValues.GetString(i)) > 0)) then // ...
        listValues.SetString(i, 'Die ' + Copy(listValues.GetString(i), 0, iPos(', Die', listValues.GetString(i))-1));

      if ((getOption('theEnd') = 1) and (iPos(', Le', listValues.GetString(i)) > 0)) then // ...
        listValues.SetString(i, 'Le ' + Copy(listValues.GetString(i), 0, iPos(', Le', listValues.GetString(i))-1));

      if ((getOption('theEnd') = 1) and (iPos(', La', listValues.GetString(i)) > 0)) then // ...
        listValues.SetString(i, 'La ' + Copy(listValues.GetString(i), 0, iPos(', La', listValues.GetString(i))-1));

      // h1 - preklad
      if(i=0) then
      begin
        SetField(fieldTranslatedTitle, listValues.GetString(i));
        continue;
      end;

      if((GetField(fieldOriginalTitle) = '') and (listNames.GetString(i) = 'orig')) then //  or (listNames.Count = 2)
      begin
        SetField(fieldOriginalTitle, listValues.GetString(i));
        continue;
      end;

      if((getOption('UlozitVsechnyNazvyFilmu') > 0) and (listNames.GetString(i) = 'cz')) then
      begin
        SetField(fieldTranslatedTitle, getField(fieldTranslatedTitle) + Value2 + listValues.GetString(i));
        continue;
      end;

      if((getOption('VynutitCeskeNazvy') = 1) and (listNames.GetString(i) = 'cz')) then
      begin
        if(listNames.Count = 2) then
          SetField(fieldOriginalTitle, listValues.GetString(0));
        if((getOption('UlozitVsechnyNazvyFilmu') > 0)) then
          SetField(fieldTranslatedTitle, listValues.GetString(i) + Value2 + getField(fieldTranslatedTitle))
        else
          SetField(fieldTranslatedTitle, listValues.GetString(i));
      end;
      
    end; // END // for

    if ((getField(fieldOriginalTitle) = '')) then
    begin
      SetField(fieldOriginalTitle, getField(fieldTranslatedTitle));
      if (getOption('allowDuplicateNames') = 1) then
        SetField(fieldTranslatedTitle, '');
    end;

    if ((getOption('allowDuplicateNames') = 0) and (getField(fieldOriginalTitle) = getField(fieldTranslatedTitle))) then
      SetField(fieldTranslatedTitle, '');

    // END // nazvy


    // poster
    BeginPos := Pos('<div class="film-posters">', Page);
    if (getOption('getPicture') = 1) and (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('/files/images/film/posters/', Value) + 26;
      EndPos := Pos('" loading="lazy"', Value);
      Value := Copy(Value,BeginPos,EndPos-BeginPos);
      
      if (Value <> '') and (Pos('data:', Value) = 0) then
      begin
        Case getOption('VelikostObrazku') of
          0: Value := 'https://image.pmgstatic.com/cache/resized/w180/files/images/film/posters/' + Value;
          1: Value := 'https://image.pmgstatic.com/cache/resized/w420/files/images/film/posters/' + Value;
          2: Value := 'https://image.pmgstatic.com/cache/resized/w720/files/images/film/posters/' + Value;
          3: Value := 'https://image.pmgstatic.com/files/images/film/posters/' + Value;
        end;

        GetPicture(Value);
      end;
    end;
    // END // poster


    // zanr
    BeginPos := Pos('<div class="genres">', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('>', Value)+1;
      EndPos := Pos('</div>', Value);

      Value := Copy(Value,BeginPos,EndPos-BeginPos);
      HTMLRemoveTags(Value);
      Value := ntrim(Value);
      if (getOption('NahraditLomeno') = 1) then
        SetField(fieldCategory, StringReplace(Value, ' / ',', '))
      else
        SetField(fieldCategory, Value);
    end; // END // zanr


    // stat, rok, delka
    BeginPos := Pos('<div class="origin">', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('>', Value)+1;
      EndPos := Pos('</div>', Value);

      Value := Copy(Value,BeginPos,EndPos-BeginPos);
      Value := ',' + ntrim(Value) + ','; // pridam carky z obou stran => ',ČR, 2009, 100 min,'
      HTMLRemoveTags(Value);

      BeginPos := Pos(',', Value); // prochazim po carkach
      while (BeginPos > 0 ) do
      begin
        Value2 := Copy(Value,BeginPos+1,Length(Value));
        EndPos := Pos(',', Value2);
        Value2 := Copy(Value2,0,EndPos-1);
        Value2 := ntrim(Value2);
        
        Value := Copy(Value,BeginPos+1,Length(Value)); // odriznu aktualni
        BeginPos := Pos(',', Value); // najdu dalsi carku
        
        if (Value2 = '') then Continue; // je prazdne, preskakuji


        if ((Length(Value2) = 4) and (StrToInt(Value2,-1) <> -1)) then // rok - pokud ma 4 znaky a je int
          SetField(fieldYear, Value2)

        else if ((Length(Value2) = 11) and (StrToInt(Copy(Value2, 2, 4),-1) <> -1)) then // rok - ma 11 znaku a 2-6 znak je int
        begin
          SetField(fieldYear, Copy(Value2, 2, 4));
        end
        
        else if (iPos(' min',Value2) <> 0) then // delka
        begin
          if (StrToInt(Copy(Value2, 0, 1),-1) = -1) then Continue; // musi zacinat cislem, resi: 149 min (Special Edition: 293 min, Director's Cut: 209 min, Alternativní 200 min)

          EndPos := Pos(' (', Value2);
          if EndPos <> 0 then Value2 := Copy(Value2, 0, EndPos); // odriznuti zavorky, resi: 6 h (Minutáž: 42–48 min)

          i := 0;
          
          EndPos := Pos('x', Value2); // resi: 6x55 min
          if EndPos <> 0 then begin
            i := StrToInt(Copy(Value2, 0, EndPos-1), -100000); // count
            Value2 := Copy(Value2, EndPos + 1, Length(Value2));
            
            EndPos := Pos(' min', Value2);
            i := i * StrToInt(Copy(Value2, 0, EndPos-1), -100000); // * minutes

          end else begin
            EndPos := Pos(' h ', Value2);
            if EndPos <> 0 then begin
              i := StrToInt(Copy(Value2, 0, EndPos-1), -100000) * 60; // hours * 60
              Value2 := Copy(Value2, EndPos + 3, Length(Value2));
            end;

            EndPos := Pos(' min', Value2);
            if EndPos <> 0 then i := i + StrToInt(Copy(Value2, 0, EndPos-1), -100000); // + minutes
          end;

          SetField(fieldLength, IntToStr(i));
        end
        
        else // zeme
        begin
          if (getOption('NahraditLomeno') = 1) then
            SetField(fieldCountry, StringReplace(Value2, ' / ',', '))
          else
            SetField(fieldCountry, Value2);

          if((getOption('OpravovatNazvyCeskychFilmu') = 1) and (iPos('česko',Value2) <> 0) and (iPos('česko',Value2) < 6) and (GetField(fieldTranslatedTitle) <> '')) then begin
            SetField(fieldOriginalTitle, GetField(fieldTranslatedTitle));

            if ((getOption('allowDuplicateNames') = 2)) then
              SetField(fieldTranslatedTitle, GetField(fieldOriginalTitle))
            else
              SetField(fieldTranslatedTitle, '');
          end;
        end;

      end;
    end; // END // stat, rok, delka


    // rezie
    BeginPos := iPos('<h4>Režie:', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('</h4>', Value);
      EndPos := Pos('</div>', Value);
      Value := Copy(Value,BeginPos,EndPos-BeginPos);

      HTMLRemoveTags(Value);
      Value := ntrim(Value);

      SetField(fieldDirector, Value);
    end; // END // rezie
    

    // scenar
    BeginPos := iPos('<h4>Scénář:', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('</h4>', Value);
      EndPos := Pos('</div>', Value);
      Value := Copy(Value,BeginPos,EndPos-BeginPos);

      HTMLRemoveTags(Value);
      Value := ntrim(Value);

      SetField(fieldWriter, Value);
    end; // END // scenar
    
    
    // hudba
    BeginPos := Pos('<h4>Hudba:', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('</h4>', Value);
      EndPos := Pos('</div>', Value);
      Value := Copy(Value,BeginPos,EndPos-BeginPos);

      HTMLRemoveTags(Value);
      Value := ntrim(Value);

      SetField(fieldComposer, Value);
    end; // END // hudba


    // herci
    BeginPos := Pos('<h4>Hrají:', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('</h4>', Value);
      EndPos := Pos('</div>', Value);
      Value := Copy(Value,BeginPos,EndPos-BeginPos);

      HTMLRemoveTags(Value);
      Value := ntrim(Value);

      SetField(fieldActors, Value);
    end; // END // herci


    // producenti
    BeginPos := iPos('<h4>Produkce:', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      BeginPos := Pos('</h4>', Value);
      EndPos := Pos('</div>', Value);
      Value := Copy(Value,BeginPos,EndPos-BeginPos);

      HTMLRemoveTags(Value);
      Value := ntrim(Value);

      SetField(fieldProducer, Value);
    end; // END // producenti


    // hodnoceni
    if (getOption('hodnoceni') = 1) then
    begin
      BeginPos := iPos('<div class="film-rating-average', Page);
      if (BeginPos <> 0) then
      begin
        Value := Copy(Page,BeginPos,Length(Page));
        EndPos := Pos('</div>', Value);
        Value := Copy(Value,0,EndPos);

        HTMLRemoveTags(Value);
        Value := ntrim(Value);
        Value := copy(Value, 0, Length(Value)-1);

        if(StrToInt(Value,-1) <> -1) then
          SetField(fieldRating, FloatToStr(StrToInt(Value,-1)/10)); // prevedu na cislo, vydelim 10, prevedu na string
      end;
    end; // END // hodnoceni


    // popis
    BeginPos := Pos('<div class="body--plots"', Page);
    if (BeginPos <> 0) then
    begin
      Value := Copy(Page,BeginPos,Length(Page));
      EndPos := Pos('</section>', Value) + 10;
      Value := Copy(Value,0,EndPos);

      BeginPos := Pos('<div class="plot-preview', Value);
      EndPos := Pos('<div class="plots', Value);
      
      Delete(Value, BeginPos, EndPos - BeginPos - 1);

      Value := StringReplace(Value,'<p>','\n\n');
      Value := StringReplace(Value,'<em',' <em');
      Value := StringReplace(Value,'<br />','\n');
      Value := StringReplace(Value,'<br>','\n');

      HTMLRemoveTags(Value);
      Value := StringReplace(Value,#13#10,'');
      Value := RegExprSetReplace('[\t ]+', Value, ' ', true);
      Value := StringReplace(Value,'\n',#13#10);
      Value := linetrim(Value);

      SetField(fieldDescription, Value);
    end; // END // popis

    // url
    BeginPos := Pos('<meta property="og:url" content="https://www.csfd.cz/film/', HTML);
    if (BeginPos <> 0) then
    begin
      Value := Copy(HTML, BeginPos+58, 256);
      EndPos := Pos('"', Value)-1;
      Value := Copy(Value, 0, EndPos);
      
      EndPos := Pos('/', Value) - 1;
      Value := Copy(Value, 0, EndPos);

      Value := BaseAddress + 'film/' + Value;

      SetField(fieldURL, Value);
    end
    else
    begin
      SetField(fieldURL, Address);
    end; // END // url

  end
end;




begin
  // kontrola verze movie catalogu
  if CheckVersion(4,2,3) then
    begin
      MovieName := GetField(fieldTranslatedTitle);
      
      // pokud je originalni jmeno filmu prazdne, vem jmeno prelozene
      if (MovieName = '') then
        MovieName := GetField(fieldOriginalTitle);

      if ((getOption('AutoUpdateFromURL') = 1) and (GetField(fieldURL) <> '')) then
        MovieName := GetField(fieldURL)
      else
        if Input('Import údajů z www.csfd.cz', 'Zadejte název filmu:', MovieName) = false then
          Exit;
          
      // zadani z inputu
      if pos('csfd.cz/film/', MovieName) > 0 then
        AnalyzeMoviePage(MovieName)
      else
        if(trim(MovieName) <> '') then begin
          SearchPages := IntToStr(Round(StrToInt(GetParam('Počet výsledků hledání'), 1) / 7 + 0.49));

          AnalyzeSearchPage(BaseAddress + 'hledat/?pageSeries=' + SearchPages + '&pageFilms=' + SearchPages + '&q=' + UrlEncode(MovieName));
        end;

    end
  else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 4.2.3)');
end.
Last edited by Roxik on 2025-12-21 08:03:07, edited 1 time in total.
antp
Site Admin
Posts: 9809
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Re: [Cz] CSFD.CZ - Working script

Post by antp »

Thanks, I updated it on my server
Post Reply