Script for CSFD.cz???

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
bloody.vc

Script for CSFD.cz???

Post by bloody.vc »

Can anybody do a script for CSFD.cz?
Dmitry501
Posts: 26
Joined: 2003-08-13 02:35:10

Post by Dmitry501 »

I can :) Please, wait for result.
Guest

Post by Guest »

Dmitry501 wrote:I can :) Please, wait for result.
COOL :-)
Dmitry501
Posts: 26
Joined: 2003-08-13 02:35:10

Post by Dmitry501 »

Code: Select all

// GETINFO SCRIPTING
// Imports from csfd.cz
// Dmitry501

program Csfd_cz;
const
  BaseAddress = 'http://csfd.cz/';
var
  MovieName: string;

function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
var
  i: Integer;
begin
  result := -1;
  if StartAt < 0 then
    StartAt := 0;
  for i := StartAt to List.Count-1 do
    if Pos(Pattern, List.GetString(i)) <> 0 then
    begin
      result := i;
      Break;
    end;
end;

function GetDirector(Line: string): String;
var BeginPos : Integer;
begin
    result := '';
    BeginPos := Pos('Režie:', Line);
    if BeginPos > 0 then
    begin
      Delete(Line,1,BeginPos+5);
      BeginPos := Pos('<br>', Line);
      if BeginPos = 0 then BeginPos := Length(Line);
      result := copy(Line, 1, BeginPos);
      HTMLDecode(result);
      HTMLRemoveTags(result);
    end;
  result := Trim(result);
end;

function GetActor(Line: string): String;
var BeginPos : Integer;
begin
    result := '';
    BeginPos := Pos('Hrají:', Line);
    if BeginPos > 0 then
    begin
      Delete(Line,1,BeginPos + 5);
      BeginPos := Pos('<br>', Line);
      if BeginPos = 0 then BeginPos := Length(Line);
      result := copy(Line, 1, BeginPos);
      HTMLDecode(result);
      HTMLRemoveTags(result);
    end;
  result := Trim(result);
end;

function GetTitle(Line: string): String;
var BeginPos : Integer;
begin
    result := '';
    BeginPos := Pos('<img src=''/images/flag_52.gif', Line);
    if BeginPos > 0 then
    begin
      Delete(Line,1,BeginPos-1);
      BeginPos := Pos('</table>', Line);
      if BeginPos = 0 then BeginPos := Length(Line);
      result := copy(Line, 1, BeginPos);
      HTMLDecode(result);
      HTMLRemoveTags(result);
      MovieName := GetField(fieldTranslatedTitle);
      MovieName := MovieName + ' (' + result + ')';
      SetField(fieldTranslatedTitle,MovieName);
      Delete(Line,1,BeginPos-1);
    end

    BeginPos := Pos(' ', Line);
    if BeginPos > 0 then
    begin
      Delete(Line,BeginPos, Length(Line));
      result := Line;
      HTMLDecode(result);
      HTMLRemoveTags(result);
    end;
  result := Trim(result);
end;

function GetCategory(Line: string): String;
var BeginPos : Integer;
begin
    result := '';
    BeginPos := Pos(' ', Line);
    if BeginPos > 0 then
    begin
      Delete(Line,1,BeginPos + 9);
      BeginPos := Pos('<br>', Line);
      if BeginPos = 0 then BeginPos := Length(Line);
      result := copy(Line, 1, BeginPos-1);
      HTMLDecode(result);
      HTMLRemoveTags(result);
    end;
    result := Trim(result);
    SetField(fieldCategory, result);
    result := '';
    Delete(Line,1,BeginPos-1);
    BeginPos := Pos('<br>', Line);
    if BeginPos > 0 then
    begin
      Delete(Line,1,BeginPos + 3);
      BeginPos := Pos('<p>', Line);
      if BeginPos = 0 then BeginPos := Length(Line);
      result := copy(Line, 1, BeginPos-1);
      HTMLDecode(result);
      HTMLRemoveTags(result);
    end;
    result := Trim(result);
    SetField(fieldCountry, result);
end;

procedure AnalyzePage(Address: string);
var
  Page: TStringList;
  LineNr : Integer;
  Line, Value : String;
  BeginPos, EndPos : Integer;
  FilmName, FilmAddr : String;
begin
    Page := TStringList.Create;
    Page.Text := GetPage(Address);
    LineNr := FindLine('databáze</title>', Page, 0);
    if LineNr = -1 then
    begin
        AnalyzeMoviePage(Address);
    end
    else
    begin
     LineNr := FindLine('Nebyly nalezeny žádné', Page, 0);
      if LineNr = -1 then
      begin
        LineNr := FindLine('<a href="film.', Page, 0);
        if LineNr > -1 then
        begin
          PickTreeClear;
          PickTreeAdd('Filmy: ' + MovieName, '');
          Line := Page.GetString(LineNr);
          repeat
            BeginPos := Pos('<a href="',Line);
            If BeginPos > 0 Then
            begin
              EndPos := Pos('">',Line);
              if EndPos = 0 Then EndPos := Length(Line);
              FilmAddr := Copy(Line, BeginPos+9, EndPos-BeginPos-9);
              HTMLDecode(FilmAddr);
              HTMLRemoveTags(FilmAddr);
              EndPos := Pos('<br>',Line);
              if EndPos = 0 Then EndPos := Length(Line);
              FilmName := Copy(Line, BeginPos, EndPos-BeginPos);
              HTMLDecode(FilmName);
              HTMLRemoveTags(FilmName);
              PickTreeAdd(FilmName, BaseAddress + FilmAddr);
              Delete(Line,1,EndPos+3);
            end;
          until BeginPos <1;
         If  PickTreeExec(Address) Then
           AnalyzeMoviePage(Address);
        end;
      end;
    end;
end;

procedure AnalyzeMoviePage(Address: string);
var
  Page: TStringList;
  LineNr : Integer;
  Line, Value : String;
  BeginPos, EndPos : Integer;
begin
    Page := TStringList.Create;
    Page.Text := GetPage(Address);
    LineNr := FindLine('<div class="nazovfilmu">', Page, 0);
    if LineNr > -1 then
    begin
 
      Line := Page.GetString(LineNr+1);
      HTMLDecode(Line);
      HTMLRemoveTags(Line);
      Value := Trim(Line);
      SetField(fieldTranslatedTitle, Value);

      Line := Page.GetString(LineNr+2);
      Value := GetDirector(Line);
      SetField(fieldDirector, Value);
      Value := GetActor(Line);
      SetField(fieldActors, Value);
      Value := GetTitle(Line);
      SetField(fieldOriginalTitle, Value);
      Value := GetCategory(Line);
    end;
    // picture
    LineNr := FindLine('style="padding-left: 10px"', Page, 0);
    if LineNr > -1 then
    begin
      Line := Page.GetString(LineNr);
      BeginPos := pos('<img src="', Line) + 10;
      if BeginPos > 10 then
        begin
          EndPos := pos('" width="', Line);
          Value := copy(Line, BeginPos, EndPos - BeginPos);
          Value := BaseAddress + Value;
          GetPicture(Value, False);
        end;
    end;
    // Info
    LineNr := FindLine('id="plot_full"', Page, 0);
    if LineNr > -1 then
    begin
      Value := Page.GetString(LineNr+1);
      HTMLDecode(Value);
      HTMLRemoveTags(Value);
      SetField(fieldDescription, Trim(Value));
    end;
   // URL
   SetField(fieldURL, Address);
  DisplayResults;
end;

begin
  if CheckVersion(3,4,0) then
  begin
    MovieName := GetField(fieldOriginalTitle);
    if MovieName = '' then
      MovieName := GetField(fieldTranslatedTitle);
    if Input('Import movie from www.csfd.cz', 'Enter the title of the movie:', MovieName) then
    begin
			AnalyzePage('http://csfd.cz/index.php?action=hledat&hledej='+UrlEncode(MovieName));
    end;
  end else
    ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.
This is BETA ;)
Changed 09/12/2003
Last edited by Dmitry501 on 2003-09-12 02:30:06, edited 6 times in total.
bloody.vc

Post by bloody.vc »

can u speak czech? / mluvis cesky, at se pripadne zbytecne nebavime v anglictine? ;-)

THANK YOU FOR A GREAT JOB :-))

little bug i found: in "Country" it imports also "Year" and "Lenght"
Dmitry501
Posts: 26
Joined: 2003-08-13 02:35:10

Post by Dmitry501 »

can u speak czech?
No, I speak only on Russian.
little bug i found: in "Country" it imports also "Year" and "Lenght"
Yes, this thus. Server in no way separates these fields. Look itself. Sometimes there are no some values. For example the country, duration. Or year, the country. Or year, the country, duration. In this beta version this problem is not solved. I will possibly make more lately.
bloody.vc

Post by bloody.vc »

ok, thank you anyway :-)
Peca

Post by Peca »

Thank you very much for this script!
vykupitel
Posts: 6
Joined: 2003-07-04 17:51:19

THX

Post by vykupitel »

Thank you very much for your work on this script,very helpfull
bloody.vc
Posts: 5
Joined: 2003-09-09 07:40:38

Post by bloody.vc »

Dmitry501 wrote:
can u speak czech?
No, I speak only on Russian.
little bug i found: in "Country" it imports also "Year" and "Lenght"
Yes, this thus. Server in no way separates these fields. Look itself. Sometimes there are no some values. For example the country, duration. Or year, the country. Or year, the country, duration. In this beta version this problem is not solved. I will possibly make more lately.
The CSFD.cz changed a little bit and now i see this bug:

error msg: Script error: CSFD_CZ at position 4458 (assigment expected)

Can anybody help?
dmitry

Post by dmitry »

The CSFD.cz changed a little bit and now i see this bug:

error msg: Script error: CSFD_CZ at position 4458 (assigment expected)

Can anybody help?
Example please. Movie name?
bloody.vc
Posts: 5
Joined: 2003-09-09 07:40:38

Post by bloody.vc »

dmitry wrote:
The CSFD.cz changed a little bit and now i see this bug:

error msg: Script error: CSFD_CZ at position 4458 (assigment expected)

Can anybody help?
Example please. Movie name?
For example: Citizen Kane, City by the Sea, Casino, i think every film i tried. Strange thing is that when i tried it yesterday, when one man told me about this error, its doesnt happen to me. Maybe active cash? But few tries later i got this error in 100% of cases.
Guest

Post by Guest »

For example: Citizen Kane, City by the Sea, Casino, i think every film i tried. Strange thing is that when i tried it yesterday, when one man told me about this error, its doesnt happen to me. Maybe active cash? But few tries later i got this error in 100% of cases.
Yes, the mistake is. I do not use this server, therefore I can not trace change :) . The corrected script look above. :up:
bloody.vc
Posts: 5
Joined: 2003-09-09 07:40:38

Post by bloody.vc »

Anonymous wrote:
For example: Citizen Kane, City by the Sea, Casino, i think every film i tried. Strange thing is that when i tried it yesterday, when one man told me about this error, its doesnt happen to me. Maybe active cash? But few tries later i got this error in 100% of cases.
Yes, the mistake is. I do not use this server, therefore I can not trace change :) . The corrected script look above. :up:
THX :-)))
vykupitel
Posts: 6
Joined: 2003-07-04 17:51:19

Question

Post by vykupitel »

How could I change this script to load from WWW only: Translated title, Director, Producer, Country, Actors, Plot? Please help me someone. I don`t want to overwrite my data with this script from csfd.cz. :(

Is there any change to cut year from category?
vykupitel
Posts: 6
Joined: 2003-07-04 17:51:19

anyone???

Post by vykupitel »

PLEASE, is there anyone who can help me??? :cry:

:( :( :(
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

What do you want to remove from the script ? Picture and URL ?
vykupitel
Posts: 6
Joined: 2003-07-04 17:51:19

RE

Post by vykupitel »

Yes, I don`t want to download pictures,category,year `cos I have it already and the script is always overwite it to me :(
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

To disable the picture, remove the code between "// picture" and "// Info"
To disable category and year (and others) remove the "SetField(...)" lines that contain the name of the field that you do not want to overwrite.
Post Reply