[PATCH] More pictures for a movie
Posted: 2004-08-27 07:54:31
Hi,
I was in need of an option to add User Pictures to the catalog, so I decided to do it myself.
I thought that maybe some of you guys might find it an interesting feature to have, so I decided to put it up for download. Here it is: Patch.zip.
You need to apply it to the source code and re-compile.
If you preffer the compiled EXE, you can get it here.
I added scripting support through a new function that you can call from your script:
The address is the URL of the picture, and the name is the actual name of the picture.
I also added support for export. It's pretty tricky, since you can have 1 picture, n pictures or no picture at all. This is how it can be done (just an example):
As you can see, basically you want to start a block with $$ITEM_USERPICTURE_BEGIN, and finish it with $$ITEM_USERPICTURE_END. Whatever is between this 2 tags gets repeated for all the pictures you add to the movie. In between these tags, you can use the $$PICTURE_PATH and $$PICTURE_NAME.
I also added a "rudimentary" GUI for manually adding and modifying/deleting user pictures . You can find a button on the main frame, that leads you to a poorly-designed dialog for this purpose. It doesn't have language support (only english for now ).
You can add as many pictures as you want to each movie, there is no restriction. You can have movies with no pictures, and movies with hundreds of them, it is your decision.
You can add pictures by hand, but the true power of the feature is revealed when adding pictures from your script, such as downloading them from the net.
Please note that these fields work only for XML catalogs. If you save your catalog in AMC format, you lose all defined pictures. When downloaded from the net, the pics are saved in the same directory with the catalog, and when exporting to HTML, they're automatically copied to the destination directory.
The feature is still rudimentary, and problems may arrise, but it pratically gets the job done, and that's what I was looking for. You can use it if you wish, but back up you catalog before doing so, cause I take no responsability for what it might do to it.
So, please note these facts before using it:
I was in need of an option to add User Pictures to the catalog, so I decided to do it myself.
I thought that maybe some of you guys might find it an interesting feature to have, so I decided to put it up for download. Here it is: Patch.zip.
You need to apply it to the source code and re-compile.
If you preffer the compiled EXE, you can get it here.
I added scripting support through a new function that you can call from your script:
Code: Select all
GetUDPicture(address: string; name: string): string;
I also added support for export. It's pretty tricky, since you can have 1 picture, n pictures or no picture at all. This is how it can be done (just an example):
Code: Select all
<table><tr>
$$ITEM_USERPICTURE_BEGIN
<td>
<img height="250" src="$$PICTURE_PATH">
</td>
$$ITEM_USERPICTURE_END
</tr>
<tr>
$$ITEM_USERPICTURE_BEGIN
<td>
<center><b>$$PICTURE_NAME</b></center>
</td>
$$ITEM_USERPICTURE_END
</tr></table>
I also added a "rudimentary" GUI for manually adding and modifying/deleting user pictures . You can find a button on the main frame, that leads you to a poorly-designed dialog for this purpose. It doesn't have language support (only english for now ).
You can add as many pictures as you want to each movie, there is no restriction. You can have movies with no pictures, and movies with hundreds of them, it is your decision.
You can add pictures by hand, but the true power of the feature is revealed when adding pictures from your script, such as downloading them from the net.
Please note that these fields work only for XML catalogs. If you save your catalog in AMC format, you lose all defined pictures. When downloaded from the net, the pics are saved in the same directory with the catalog, and when exporting to HTML, they're automatically copied to the destination directory.
The feature is still rudimentary, and problems may arrise, but it pratically gets the job done, and that's what I was looking for. You can use it if you wish, but back up you catalog before doing so, cause I take no responsability for what it might do to it.
So, please note these facts before using it:
- You can add user pictures to a catalog only after saving it. (so if you start a new catalog, save it first, then begin importing;
You can use this feature (along with the user defined fields feature) only with XML catalogs (it does not and will not work with the binary AMC format).
Backup your main catalog before using this feature, it is not fully tested, and probably has a lot of bugs.
Code: Select all
// GETINFO SCRIPTING
// IMP Awards (only pictures) by TekmanRO
(***************************************************
* Movie importation script for: *
* ImpAwards.com (EN), http://www.ImpAwards.com *
* *
* *
* 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 *
***************************************************
THIS SCRIPT SHOULD BE CONSIDERED ONLY A PROOF OF CONCEPT FOR USER PICTURES, NOT
PRODUCTION QUALITY. USE AT YOUR OWN RISK :P
Basically meaning it CAN be done a lot smarter :)
*)
program IMPAwards;
var
MovieName: string;
const
BaseURL = 'http://www.impawards.com/cgi-bin/htsearch?method=or&words=';
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;
LineNr: Integer;
PosIni, PosFin: Integer;
Line, SubLine: string;
Title, DirURL: string;
txtTemp: string;
begin
Page := TStringList.Create;
Page.Text := GetPage(Address);
if Pos('IMP could not find any matches for', Page.Text) > 0 then
begin
ShowMessage('No results found.');
end else
begin
PickTreeClear;
PickTreeAdd('Results found for "' + MovieName + '":', '');
LineNr := 0;
while LineNr < Page.Count do
begin
SubLine := Page.GetString(LineNr);
txtTemp := '<dl><dt><strong><a href="';
PosIni := pos(txtTemp, SubLine);
if PosIni > 0 then
begin
SubLine := Copy(SubLine, PosIni + Length(txtTemp), Length(SubLine));
txtTemp := '">';
PosFin := pos(txtTemp, SubLine);
DirURL := Copy(SubLine, 1, PosFin - 1);
SubLine := Copy(SubLine, PosFin + Length(txtTemp), Length(SubLine));
txtTemp := '</a>';
PosFin := pos(txtTemp, SubLine);
Title := Copy(SubLine, 1, PosFin - 1);
PickTreeAdd(Title, DirURL);
end;
LineNr := LineNr + 1;
end;
Page.Free;
if PickTreeExec(Address) then
AnalyzeMoviePage(Address);
end;
end;
procedure AnalyzeMoviePage(Address: string);
var
Page: TStringList;
PosIni, PosFin: Integer;
dirBase: string;
txtTemp: string;
ImgTMP: string;
iPicsToImport, i : integer;
sPicName : string;
begin
Page := TStringList.Create;
Page.Text := StringReplace(GetPage(Address), '<br>', #13#10);
PosFin := 0;
dirBase := Address;
PosIni := pos('/', dirBase);
while PosIni > 0 do
begin
PosFin := PosFin + PosIni;
dirBase := Copy(dirBase, PosIni + 1, Length(DirBase));
PosIni := pos('/', dirBase);
end;
dirBase := Copy(Address, 1, PosFin);
txtTemp := '<img SRC="posters/';
PosIni := pos(txtTemp, Page.Text);
if PosIni > 0 then
begin
txtTemp := Copy(Page.Text, PosIni + Length(txtTemp), 3*Length(txtTemp));
PosFin := pos('"', txtTemp);
ImgTMP := Copy(txtTemp, 1, PosFin - 1);
iPicsToImport := 1;
if pos( 'ver2', Page.Text) > 0 then
iPicsToImport := 2;
if pos( 'ver3', Page.Text) > 0 then
iPicsToImport := 3;
if pos( 'ver4', Page.Text) > 0 then
iPicsToImport := 4;
if pos( 'ver5', Page.Text) > 0 then
iPicsToImport := 5;
if pos( 'ver6', Page.Text) > 0 then
iPicsToImport := 6;
if pos( 'ver7', Page.Text) > 0 then
iPicsToImport := 7;
if pos( 'ver8', Page.Text) > 0 then
iPicsToImport := 8;
if pos( 'ver9', Page.Text) > 0 then
iPicsToImport := 9;
if pos( 'ver', ImgTMP) > 0 then
begin
txtTemp := copy( ImgTMP, pos( '_ver', ImgTMP), 5);
sPicName := StringReplace( ImgTMP, txtTemp, '');
GetUDPicture( dirBase + 'posters/' + sPicName, 'some pic 0');
for i := 1 to iPicsToImport do
begin
sPicName := StringReplace( ImgTMP, txtTemp, '_ver' + Chr( i + Ord('0')));
GetUDPicture( dirBase + 'posters/' + sPicName, 'some pic ' + Chr( i + Ord('0')));
end;
end
else
GetUDPicture( dirBase + 'posters/' + ImgTMP, 'some pic');
end;
Page.Free;
DisplayResults;
end;
begin
if CheckVersion(3,4,0) then
begin
MovieName := GetField(fieldOriginalTitle);
if MovieName = '' then
MovieName := GetField(fieldTranslatedTitle);
Input('IMP Awards Import', 'Enter the title of the movie:', MovieName);
AnalyzePage(BaseURL + UrlEncode(MovieName));
end else
ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
end.