Page 1 of 1
XBMC-NFO script update
Posted: 2008-11-29 07:42:24
by Nicezia
Code: Select all
(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=Nicezia
Title=XBMC .nfo Export
Description=Exports Movies to individual .nfo files that XBMC can read for movie Information
Site=
Language=?
Version=1.0.32
Requires=3.5.1
Comments=Contains sample code written by antp to export actors
License=
GetInfo=0
[Options]
***************************************************)
program XBMCNfo;
var
MovieActors: string;
MovieGenre: string;
SavefileName: string;
DirSelected: string;
FormatedData: string;
OutToFile: TStringList;
function ActorsToXml(actors: string): string;
var
lstActor: TStringList;
iActor: Integer;
sActor: string;
begin
lstActor := TStringList.Create;
lstActor.Text := StringReplace(actors, ', ', #13#10);
for iActor := 0 to lstActor.Count - iActor do
begin
sActor := ' <actor>' + #13#10 + ' <name>' + lstActor.GetString(iActor) + '</name>' + #13#10 +' </actor>';
if lstActor.GetString(iActor) <> #13#10 then lstActor.SetString(iActor, sActor);
end;
Result := lstActor.Text;
lstActor.Free;
end;
function GenreToXML(genre: string): string;
var
lstGenre: TStringList;
iGenre: Integer;
sGenre: string;
begin
lstGenre := TStringList.Create;
lstGenre.Text := StringReplace(genre, ', ', #13#10);
for iGenre := 0 to lstGenre.Count -iGenre do
begin
sGenre := ' <genre>' + lstGenre.GetString(iGenre) + '</genre>';
lstGenre.SetString(iGenre, sGenre);
end
Result := lstGenre.Text;
lstGenre.Free;
end;
function ChooseTitle(Original: string; Translated: string): string;
begin
if Translated <> '' then Result := Translated else Result := Original
end;
begin
if DirSelected ='' then
begin
Input('Folder Select','Select Folder to save NFO files',DirSelected)
end;
begin
OutToFile := TStringList.Create;
SaveFileName := IncludeTrailingPathDelimiter(DirSelected) + GetField(fieldOriginalTitle) + '.nfo';
FormatedData := FormatedData +'<movie>'+#13#10;
FormatedData := FormatedData +' <title>'+ ChooseTitle(GetField(fieldOriginalTitle), GetField(fieldTranslatedTitle)) + '</title>'+#13#10;
FormatedData := FormatedData +' <rating>'+GetField(fieldRating)+'</rating>'+#13#10;
FormatedData := FormatedData +' <year>'+GetField(fieldYear)+'</year>'+#13#10;
(* FormatedData := FormatedData +' <top250>'+GetFeild(fieldWhatever)+'</top250>'+#13#10;
FormatedData := FormatedData +' <votes>'+GetField(fieldWhatever)+'</votes>'+#13#10;
FormatedData := FormatedData +' <outline>'+GetField(Whatever)+'</outline>'+#13#10; *)
FormatedData := FormatedData +' <plot>'+GetField(fieldDescription)+'</plot>'+#13#10;
FormatedData := FormatedData +' <tagline>'+GetField(fieldComments)+'</tagline>'+#13#10;
FormatedData := FormatedData +' <runtime>'+GetField(fieldLength)+'min</runtime>'+#13#10;
FormatedData := FormatedData +' <thumb>'+GetField(fieldOriginalTitle)+'.tbn</thumb>'+#13#10;
FormatedData := FormatedData +' <mpaa>X</mpaa>'+#13#10;
FormatedData := FormatedData +' <director>'+GetField(fieldDirector)+'</director>'+#13#10;
FormatedData := FormatedData +' <studio>'+GetField(fieldProducer)+'</studio>' + #13#10;
(* Run Actor Script here*)
MovieActors := ActorsToXML(GetField(fieldActors));
MovieGenre := GenreToXML(GetField(fieldCategory));
OutToFile.Append(UTF8Encode(FormatedData + MovieGenre + MovieActors + '</movie>'));
OutToFile.SaveToFile(SaveFileName);
OutToFile.Free;
FormatedData := ''
end;
end.
Updated in this version
*Select folder is universal on multiple file export (no continuous popup per file, all files will be exported to the folder you select)
*Translated title is default for title, but if translated title field is empty will default to original title, (original title is still used for filename.)
*Will output multiple genre fields if cateories are seperated by ", " (thats a comma and a space after it)
*Cleaned up code (Finally gave in and started learning Delphi as it seems much easier and cleaner than Visual Basic.NET)
*Script no longer outputs spaces after
To Do:
*MPAA Rating Field Information/IMDB title id info/etc
* Considering making this script a universal XML export. Allowing the user to set tags for each node of the xml before exporting, and/or selecting to export all information to a single file (to be imported into possible other managers)[/code]
Posted: 2009-02-01 23:45:19
by ihelfe
HI,
I find this script really useful, but I have no experience of scripting.
I am using this with the YAMJ program on Popcorn Hour, which can now use XMC NFO files and would like to know how to change the URL Field
I have added
FormatedData := FormatedData +' <id>'+GetField(fieldURL) +'</id>'+#13#10;
to the output file but ideally I only want the imdb # "tt0241303" rather than the whole "
http://imdb.com/title/tt0241303"
Can you advise how this is done.
Thank you
Posted: 2009-02-02 09:37:15
by antp
Hi,
You can do that for exampe:
Code: Select all
FormatedData := FormatedData +' <id>' + TextAfter(GetField(fieldURL), '/title/') + '</id>' + #13#10;
But you would have to add
after
Posted: 2009-02-02 11:41:25
by ihelfe
Perfect = thank you very much
Posted: 2009-04-02 06:51:05
by argus
can you do a quick mod so it exports all the movies in a single .xml file that can be imported directly into XMBC
Posted: 2009-04-06 21:40:24
by mikel
Hello
Can someone help. Exporting German characters does not work with this script.
eg:
Kräften exported becomes Kräften
so Characters like ö, ä, ü do not work.
Any suggestions why that is?
Thanks, Mikel
Posted: 2009-04-07 06:55:46
by antp
It is because the file is encoded in UTF8 (using UTF8Encode function), isn't that what is expected by XBMC ?
Posted: 2009-04-07 09:39:30
by mikel
Hello antp
Thanks for your quick reply.
Actually I do not know what is excpected for XBMC, I use it for YAMJ which is a Jukebox for the Popcorn Hour Movie Player.
Since the XBMC format is widly used, YAMJ also uses that nfo-format to generate the movie database for the jukebox.
If I work with just english files, everything works fine.
The great advantage of ANT is, that I can get german infos as well.
It seems that YAMJ expects ä, ö, and ü in the file.
Is there a way to encode those characters into the xml-file?
In my understanding, ä, ö and ü should be encoded correctly into UTF8.
When I safe a german text as UTF8 with editor, those characters are not corrupted. So my conclusion is that they should be not affected.
Am I wrong?
Thanks, Mikel
Posted: 2009-04-07 10:11:48
by bad4u
mikel wrote:It seems that YAMJ expects ä, ö, and ü in the file.
I did a short test and there
are german characters ä, ö and ü in the exported XML file. So it seems YAMJ needs something different or Popcorn hour does not show special characters at all.
Try changing
Code: Select all
OutToFile.Append(UTF8Encode(FormatedData + MovieGenre + MovieActors + '</movie>'));
to
Code: Select all
OutToFile.Append(FormatedData + MovieGenre + MovieActors + '</movie>');
or try replacing UTF8Encode with UTF8Decode, just to see what happens. Or maybe post a working YAMJ nfo file here, that shows such characters on the Popcorn box (if you have such file). If Popcorn Hour cannot handle these characters, you could at least use a short script and replace them by oe, ae and ue ("Kraeften").
Posted: 2009-04-07 10:31:29
by mikel
I will test tonight since I am at work right now
Thanks in the meantime.
I will report back.
Cheers, mikel
Posted: 2009-04-07 10:56:55
by bad4u
One more hint. YAMJ wiki says:
Code: Select all
XML Encoding
XML must be either provided in UTF-8 charset or the encoding must be explicitly specified in the xml header
Example:
<?xml version="1.0" encoding="windows-1252"?>
<movie>
...
If existing(old) NFO files do not have the described header and you do not want to re-encode or add the header to all the files, there is a parameter in the moviejukebox.properties which can be used to force the XML parser to read all the NFO files using the specified encoding.
mjb.forceNFOEncoding=YOUR-ENCODING
So UTF-8 Encoding in general should work correct. Maybe parameter mjb.forceNFOEncoding contains wrong encoding settings on your installation.
Posted: 2009-04-08 05:54:42
by mikel
@ bad4u
Thanks for pointing the section out the WIKI of YAMJ.
So:
I upgraded YAMJ to the latest version and violà, it's working.
Not sure what the problem was before.
So I can confirm that this script is working as expected.
Is is possible to also export all the pictures with this script? The pictures should also have the same filename as the nfo files.
I do this manually at the moment but it would safe some work if that was possible.
Also, I would like to export the IMDB-Link under the TAG <id>, but just the portion with the id.
That means the URL
http://www.imdb.com/title/tt0113189/ will be exported just as <id>tt0113189</id>
The IMDB-ID is very crucial for YAMJ in rebuiding the IMDB-Database if required.
I just love ANT!!! What a cool piece of software
Kind regards, Mikel
Posted: 2009-04-08 06:11:59
by bad4u
mikel wrote:Is is possible to also export all the pictures with this script? The pictures should also have the same filename as the nfo files.
Unfortunately it's not possible to export pictures via scripting.
Also, I would like to export the IMDB-Link under the TAG <id>, but just the portion with the id.
antp explained how to do that on his posting above. You only have to add the 2 lines of code.
Posted: 2009-04-08 07:37:04
by mikel
@ bad4u
Shame on me, I have completly missed that post above
Thanks for sticking my nose into it
Have a good day,
Mikel