Script for CSFD.cz???
Posted: 2003-09-03 13:18:34
Can anybody do a script for CSFD.cz?
COOL :-)Dmitry501 wrote:I can Please, wait for result.
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.
No, I speak only on Russian.can u speak czech?
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.little bug i found: in "Country" it imports also "Year" and "Lenght"
The CSFD.cz changed a little bit and now i see this bug:Dmitry501 wrote:No, I speak only on Russian.can u speak czech?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.little bug i found: in "Country" it imports also "Year" and "Lenght"
Example please. Movie name?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?
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.dmitry wrote:Example please. Movie name?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?
Yes, the mistake is. I do not use this server, therefore I can not trace change . The corrected script look above.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.
THX :-)))Anonymous wrote:Yes, the mistake is. I do not use this server, therefore I can not trace change . The corrected script look above.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.