[PATCH] More pictures for a movie

Comments on existing version & Suggestions for future versions. If you want a new feature suggest it here. Discussions about beta versions also come in this section.
Post Reply
TekmanRO
Posts: 13
Joined: 2004-05-26 22:06:59
Location: Romania, Iasi

[PATCH] More pictures for a movie

Post by TekmanRO »

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:

Code: Select all

GetUDPicture(address: string; name: string): string;
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):

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>
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" :D 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 :/).

Image
Image

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.
If you want a sample script for importing more pictures, check this out (it's for the IMP Awards site), only as a proof of concept:

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.
TekmanRO
Posts: 13
Joined: 2004-05-26 22:06:59
Location: Romania, Iasi

Post by TekmanRO »

Ok, if anyone tried this, just let me know, don't wanna bother you with these patches if they're not useful to anyone... :)
Guest

Post by Guest »

Thanks, but i don't speak english, sorry...
Cela m'interresse, mais je ne comprend pas comment faire. Est-il possible de m'expliquer en français ?
Merci
TekmanRO
Posts: 13
Joined: 2004-05-26 22:06:59
Location: Romania, Iasi

Post by TekmanRO »

Hmm, my french is soo rusty... I only had some classes way back in primary school :ha:

I have used an online translation to obtain the following results (if it's not what it should be, please some french/english speaker let me know about it) :)

Ce texte est traduit en ligne. Je suis désolé s'il semble mauvais.
Ainsi, il est tout à fait simple d'utiliser ce dispositif. Installez simplement la dernière version d'AMC, et substituez alors le fichier d'EXE avec celui que j'ai fourni à celien. Vous lancez le nouvel EXE et vous êtes prêt à aller. Comme vous pouvez voir dans les screenshots, il y a 2 nouveaux boutons (ceux sont employés pour passer en revueles photos et les zones définies par utilisateur), et ajoutez par la suitemodifiez-ou effacez-les manuellement. Vous pouvez utiliser ces photos de vos séquences type d'importationet également dans le HTMLExportation de XML. Pour faire ceci, vous pouvez voir les exemples que j'ai écrits dans le poteau initial. Par exemple, l'utilisation juste le IMPAwards la séquence type modifiée pourobtenir toutes les images pour un film spécifique qu'elles ont là.
elman

Post by elman »

hi,

I tried it and it looks quite good, but there were some things I didn't like. First of all you can't resize window with images, so you can browse only small thumbs. Secondly big picture opens as modal window, so I can't surf my covers. :( And thirdly it doesn't stores link to the original image. I would prefer if it would move pictures to ant folder and sufix them with letter maybe. (catalog_22, catalog_22a, catalog_22b etc..)

And still I would't know if I would use it because these were things requested for version 4 and when it appears, it might do these things differently. Maybe if you could talk to Antoine and together find some way to store images and extra fields. Then I would be more than happy to use your enhacements until version 4 appears.

But I still appreciate your effort!
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

You are right, it would be nice to see together how to store pictures in the XML file so it would be compatible with version 4 (or 3.x) that will support multiple pictures.
TekmanRO
Posts: 13
Joined: 2004-05-26 22:06:59
Location: Romania, Iasi

Post by TekmanRO »

antp wrote:You are right, it would be nice to see together how to store pictures in the XML file so it would be compatible with version 4 (or 3.x) that will support multiple pictures.
As I wrote it now, the pictures (and UDFs) are saved like this. You have an XML node for each movie that is called... "Movie" :) This node has all fields saved as attributes.
Since the number of UDFs and pictures is variable for each movie, I thought of adding them as child nodes to the "Movie" node instead of attributes.

Basically, it looks something like this:

Code: Select all

<Movie Number="1" ....many attributes here.... >
    <UserDefinedField Name="Full Rating" Value="7.1"/>
    <UserDefinedField Name="Available on DVD" Value="Yes"/>
    <UDPicture Name="The Funny Cat" Path="C:\Documents and Settings\tekman\My Documents\My Pictures\00017777.jpg"/>
    <UDPicture Name="Beyond Compare" Path="C:\Documents and Settings\tekman\My Documents\My Pictures\Beyond_Compare.png"/>
    <UDPicture Name="Linux XP :D" Path="C:\Documents and Settings\tekman\My Documents\My Pictures\00004155.jpg"/>
</Movie>
So, for each user defined field, I add a new "UserDefinedField" node. This node can have 2 attributes, which are -of course- "Name" and "Value".
For each Picture, I add a new "UDPicture" node, which has 2 attributes also ("Name" and "Path"). The "Path" can be either relative or absolute. It is relative always to the path where the catalog resides. For example it can be "images\img1.jpg", which means that if the catalog is saved in "c:\my catalog\cat.xml", then the image will be found in "c:\my catalog\images\img1.jpg".

Any other fields I might add to pictures or UDFs, I will add as attributes to the respective node. For example, "Description" or "OriginalLink" for pictures.

Of course, I know that my solution is most likely not the best, so I'm waiting for sugestions on improving it. :wink:
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I was thinking of using a <pictures> field, like what I did in AMC 4 tests :

Code: Select all

   <pictures>
    <picture storage="absoluteLink" kind="JPEG" link="C:\Temp\img\Bad Boys 2 - FR 2.jpg"/>
    <picture storage="absoluteLink" kind="PNG" link="C:\Temp\img\Cypher - Affiche FR.png"/>
   </pictures>
Storage can be one of the following : absoluteLink, relativeLink, httpLink, stored
and kind can be : JPEG, GIF, PNG

httpLink would be for pictures located on a site (but cached locally), which could be useful for using IMDB pictures for not having to upload all pictures when uploading exported HTML for example.

stored would be for pictures stored in the database, since I wanted to replace the .amc by a .xml stored with its picture in a kind of ZIP file renamed to .amc
TekmanRO
Posts: 13
Joined: 2004-05-26 22:06:59
Location: Romania, Iasi

Post by TekmanRO »

Ok, roger that... :lol:
I will change all code for this format. I also started to make a tabbed version instead of these 2 dialogs.
It's a busy week at work, though (annual reviews :innocent:), but I'll get right back at these patches as soon as that's done with. :p
I know that my coding is not production-quality, mostly because I don't have so much time on my hands, but I will try to make it at least according to ant's specifications, so it will be smooth to upgrade the catalogs to version 3.5 (or 4) when they will be completed, and also allow users the possibility to use such features as more pictures for one movie or UDFs mean-while.
Post Reply