XBMC .nfo Export - question

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

XBMC .nfo Export - question

Post by rs232 »

Hi, I have a 2x questions about the XBMC .nfo Export script.

a) Why is it asking me the location where to save the .nfo once I run the script against the movies? I would expect this to be store in the very same location where the media is found

b) It seems like the <id> is not exported. Given I have the IMDB URL in the "URL" field it should (so I've seen it doing with other softwares) export the ttxxxxxx of reference
e.g. if the URL was: http://www.imdb.com/title/tt0499603/
This should be added to the .nfo
<id>tt0499603</id>


Thanks!
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

Ok I have made some progression in my personal setup.

This modified version of the script add the URL files at the end (as per NFO standard) and just saves the .nfo in the same folder where the media is located which works well for my needs.

Can I get some help on how I can also add the <id></id> filling this in with the ttxxxxxxx reference as per IMDB (e.g. URL)?

I'm stuck at this point
Thanks!

Code: Select all

program _XBMCNfo;
  uses
  FieldsUtils;
  
  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;
    fullPathFile, fullPathLink: string;
    fieldIdxUrl, fieldIdxFullPath: Integer;
   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;
//     fieldIdxFullPath := fieldSource;
//     DirSelected := GetFieldOrCustomField(fieldIdxFullPath);

      begin
      OutToFile := TStringList.Create;
//      SaveFileName := IncludeTrailingPathDelimiter(DirSelected) + GetField(fieldOriginalTitle) + '.nfo';
      SaveFileName := GetField(fieldSource) +  '.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>' + #13#10 + GetField(fieldUrl)));
      OutToFile.SaveToFile(SaveFileName);
      OutToFile.Free;
      FormatedData := ''
     end;
end.
:) :) :) :)
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

So you have in the URL field all the full IMDb links, and you want to keep only what's after "tt" ? Assuming that the address ends by a "/" after the number, under the series of FormatedData lines you may add this:

Code: Select all

 FormatedData := FormatedData +'   <id>' + TextBetween(GetField(fieldUrl), 'tt', '/') + '</id>'+#13#10; 
Also to have the TextBetween function you'll have to add StringUtils1 in the uses: and the beginning, change use FieldsUtils; to use FieldUtils, StringUtils1;
If you wish to keep the "tt" in the number, rather use TextBetween(GetField(fieldUrl), 'title/', '/') for example
rs232
Posts: 107
Joined: 2012-05-09 21:57:22

Post by rs232 »

Great, definitely give it a go tonight in my tests :-)

One more question please, the original script (as well as the modified version I posted) has problem with special characters.

e.g.

Code: Select all

20,13 - Purgatório
is exported as:

Code: Select all

20,13 Purgat├│rio
Is there any smart work-around to retain the original special characters?
I do see the :

Code: Select all

OutToFile.Append(UTF8Encode....
line but it doesn't seem to be enough to address the issue.
antp
Site Admin
Posts: 9630
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

Depends what XBMC expects.
If you have a sample working file from elsewhere it may be easier to see how it is supposed to be encoded when generated by AMC ;)
(to send to my by e-mail, zipped)
Post Reply