Hi, I needed a script for Cinemagia.ro also, so this is what I came up with in about 2 hours.
Don't flame me, I know the code is a mess, but my Pascal skills are kinda rusty, and I only had 2 hours to do it
If there are more articles assigned to one movie, the first one ( ussualy 'Sinopsis' or 'Despre Productie'=about production) goes in the Description field, and all the rest (including press reviews) go in the Comments field. I needed all data for the movie, that's why I didn't add a picker for descriptions.
) stages, so don't expect too much, but it still takes basic fields, and the large image. I recommend running a IMDB script first though to take all details, then this one for the Romanian details.
Note that some diacritics don't show up correctly in the main AMC window, but as soon as you export your catalog in XML/HTML, everything should look good (including HTML formatting for titles & such). (some manual modification needs to be done if there are more articles for one movie - to separate them, but you'll figure that out
Code: Select all
// GETINFO SCRIPTING
// Cinemagia.ro (RO) import with picture
(***************************************************
* Movie importation script for: *
* Cinemagia.ro (RO), http://www.cinemagia.ro *
* *
* (c) 2004 Mihai Tudor *
* tekman@go.ro *
* *
* For use with Ant Movie Catalog 3.4.0 *
* www.antp.be/software/moviecatalog *
* *
* 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 *
***************************************************)
program Cinemagia;
var
MovieName: string;
MovieURL: 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;
procedure AnalyzePage(Address: string);
var
Page: TStringList;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if pos('Rezultatele cautarii', Page.Text) = 0 then
begin
AnalyzeMoviePage(Page)
end
else
begin
if pos('Nici un rezultat', Page.Text) > 0 then
ShowMessage('Sorry, no results were found for ' + MovieName)
else
begin
PickTreeClear;
AddMoviesTitles(Page);
if PickTreeExec(Address) then
AnalyzePage(Address);
end
end;
Page.Free;
end;
function FindValue(BeginTag, EndTag: string; Page: TStringList; var LineNr: Integer; var Line: string): string;
var
BeginPos, EndPos: Integer;
Value: string;
begin
Result := '';
Value := '';
BeginPos := Pos(BeginTag, Line);
if BeginPos > 0 then
begin
BeginPos := BeginPos + Length(BeginTag);
if BeginTag = EndTag then
begin
Delete(Line,1,BeginPos-1);
BeginPos := 1;
end;
EndPos := pos(EndTag, Line);
while ((EndPos = 0) and (LineNr < Page.Count-1 )) do
begin
Value := Value + copy(Line, BeginPos, Length(Line) - BeginPos);
// Next Line
BeginPos := 1;
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
if Value = '' then
Exit;
EndPos := Pos(EndTag, Line);
end;
Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
end;
Result := Value;
end;
procedure AnalyzeMoviePage(Page: TStringList);
var
Line, Value, Value2: string;
IsFirst, LineNr, BeginPos, EndPos, DescrImport: Integer;
HasPressReviews : Integer;
PressReviewAddress : string;
begin
LineNr := FindLine('<h1 class="movie">', Page, 0);
if LineNr > 2 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<a href="', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 9;
EndPos := pos('style=', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos - 2);
HTMLDecode(Value);
MovieURL := 'http://www.cinemagia.ro' + Value;
// URL
SetField(fieldURL, MovieURL);
Value := FindValue( '<b>', '</b>', Page, LineNr, Line);
HTMLDecode(Value);
SetField(fieldTranslatedTitle, Value);
Value := FindValue( '<i>(', ')</i>', Page, LineNr, Line);
HTMLDecode(Value);
SetField(fieldYear, Value);
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
Value := FindValue( '<i>', '</i>', Page, LineNr, Line);
HTMLDecode(Value);
SetField(fieldOriginalTitle, Value);
end;
LineNr := FindLine('<img src="/getimg.php?id=', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<img src="/getimg.php?id=', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 10;
EndPos := pos('&size=s"', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos + 6) + 'm';
HTMLDecode(Value);
GetMoviePicture( 'http://www.cinemagia.ro' + Value);
end;
LineNr := FindLine('Regia<br>', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('Regia<br>', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 9;
Delete( Line, 1, BeginPos);
EndPos := pos('<br>', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, 1, EndPos);
BeginPos := pos('">', Value) + 2;
EndPos := pos('</a>', Value);
Value := copy(Value, BeginPos, EndPos - BeginPos);
HTMLDecode(Value);
SetField(fieldDirector, Value);
end;
LineNr := FindLine('Gen<br>', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('Gen<br>', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 7;
Delete( Line, 1, BeginPos);
EndPos := pos('<br>', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, 1, EndPos);
Value2 := '';
repeat
BeginPos := pos('">', Value) + 2;
EndPos := pos('</span>', Value);
Value2 := Value2 + ', ' + copy(Value, BeginPos, EndPos - BeginPos);
Delete( Value, 1, EndPos + 8);
until pos('">', Value) < 1;
Delete( Value2, 1, 2);
HTMLDecode(Value2);
SetField(fieldCategory, Value2);
end;
LineNr := FindLine('what=cast', Page, LineNr);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<a href="', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 9;
EndPos := pos('" class', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
SetField(fieldActors, GetCast('http://www.cinemagia.ro' + Value));
end;
HasPressReviews := 0;
IsFirst := 1;
Value2 := '';
LineNr := FindLine('Continuare</a>', Page, 0);
while (LineNr > -1) do
begin
Line := Page.GetString(LineNr);
BeginPos := pos('<a href="/movie.php', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 9;
EndPos := pos('&hist=0', Line);
if EndPos = 0 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos + 7);
HTMLDecode(Value);
if pos( 'what=pressreviews', Value) > 0 then
begin
PressReviewAddress := Value;
HasPressReviews := 1;
end
else
begin
if IsFirst = 1 then
begin
SetField(fieldDescription, GetDescriptions( Value));
IsFirst := 0;
end
else
begin
Value2 := Value2 + GetDescriptions( Value) + Chr(10) + Chr(13) + '===============';
end;
end;
LineNr := FindLine('Continuare</a>', Page, LineNr + 1);
end;
if HasPressReviews = 1 then
begin
Value2 := Value2 + GetPressReviews( PressReviewAddress);
end;
SetField(fieldComments, Value2);
DisplayResults;
end;
procedure GetMoviePicture( PictureAddress: string);
begin
GetPicture(PictureAddress, false);
end;
function GetCast(Address: string): string;
var
Line, Value: string;
LineNr: Integer;
NoInfiniteLoop : Integer;
BeginPos, EndPos: Integer;
Page: TStringList;
begin
Result := '';
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('Distributie', Page, 0);
Value := '';
if LineNr > -1 then
begin
LineNr := LineNr + 2;
Line := Page.GetString(LineNr);
NoInfiniteLoop := 0;
while ( pos('</table>', Line) < 1 ) and ( NoInfiniteLoop < 10) do
begin
NoInfiniteLoop := NoInfiniteLoop + 1;
Line := Page.GetString(LineNr + 1);
BeginPos := pos('">', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 2;
EndPos := pos('</a>', Line);
if EndPos < 1 then
EndPos := Length(Line);
if Value <> '' then
Value := Value + '; ';
Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
Line := Page.GetString(LineNr + 2);
BeginPos := pos('<td>', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 4;
EndPos := pos('</td>', Line);
if EndPos < 1 then
EndPos := Length(Line);
if Value <> '' then
Value := Value + ' ';
Value := Value + '(in rolul ' + copy(Line, BeginPos, EndPos - BeginPos) + ')';
Line := Page.GetString(LineNr + 4);
LineNr := LineNr + 4;
end;
HTMLDecode(Value);
Result := Value;
end;
Page.Free;
end;
function GetDescriptions(Address: string): string;
var
Line, Value: string;
LineNr: Integer;
BeginPos, EndPos: Integer;
Page: TStringList;
begin
Result := '';
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('Pagina principala', Page, 0);
if LineNr > -1 then
begin
Line := Page.GetString(LineNr + 1);
BeginPos := pos('<div class="section_title">', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 27;
EndPos := pos('</div>', Line);
if EndPos < 1 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLRemoveTags(Value);
Value := '<b>' + Value + '</b><br/>';
LineNr := LineNr + 2;
repeat
Line := Page.GetString(LineNr);
BeginPos := pos('<div class="section">', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 21
else
BeginPos := 1;
EndPos := pos('</div>', Line);
if EndPos < 1 then
EndPos := Length(Line) + 1;
if Value <> '' then
Value := Value + ' ';
Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
LineNr := LineNr + 1;
until (pos('</div>', Line) > 0) or (LineNr = Page.Count);
HTMLDecode(Value);
Result := Value;
end;
Page.Free;
end;
function GetPressReviews(Address: string): string;
var
Line, Value, Value2: string;
LineNr: Integer;
BeginPos, EndPos: Integer;
Page: TStringList;
begin
Result := '';
Value2 := '';
Value := '';
Page := TStringList.Create;
Page.Text := GetPage(Address);
LineNr := FindLine('<div class="section_title">', Page, 0);
while LineNr > -1 do
begin
Line := Page.GetString(LineNr);
if pos('a href=', Line) < 1 then
begin
BeginPos := pos('<div class="section_title">', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 27;
EndPos := pos('</div>', Line);
if EndPos < 1 then
EndPos := Length(Line);
Value := copy(Line, BeginPos, EndPos - BeginPos);
HTMLRemoveTags(Value);
Value := '<b>' + Value + '</b><br/>';
LineNr := LineNr + 2;
repeat
Line := Page.GetString(LineNr);
BeginPos := pos('<div class="section">', Line);
if BeginPos > 0 then
BeginPos := BeginPos + 21
else
BeginPos := 1;
EndPos := pos('</div>', Line);
if EndPos < 1 then
EndPos := Length(Line) + 1;
if Value <> '' then
Value := Value + ' ';
Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
LineNr := LineNr + 1;
until (pos('</div>', Line) > 0) or (LineNr = Page.Count);
Value2 := Value2 + Value;
end
else
LineNr := LineNr + 1;
LineNr := FindLine('<div class="section_title">', Page, LineNr);
end;
HTMLDecode(Value2);
Result := Value2;
Page.Free;
end;
procedure AddMoviesTitles(Page: TStringList);
var
Line: string;
LineNr: Integer;
MovieTitle, MovieAddress: string;
StartPos: Integer;
begin
LineNr := FindLine( 'Rezultatele cautarii', Page, 0);
if LineNr > -1 then
begin
PickTreeAdd('Filme', '');
LineNr := LineNr + 3;
Line := Page.GetString(LineNr);
repeat
StartPos := pos('href="', Line) + 5;
Delete(Line, 1, StartPos);
MovieAddress := Copy(Line, 1, pos('"', Line) - 1);
StartPos := Pos('">', Line) + 2;
MovieTitle := Copy(Line, StartPos, Pos('</i>', Line) - StartPos);
HTMLDecode(Movietitle);
Delete( Movietitle, Pos('</a>', Movietitle), 4);
Delete( Movietitle, Pos('<i>', Movietitle), 3);
PickTreeAdd(MovieTitle, 'http://www.cinemagia.ro' + MovieAddress);
LineNr := LineNr + 1;
Line := Page.GetString(LineNr);
until Pos('</div>', Line) > 0;
end;
end;
begin
if CheckVersion(3,4,0) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
if Input('Cinemagia.RO Import', 'Enter the title of the movie:', MovieName) then
begin
AnalyzePage('http://www.cinemagia.ro/search.php?q=' + UrlEncode(MovieName) + '&hist=0');
end;
end
else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.
I will try to fix/clean some of the code, and add parsing for the rest of the fields as soon as I have some free time