home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / amc / amc_install.exe / {app} / Scripts / csfd.cz.ifs < prev    next >
Encoding:
Text File  |  2005-03-13  |  7.2 KB  |  259 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Dmitry501
  8. Title=csfd.cz
  9. Description=Imports from csfd.cz
  10. Site=www.csfd.cz
  11. Language=CZ
  12. Version=
  13. Requires=3.5.0
  14. Comments= 
  15. 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. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program Csfd_cz;
  23. const
  24.   BaseAddress = 'http://www.csfd.cz/';
  25. var
  26.   MovieName: string;
  27.  
  28. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  29. var
  30.   i: Integer;
  31. begin
  32.   result := -1;
  33.   if StartAt < 0 then
  34.     StartAt := 0;
  35.   for i := StartAt to List.Count-1 do
  36.     if Pos(Pattern, List.GetString(i)) <> 0 then
  37.     begin
  38.       result := i;
  39.       Break;
  40.     end;
  41. end;
  42.  
  43. function GetDirector(Line: string): String;
  44. var BeginPos : Integer;
  45. begin
  46.     result := '';
  47.     BeginPos := Pos('Re₧ie:', Line);
  48.     if BeginPos > 0 then
  49.     begin
  50.       Delete(Line,1,BeginPos+5);
  51.       BeginPos := Pos('<br>', Line);
  52.       if BeginPos = 0 then BeginPos := Length(Line);
  53.       result := copy(Line, 1, BeginPos);
  54.       HTMLDecode(result);
  55.       HTMLRemoveTags(result);
  56.     end;
  57.   result := Trim(result);
  58. end;
  59.  
  60. function GetActor(Line: string): String;
  61. var BeginPos : Integer;
  62. begin
  63.     result := '';
  64.     BeginPos := Pos('Hrajφ:', Line);
  65.     if BeginPos > 0 then
  66.     begin
  67.       Delete(Line,1,BeginPos + 5);
  68.       BeginPos := Pos('<br>', Line);
  69.       if BeginPos = 0 then BeginPos := Length(Line);
  70.       result := copy(Line, 1, BeginPos);
  71.       HTMLDecode(result);
  72.       HTMLRemoveTags(result);
  73.     end;
  74.   result := Trim(result);
  75. end;
  76.  
  77. function GetTitle(Line: string): String;
  78. var BeginPos : Integer;
  79. begin
  80.     result := '';
  81.     BeginPos := Pos('<img src=''/images/flag_52.gif', Line);
  82.     if BeginPos > 0 then
  83.     begin
  84.       Delete(Line,1,BeginPos-1);
  85.       BeginPos := Pos('</table>', Line);
  86.       if BeginPos = 0 then BeginPos := Length(Line);
  87.       result := copy(Line, 1, BeginPos);
  88.       HTMLDecode(result);
  89.       HTMLRemoveTags(result);
  90.       MovieName := GetField(fieldTranslatedTitle);
  91.       MovieName := MovieName + ' (' + result + ')';
  92.       SetField(fieldTranslatedTitle,MovieName);
  93.       Delete(Line,1,BeginPos-1);
  94.     end
  95.  
  96.     BeginPos := Pos(' ', Line);
  97.     if BeginPos > 0 then
  98.     begin
  99.       Delete(Line,BeginPos, Length(Line));
  100.       result := Line;
  101.       HTMLDecode(result);
  102.       HTMLRemoveTags(result);
  103.     end;
  104.   result := Trim(result);
  105. end;
  106.  
  107. function GetCategory(Line: string): String;
  108. var BeginPos : Integer;
  109. begin
  110.     result := '';
  111.     BeginPos := Pos(' ', Line);
  112.     if BeginPos > 0 then
  113.     begin
  114.       Delete(Line,1,BeginPos + 9);
  115.       BeginPos := Pos('<br>', Line);
  116.       if BeginPos = 0 then BeginPos := Length(Line);
  117.       result := copy(Line, 1, BeginPos-1);
  118.       HTMLDecode(result);
  119.       HTMLRemoveTags(result);
  120.     end;
  121.     result := Trim(result);
  122.     SetField(fieldCategory, result);
  123.     result := '';
  124.     Delete(Line,1,BeginPos-1);
  125.     BeginPos := Pos('<br>', Line);
  126.     if BeginPos > 0 then
  127.     begin
  128.       Delete(Line,1,BeginPos + 3);
  129.       BeginPos := Pos('<p>', Line);
  130.       if BeginPos = 0 then BeginPos := Length(Line);
  131.       result := copy(Line, 1, BeginPos-1);
  132.       HTMLDecode(result);
  133.       HTMLRemoveTags(result);
  134.     end;
  135.     result := Trim(result);
  136.     SetField(fieldCountry, result);
  137. end;
  138.  
  139. procedure AnalyzePage(Address: string);
  140. var
  141.   Page: TStringList;
  142.   LineNr : Integer;
  143.   Line, Value : String;
  144.   BeginPos, EndPos : Integer;
  145.   FilmName, FilmAddr : String;
  146. begin
  147.     Page := TStringList.Create;
  148.     Page.Text := GetPage(Address);
  149.     LineNr := FindLine('databßze</title>', Page, 0);
  150.     if LineNr = -1 then
  151.     begin
  152.         AnalyzeMoviePage(Address);
  153.     end
  154.     else
  155.     begin
  156.      LineNr := FindLine('Nebyly nalezeny ₧ßdnΘ', Page, 0);
  157.       if LineNr = -1 then
  158.       begin
  159.         LineNr := FindLine('<a href="film.', Page, 0);
  160.         if LineNr > -1 then
  161.         begin
  162.           PickTreeClear;
  163.           PickTreeAdd('Filmy: ' + MovieName, '');
  164.           Line := Page.GetString(LineNr);
  165.           repeat
  166.             BeginPos := Pos('<a href="',Line);
  167.             If BeginPos > 0 Then
  168.             begin
  169.               EndPos := Pos('">',Line);
  170.               if EndPos = 0 Then EndPos := Length(Line);
  171.               FilmAddr := Copy(Line, BeginPos+9, EndPos-BeginPos-9);
  172.               HTMLDecode(FilmAddr);
  173.               HTMLRemoveTags(FilmAddr);
  174.               EndPos := Pos('<br>',Line);
  175.               if EndPos = 0 Then EndPos := Length(Line);
  176.               FilmName := Copy(Line, BeginPos, EndPos-BeginPos);
  177.               HTMLDecode(FilmName);
  178.               HTMLRemoveTags(FilmName);
  179.               PickTreeAdd(FilmName, BaseAddress + FilmAddr);
  180.               Delete(Line,1,EndPos+3);
  181.             end;
  182.           until BeginPos <1;
  183.          If  PickTreeExec(Address) Then
  184.            AnalyzeMoviePage(Address);
  185.         end;
  186.       end;
  187.     end;
  188. end;
  189.  
  190. procedure AnalyzeMoviePage(Address: string);
  191. var
  192.   Page: TStringList;
  193.   LineNr : Integer;
  194.   Line, Value : String;
  195.   BeginPos, EndPos : Integer;
  196. begin
  197.     Page := TStringList.Create;
  198.     Page.Text := GetPage(Address);
  199.     LineNr := FindLine('<div class="nazovfilmu">', Page, 0);
  200.     if LineNr > -1 then
  201.     begin
  202.  
  203.       Line := Page.GetString(LineNr+1);
  204.       HTMLDecode(Line);
  205.       HTMLRemoveTags(Line);
  206.       Value := Trim(Line);
  207.       SetField(fieldTranslatedTitle, Value);
  208.  
  209.       Line := Page.GetString(LineNr+2);
  210.       Value := GetDirector(Line);
  211.       SetField(fieldDirector, Value);
  212.       Value := GetActor(Line);
  213.       SetField(fieldActors, Value);
  214.       Value := GetTitle(Line);
  215.       SetField(fieldOriginalTitle, Value);
  216.       Value := GetCategory(Line);
  217.     end;
  218.     // picture
  219.     LineNr := FindLine('style="padding-left: 10px"', Page, 0);
  220.     if LineNr > -1 then
  221.     begin
  222.       Line := Page.GetString(LineNr);
  223.       BeginPos := pos('<img src="', Line) + 10;
  224.       if BeginPos > 10 then
  225.         begin
  226.           EndPos := pos('" width="', Line);
  227.           Value := copy(Line, BeginPos, EndPos - BeginPos);
  228.           Value := BaseAddress + Value;
  229.           GetPicture(Value);
  230.         end;
  231.     end;
  232.     // Info
  233.     LineNr := FindLine('id="plot_full"', Page, 0);
  234.     if LineNr > -1 then
  235.     begin
  236.       Value := Page.GetString(LineNr+1);
  237.       HTMLDecode(Value);
  238.       HTMLRemoveTags(Value);
  239.       SetField(fieldDescription, Trim(Value));
  240.     end;
  241.    // URL
  242.    SetField(fieldURL, Address);
  243.   //DisplayResults;
  244. end;
  245.  
  246. begin
  247.   if CheckVersion(3,5,0) then
  248.   begin
  249.     MovieName := GetField(fieldOriginalTitle);
  250.     if MovieName = '' then
  251.       MovieName := GetField(fieldTranslatedTitle);
  252.     if Input('Import movie from www.csfd.cz', 'Enter the title of the movie:', MovieName) then
  253.     begin
  254.          AnalyzePage(BaseAddress + 'index.php?action=hledat&hledej='+UrlEncode(MovieName));
  255.     end;
  256.   end else
  257.   ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  258. end.
  259.