YAMMM mymovies.xml import

Post Reply
andyselects
Posts: 11
Joined: Sun Jan 31, 2010 7:32 pm

YAMMM mymovies.xml import

Post by andyselects »

Not sure whether this is any use for anybody.
I use YAMMM to automatically update my movie collection with data from IMDB. This creates a mymovies.xml file containing information about the actors/directors, ratings, genres etc. It also creates a folder.jpg and some other cover.jpgs too.

I've written a little script that will look in the folder of the movie for this mymovies.xml file and automatically populate this information within WildMediaServer. It'll also set the thumbnail image to the Folder.jpg.

Please feel free to use/modify the code in anyway.
I've not written any PascalScript before so go easy on me but I'd welcome any comments too.

NOTE: This will overwrite all the information you may have entered manually.

Code: Select all

function GetThumbnail( XMLRoot : TXMLItem ) : string;
   var XMLCovers : TXMLItem  ;
begin
   XMLCovers := XMLRoot.Find("Covers");
   Result := "";
      
   if XMLCovers <> nil then 
      Result := XMLCovers.Find("Front").Value;
end;

procedure GetPeople( XMLRoot : TXMLItem; 
                     var actors : string; 
                     var directors : string;
                     var producers : string;  );
   var XMLPeopleRoot : TXMLItem;       
   var XMLPerson : TXMLItem;   
   var Name: string;
   var i : Integer;
begin
   actors := "";   
   directors := "";   
   producers := "";

   XMLPeopleRoot := XMLRoot.Find("Persons");    
   if XMLPeopleRoot <> nil then begin   
      for i := 0 To XMLPeopleRoot.Count - 1 do begin
         XMLPerson := XMLPeopleRoot[i];
         Name := XMLPerson.Find("Name").Value;
                  
         if XMLPerson.Find("Type").Value = "Actor" then begin         
            if Length(actors) = 0 then
               actors := Name
            else
               actors := actors + "," + Name       
         end         
         else if XMLPerson.Find("Type").Value = "Director" then begin         
            if Length(directors) = 0 then
               directors := Name
            else
               directors := directors + "," + Name       
         end         
         else if XMLPerson.Find("Type").Value = "Producer" then begin         
            if Length(producers) = 0 then
               producers := Name
            else
               producers := producers + "," + Name 
         end
      end;
   end;
end;

function GetGenres( XMLRoot : TXMLItem ) : string;
   var XMLGenreRoot : TXMLItem;   
   var genres : string;   
   var i : Integer;
begin
   XMLGenreRoot := XMLRoot.Find("Genres");
   genres := "";
      
   if XMLGenreRoot <> nil then begin
      for i := 0 To XMLGenreRoot.Count - 1 do begin  
         if Length(genres) = 0 then         
            genres := XMLGenreRoot[i].Value
         else
            genres := genres + "," + XMLGenreRoot[i].Value
      end
   end; 

   Result := genres;
end;

function GetItemAsString(XMLRoot : TXMLItem; requiredData : string) : string ;
   var XMLItemData : TXMLItem;
begin
   XMLItemData := XMLRoot.Find(requiredData);
   if XMLItemData <> nil then
      Result := XMLItemData.Value      
   else   
      Result := ""         
end;


procedure ImportMetaData(XMLRoot : TXMLItem; TheMediaItem : TWmsScriptMediaItem);
   var title, description, year, runningTime, rating: string;
   var actors, directors, producers : string;   
   var XMLTitle: TXMLItem;  
begin
      title :=  GetItemAsString(XMLRoot, "LocalTitle");
      description := GetItemAsString(XMLRoot, "Description");
      rating := GetItemAsString(XMLRoot, "IMDBrating");
      year := GetItemAsString(XMLRoot, "ProductionYear");
      runningTime := GetItemAsString(XMLRoot, "RunningTime");  
                                    
      TheMediaItem.Properties[mpiTitle] := title;
      TheMediaItem.Properties[mpiYear] := year;
      TheMediaItem.Properties[mpiComment] := description;
      TheMediaItem.Properties[mpiRating] := rating; 
      TheMediaItem.Properties[mpiGenre] := GetGenres(XMLRoot);      
      TheMediaItem.Properties[mpiThumbnail] := GetThumbnail(XMLRoot);
 
      GetPeople(XMLRoot, actors, directors, producers);       
      TheMediaItem.Properties[mpiActor] := actors;      
      TheMediaItem.Properties[mpiDirector] := directors;     
      TheMediaItem.Properties[mpiProducer] := producers;        

end;

function GetMetaDataForItem(TheMediaItem : TWmsScriptMediaItem) : boolean;
var loadDir, movieXmlFileName, fullPath: string;
var XMLDocument: TXMLDocument;   
 
begin
   Result := false;
   movieXmlFileName := "mymovies.xml";
   loadDir := IncludeTrailingBackslash(ExtractFilePath(TheMediaItem.Properties[mpiFilePath]));   
   fullPath := loadDir + movieXmlFileName;   

   if FileExists(fullPath) then begin   
      XMLDocument := TXMLDocument.Create;      
      try       
         XMLDocument.LoadFromFile(fullPath);
         if XMLDocument.Root.Name = "Title" then begin   
            ImportMetaData(XMLDocument.Root, TheMediaItem);             
            Result := true;            
         end;
      finally      
         XMLDocument.Free         
      end;
   end;                          
end;

var
  i, iSuccessCount: Integer;
  MediaItemList: TWmsScriptMediaItemList;
begin
  MediaItemList := WmsCurrentMediaListItems;
  try
    iSuccessCount := 0;  
    if MediaItemList.Count > 0 then begin
      WmsShowProgress('Load metadata...');
      try
        for i := 0 to MediaItemList.Count - 1 do begin
          if WmsCancelPressed then
            Break
          else begin  
            if GetMetaDataForItem(MediaItemList[i]) then
               Inc(iSuccessCount);
             
            WmsSetProgress(Round(((i + 1) / MediaItemList.Count) * 100))
          end  
        end  
      finally
        WmsHideProgress
      end      
    end;
    if WmsCancelPressed then
      MessageDlg('Load aborted by the user.', mtError, mbOK, 0)
    else if iSuccessCount > 0 then
      MessageDlg('Load metadata was successful.', mtInformation, mbOK, 0)
    else
      MessageDlg('No information available for load.', mtError, mbOK, 0)
  finally
    MediaItemList.Free
  end;
  WmsDatabaseAutoSave;
  ProcessMediaResult := True      
end.
Eugene
Posts: 2940
Joined: Tue Nov 17, 2009 8:05 pm

Re: YAMMM mymovies.xml import

Post by Eugene »

Great, I think it is in any case it will be useful to other users.
mikinho
Posts: 1
Joined: Wed Feb 17, 2010 4:21 pm

Re: YAMMM mymovies.xml import

Post by mikinho »

Hi, I'm the author of Yammm. If there is any interest in having Yammm create the native metadata for Wild Media Server directly please let me know and I'd be happy to add it.
Eugene
Posts: 2940
Joined: Tue Nov 17, 2009 8:05 pm

Re: YAMMM mymovies.xml import

Post by Eugene »

Hi,
mikinho wrote:Hi, I'm the author of Yammm. If there is any interest in having Yammm create the native metadata for Wild Media Server directly please let me know and I'd be happy to add it.
Thanks for the offer, but the metadata WMS is very native (number-based). I do not think it will be convenient for you. Rather, the WMS will be added to support any format that supports Yammm.
snifferr
Posts: 1
Joined: Mon Mar 08, 2010 9:04 pm

Re: YAMMM mymovies.xml import

Post by snifferr »

Hi,

I've just downloaded WMS as i love the idea of building a DLNA server using mymovies.xml metadata.

Please could you explain how i run the above code to populate the movie details and folder.jpg to WMS?

Many thanks in advance.

Snifferr
Eugene
Posts: 2940
Joined: Tue Nov 17, 2009 8:05 pm

Re: YAMMM mymovies.xml import

Post by Eugene »

Hi,
snifferr wrote:
I've just downloaded WMS as i love the idea of building a DLNA server using mymovies.xml metadata.

Please could you explain how i run the above code to populate the movie details and folder.jpg to WMS?

Many thanks in advance.

Snifferr
Example, http://www.wildmediaserver.com/forum/vi ... p=452#p452
manichon
Posts: 2
Joined: Wed Aug 11, 2010 7:54 pm

Re: YAMMM mymovies.xml import

Post by manichon »

Hello, noob here, just one question, do I have to select a movie folder and then click on the button for the script or is there a way for the script to run automatically on every movie folder?
Eugene
Posts: 2940
Joined: Tue Nov 17, 2009 8:05 pm

Re: YAMMM mymovies.xml import

Post by Eugene »

Hello,
manichon wrote:do I have to select a movie folder and then click on the button for the script or is there a way for the script to run automatically on every movie folder?
Modified version http://www.wildmediaserver.com/forum/vi ... 3357#p3357
manichon
Posts: 2
Joined: Wed Aug 11, 2010 7:54 pm

Re: YAMMM mymovies.xml import

Post by manichon »

Thanks a lot Eugene!
Post Reply