YAMMM mymovies.xml import
Posted: Sat Feb 13, 2010 1:10 pm
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.
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.