2014-07-07 18:41:03 -07:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
|
|
|
|
using MediaBrowser.Model.Configuration;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
2014-07-11 19:31:08 -07:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
using MediaBrowser.XbmcMetadata.Configuration;
|
2014-07-07 18:41:03 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2014-07-08 17:46:11 -07:00
|
|
|
|
using System.Threading;
|
2014-07-07 18:41:03 -07:00
|
|
|
|
using System.Xml;
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Controller.IO;
|
2015-01-17 13:12:02 -07:00
|
|
|
|
using MediaBrowser.Model.Extensions;
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-10-25 19:53:47 -07:00
|
|
|
|
using MediaBrowser.Model.Xml;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.XbmcMetadata.Savers
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
public abstract class BaseNfoSaver : IMetadataFileSaver
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
|
|
|
|
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
|
|
|
|
|
2016-08-26 21:33:18 -07:00
|
|
|
|
private static readonly Dictionary<string, string> CommonTags = new[] {
|
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
"plot",
|
|
|
|
|
"customrating",
|
|
|
|
|
"lockdata",
|
|
|
|
|
"type",
|
|
|
|
|
"dateadded",
|
|
|
|
|
"title",
|
|
|
|
|
"rating",
|
|
|
|
|
"year",
|
|
|
|
|
"sorttitle",
|
|
|
|
|
"mpaa",
|
|
|
|
|
"mpaadescription",
|
|
|
|
|
"aspectratio",
|
|
|
|
|
"website",
|
|
|
|
|
"collectionnumber",
|
|
|
|
|
"tmdbid",
|
|
|
|
|
"rottentomatoesid",
|
|
|
|
|
"language",
|
|
|
|
|
"tvcomid",
|
|
|
|
|
"budget",
|
|
|
|
|
"revenue",
|
|
|
|
|
"tagline",
|
|
|
|
|
"studio",
|
|
|
|
|
"genre",
|
|
|
|
|
"tag",
|
|
|
|
|
"runtime",
|
|
|
|
|
"actor",
|
|
|
|
|
"criticratingsummary",
|
|
|
|
|
"criticrating",
|
|
|
|
|
"fileinfo",
|
|
|
|
|
"director",
|
|
|
|
|
"writer",
|
|
|
|
|
"trailer",
|
|
|
|
|
"premiered",
|
|
|
|
|
"releasedate",
|
|
|
|
|
"outline",
|
|
|
|
|
"id",
|
|
|
|
|
"votes",
|
|
|
|
|
"credits",
|
|
|
|
|
"originaltitle",
|
|
|
|
|
"watched",
|
|
|
|
|
"playcount",
|
|
|
|
|
"lastplayed",
|
|
|
|
|
"art",
|
|
|
|
|
"resume",
|
|
|
|
|
"biography",
|
|
|
|
|
"formed",
|
|
|
|
|
"review",
|
|
|
|
|
"style",
|
|
|
|
|
"imdbid",
|
|
|
|
|
"imdb_id",
|
|
|
|
|
"plotkeyword",
|
2016-10-09 00:18:43 -07:00
|
|
|
|
"country",
|
2014-06-29 20:04:50 -07:00
|
|
|
|
"audiodbalbumid",
|
|
|
|
|
"audiodbartistid",
|
|
|
|
|
"awardsummary",
|
|
|
|
|
"enddate",
|
|
|
|
|
"lockedfields",
|
|
|
|
|
"metascore",
|
|
|
|
|
"zap2itid",
|
|
|
|
|
"tvrageid",
|
|
|
|
|
"gamesdbid",
|
|
|
|
|
|
|
|
|
|
"musicbrainzartistid",
|
|
|
|
|
"musicbrainzalbumartistid",
|
|
|
|
|
"musicbrainzalbumid",
|
|
|
|
|
"musicbrainzreleasegroupid",
|
|
|
|
|
"tvdbid",
|
2014-09-26 19:28:13 -07:00
|
|
|
|
"collectionitem",
|
|
|
|
|
|
|
|
|
|
"isuserfavorite",
|
2016-07-08 11:10:38 -07:00
|
|
|
|
"userrating",
|
|
|
|
|
|
|
|
|
|
"countrycode"
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
}.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
2016-10-25 19:53:47 -07:00
|
|
|
|
protected BaseNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
|
2014-07-08 17:46:11 -07:00
|
|
|
|
{
|
2014-07-11 19:31:08 -07:00
|
|
|
|
Logger = logger;
|
2016-10-25 19:53:47 -07:00
|
|
|
|
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
|
2014-07-08 17:46:11 -07:00
|
|
|
|
UserDataManager = userDataManager;
|
|
|
|
|
UserManager = userManager;
|
|
|
|
|
LibraryManager = libraryManager;
|
|
|
|
|
ConfigurationManager = configurationManager;
|
|
|
|
|
FileSystem = fileSystem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected IFileSystem FileSystem { get; private set; }
|
|
|
|
|
protected IServerConfigurationManager ConfigurationManager { get; private set; }
|
|
|
|
|
protected ILibraryManager LibraryManager { get; private set; }
|
|
|
|
|
protected IUserManager UserManager { get; private set; }
|
|
|
|
|
protected IUserDataManager UserDataManager { get; private set; }
|
2014-07-11 19:31:08 -07:00
|
|
|
|
protected ILogger Logger { get; private set; }
|
2016-10-25 19:53:47 -07:00
|
|
|
|
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
|
2014-07-08 17:46:11 -07:00
|
|
|
|
|
2015-01-03 22:55:34 -07:00
|
|
|
|
protected ItemUpdateType MinimumUpdateType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ConfigurationManager.GetNfoConfiguration().SaveImagePathsInNfo)
|
|
|
|
|
{
|
|
|
|
|
return ItemUpdateType.ImageUpdate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ItemUpdateType.MetadataDownload;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
public string Name
|
2014-09-26 19:28:13 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return SaverName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string SaverName
|
2014-07-08 17:46:11 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-11-10 20:41:55 -07:00
|
|
|
|
return "Nfo";
|
2014-07-08 17:46:11 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 21:42:26 -07:00
|
|
|
|
public string GetSavePath(IHasMetadata item)
|
|
|
|
|
{
|
|
|
|
|
return GetLocalSavePath(item);
|
|
|
|
|
}
|
2015-03-31 12:33:38 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the save path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
2014-10-21 21:42:26 -07:00
|
|
|
|
protected abstract string GetLocalSavePath(IHasMetadata item);
|
2014-07-08 17:46:11 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the name of the root element.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
protected abstract string GetRootElementName(IHasMetadata item);
|
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
/// <summary>
|
2014-07-08 17:46:11 -07:00
|
|
|
|
/// Determines whether [is enabled for] [the specified item].
|
2014-06-29 20:04:50 -07:00
|
|
|
|
/// </summary>
|
2014-07-08 17:46:11 -07:00
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="updateType">Type of the update.</param>
|
|
|
|
|
/// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
|
|
|
|
|
public abstract bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType);
|
|
|
|
|
|
|
|
|
|
protected virtual List<string> GetTagsUsed()
|
|
|
|
|
{
|
|
|
|
|
return new List<string>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save(IHasMetadata item, CancellationToken cancellationToken)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var path = GetSavePath(item);
|
2015-03-31 12:33:38 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
using (var memoryStream = new MemoryStream())
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
Save(item, memoryStream, path);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
memoryStream.Position = 0;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
SaveToFile(memoryStream, path);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
private void SaveToFile(Stream stream, string path)
|
|
|
|
|
{
|
2015-09-27 08:00:57 -07:00
|
|
|
|
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
|
|
|
|
|
2016-10-25 19:53:47 -07:00
|
|
|
|
var file = FileSystem.GetFileInfo(path);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
var wasHidden = false;
|
|
|
|
|
|
|
|
|
|
// This will fail if the file is hidden
|
|
|
|
|
if (file.Exists)
|
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
if (file.IsHidden)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
FileSystem.SetHidden(path, false);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
wasHidden = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 12:02:04 -07:00
|
|
|
|
using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
stream.CopyTo(filestream);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 21:21:23 -07:00
|
|
|
|
if (wasHidden || ConfigurationManager.Configuration.SaveMetadataHidden)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
FileSystem.SetHidden(path, true);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
private void Save(IHasMetadata item, Stream stream, string xmlPath)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var settings = new XmlWriterSettings
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
Indent = true,
|
|
|
|
|
Encoding = Encoding.UTF8,
|
|
|
|
|
CloseOutput = false
|
2014-06-29 20:04:50 -07:00
|
|
|
|
};
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(stream, settings))
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var root = GetRootElementName(item);
|
|
|
|
|
|
|
|
|
|
writer.WriteStartDocument(true);
|
|
|
|
|
|
|
|
|
|
writer.WriteStartElement(root);
|
|
|
|
|
|
|
|
|
|
var baseItem = item as BaseItem;
|
|
|
|
|
|
|
|
|
|
if (baseItem != null)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
AddCommonNodes(baseItem, writer, LibraryManager, UserManager, UserDataManager, FileSystem, ConfigurationManager);
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
WriteCustomElements(item, writer);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var hasMediaSources = baseItem as IHasMediaSources;
|
|
|
|
|
|
|
|
|
|
if (hasMediaSources != null)
|
|
|
|
|
{
|
|
|
|
|
AddMediaInfo(hasMediaSources, writer);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var tagsUsed = GetTagsUsed();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
AddCustomTags(xmlPath, tagsUsed, writer, Logger, FileSystem);
|
2014-07-08 17:46:11 -07:00
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
2014-07-11 19:31:08 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
}
|
2016-10-25 19:53:47 -07:00
|
|
|
|
catch (IOException)
|
2014-12-22 20:58:14 -07:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2015-03-31 12:33:38 -07:00
|
|
|
|
catch (XmlException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error reading existng nfo", ex);
|
|
|
|
|
}
|
2014-07-08 17:46:11 -07:00
|
|
|
|
|
|
|
|
|
writer.WriteEndElement();
|
|
|
|
|
|
|
|
|
|
writer.WriteEndDocument();
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
protected abstract void WriteCustomElements(IHasMetadata item, XmlWriter writer);
|
|
|
|
|
|
|
|
|
|
public static void AddMediaInfo<T>(T item, XmlWriter writer)
|
|
|
|
|
where T : IHasMediaSources
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteStartElement("fileinfo");
|
|
|
|
|
writer.WriteStartElement("streamdetails");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var mediaSource = item.GetMediaSources(false).First();
|
|
|
|
|
|
|
|
|
|
foreach (var stream in mediaSource.MediaStreams)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteStartElement(stream.Type.ToString().ToLower());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(stream.Codec))
|
|
|
|
|
{
|
2016-01-14 10:17:21 -07:00
|
|
|
|
var codec = stream.Codec;
|
|
|
|
|
|
|
|
|
|
if ((stream.CodecTag ?? string.Empty).IndexOf("xvid", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
|
|
|
|
codec = "xvid;";
|
|
|
|
|
}
|
|
|
|
|
else if ((stream.CodecTag ?? string.Empty).IndexOf("divx", StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
|
|
{
|
|
|
|
|
codec = "divx;";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writer.WriteElementString("codec", codec);
|
|
|
|
|
writer.WriteElementString("micodec", codec);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.BitRate.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("bitrate", stream.BitRate.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.Width.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("width", stream.Width.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.Height.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("height", stream.Height.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(stream.AspectRatio))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("aspect", stream.AspectRatio);
|
|
|
|
|
writer.WriteElementString("aspectratio", stream.AspectRatio);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var framerate = stream.AverageFrameRate ?? stream.RealFrameRate;
|
|
|
|
|
|
|
|
|
|
if (framerate.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("framerate", framerate.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(stream.Language))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("language", stream.Language);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var scanType = stream.IsInterlaced ? "interlaced" : "progressive";
|
|
|
|
|
if (!string.IsNullOrEmpty(scanType))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("scantype", scanType);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.Channels.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("channels", stream.Channels.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.SampleRate.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("samplingrate", stream.SampleRate.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("default", stream.IsDefault.ToString());
|
|
|
|
|
writer.WriteElementString("forced", stream.IsForced.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
if (stream.Type == MediaStreamType.Video)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
if (mediaSource.RunTimeTicks.HasValue)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
var timespan = TimeSpan.FromTicks(mediaSource.RunTimeTicks.Value);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("duration", Convert.ToInt32(timespan.TotalMinutes).ToString(UsCulture));
|
|
|
|
|
writer.WriteElementString("durationinseconds", Convert.ToInt32(timespan.TotalSeconds).ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var video = item as Video;
|
|
|
|
|
|
|
|
|
|
if (video != null)
|
|
|
|
|
{
|
|
|
|
|
//AddChapters(video, builder, itemRepository);
|
|
|
|
|
|
|
|
|
|
if (video.Video3DFormat.HasValue)
|
|
|
|
|
{
|
|
|
|
|
switch (video.Video3DFormat.Value)
|
|
|
|
|
{
|
|
|
|
|
case Video3DFormat.FullSideBySide:
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("format3d", "FSBS");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
break;
|
|
|
|
|
case Video3DFormat.FullTopAndBottom:
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("format3d", "FTAB");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
break;
|
|
|
|
|
case Video3DFormat.HalfSideBySide:
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("format3d", "HSBS");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
break;
|
|
|
|
|
case Video3DFormat.HalfTopAndBottom:
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("format3d", "HTAB");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
break;
|
2016-02-11 12:11:28 -07:00
|
|
|
|
case Video3DFormat.MVC:
|
|
|
|
|
writer.WriteElementString("format3d", "MVC");
|
|
|
|
|
break;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteEndElement();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteEndElement();
|
|
|
|
|
writer.WriteEndElement();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 12:28:33 -07:00
|
|
|
|
public const string DateAddedFormat = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds the common nodes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Task.</returns>
|
2014-07-08 17:46:11 -07:00
|
|
|
|
public static void AddCommonNodes(BaseItem item, XmlWriter writer, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataRepo, IFileSystem fileSystem, IServerConfigurationManager config)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
var writtenProviderIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
var overview = (item.Overview ?? string.Empty)
|
|
|
|
|
.StripHtml()
|
|
|
|
|
.Replace(""", "'");
|
|
|
|
|
|
|
|
|
|
var options = config.GetNfoConfiguration();
|
|
|
|
|
|
|
|
|
|
if (item is MusicArtist)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("biography", overview);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
else if (item is MusicAlbum)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("review", overview);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("plot", overview);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 09:18:12 -07:00
|
|
|
|
if (item is Video)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-17 09:18:12 -07:00
|
|
|
|
var outline = (item.ShortOverview ?? string.Empty)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
.StripHtml()
|
|
|
|
|
.Replace(""", "'");
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("outline", outline);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("outline", overview);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.CustomRating))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("customrating", item.CustomRating);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("lockdata", item.IsLocked.ToString().ToLower());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
if (item.LockedFields.Count > 0)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("lockedfields", string.Join("|", item.LockedFields.Select(i => i.ToString()).ToArray()));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
2014-07-08 17:46:11 -07:00
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(item.DisplayMediaType))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("type", item.DisplayMediaType);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 12:28:33 -07:00
|
|
|
|
writer.WriteElementString("dateadded", item.DateCreated.ToLocalTime().ToString(DateAddedFormat));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("title", item.Name ?? string.Empty);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2016-10-30 21:28:23 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.OriginalTitle))
|
2015-03-09 18:30:20 -07:00
|
|
|
|
{
|
2016-10-30 21:28:23 -07:00
|
|
|
|
writer.WriteElementString("originaltitle", item.OriginalTitle);
|
2015-03-31 12:33:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-20 20:35:22 -07:00
|
|
|
|
var people = libraryManager.GetPeople(item);
|
|
|
|
|
|
|
|
|
|
var directors = people
|
2014-06-29 20:04:50 -07:00
|
|
|
|
.Where(i => IsPersonType(i, PersonType.Director))
|
|
|
|
|
.Select(i => i.Name)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var person in directors)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("director", person);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-20 20:35:22 -07:00
|
|
|
|
var writers = people
|
2014-06-30 06:28:38 -07:00
|
|
|
|
.Where(i => IsPersonType(i, PersonType.Writer))
|
2014-06-29 20:04:50 -07:00
|
|
|
|
.Select(i => i.Name)
|
2014-06-30 06:28:38 -07:00
|
|
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var person in writers)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("writer", person);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 18:41:03 -07:00
|
|
|
|
foreach (var person in writers)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("credits", person);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasTrailer = item as IHasTrailers;
|
|
|
|
|
if (hasTrailer != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var trailer in hasTrailer.RemoteTrailers)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("trailer", GetOutputTrailerUrl(trailer.Url));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.CommunityRating.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("rating", item.CommunityRating.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.ProductionYear.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("year", item.ProductionYear.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.ForcedSortName))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("sorttitle", item.ForcedSortName);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.OfficialRating))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("mpaa", item.OfficialRating);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.OfficialRatingDescription))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("mpaadescription", item.OfficialRatingDescription);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasAspectRatio = item as IHasAspectRatio;
|
|
|
|
|
if (hasAspectRatio != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("aspectratio", hasAspectRatio.AspectRatio);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.HomePageUrl))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("website", item.HomePageUrl);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rt = item.GetProviderId(MetadataProviders.RottenTomatoes);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(rt))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("rottentomatoesid", rt);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.RottenTomatoes.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tmdbCollection = item.GetProviderId(MetadataProviders.TmdbCollection);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(tmdbCollection))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("collectionnumber", tmdbCollection);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.TmdbCollection.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var imdb = item.GetProviderId(MetadataProviders.Imdb);
|
|
|
|
|
if (!string.IsNullOrEmpty(imdb))
|
|
|
|
|
{
|
|
|
|
|
if (item is Series)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("imdb_id", imdb);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("imdbid", imdb);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.Imdb.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Series xml saver already saves this
|
|
|
|
|
if (!(item is Series))
|
|
|
|
|
{
|
|
|
|
|
var tvdb = item.GetProviderId(MetadataProviders.Tvdb);
|
|
|
|
|
if (!string.IsNullOrEmpty(tvdb))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("tvdbid", tvdb);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.Tvdb.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tmdb = item.GetProviderId(MetadataProviders.Tmdb);
|
|
|
|
|
if (!string.IsNullOrEmpty(tmdb))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("tmdbid", tmdb);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.Tmdb.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tvcom = item.GetProviderId(MetadataProviders.Tvcom);
|
|
|
|
|
if (!string.IsNullOrEmpty(tvcom))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("tvcomid", tvcom);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.Tvcom.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 10:35:23 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(item.PreferredMetadataLanguage))
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2015-09-29 10:35:23 -07:00
|
|
|
|
writer.WriteElementString("language", item.PreferredMetadataLanguage);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(item.PreferredMetadataCountryCode))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("countrycode", item.PreferredMetadataCountryCode);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.PremiereDate.HasValue && !(item is Episode))
|
|
|
|
|
{
|
|
|
|
|
var formatString = options.ReleaseDateFormat;
|
|
|
|
|
|
|
|
|
|
if (item is MusicArtist)
|
|
|
|
|
{
|
2016-01-27 11:08:55 -07:00
|
|
|
|
writer.WriteElementString("formed", item.PremiereDate.Value.ToLocalTime().ToString(formatString));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-01-27 11:08:55 -07:00
|
|
|
|
writer.WriteElementString("premiered", item.PremiereDate.Value.ToLocalTime().ToString(formatString));
|
|
|
|
|
writer.WriteElementString("releasedate", item.PremiereDate.Value.ToLocalTime().ToString(formatString));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.EndDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (!(item is Episode))
|
|
|
|
|
{
|
|
|
|
|
var formatString = options.ReleaseDateFormat;
|
|
|
|
|
|
2016-01-27 11:08:55 -07:00
|
|
|
|
writer.WriteElementString("enddate", item.EndDate.Value.ToLocalTime().ToString(formatString));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 09:18:12 -07:00
|
|
|
|
if (item.CriticRating.HasValue)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-17 09:18:12 -07:00
|
|
|
|
writer.WriteElementString("criticrating", item.CriticRating.Value.ToString(UsCulture));
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2016-10-17 09:18:12 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(item.CriticRatingSummary))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("criticratingsummary", item.CriticRatingSummary);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasDisplayOrder = item as IHasDisplayOrder;
|
|
|
|
|
|
|
|
|
|
if (hasDisplayOrder != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("displayorder", hasDisplayOrder.DisplayOrder);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.VoteCount.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("votes", item.VoteCount.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasBudget = item as IHasBudget;
|
|
|
|
|
if (hasBudget != null)
|
|
|
|
|
{
|
|
|
|
|
if (hasBudget.Budget.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("budget", hasBudget.Budget.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasBudget.Revenue.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("revenue", hasBudget.Revenue.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasMetascore = item as IHasMetascore;
|
|
|
|
|
if (hasMetascore != null && hasMetascore.Metascore.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("metascore", hasMetascore.Metascore.Value.ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use original runtime here, actual file runtime later in MediaInfo
|
|
|
|
|
var runTimeTicks = item.RunTimeTicks;
|
|
|
|
|
|
|
|
|
|
if (runTimeTicks.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var timespan = TimeSpan.FromTicks(runTimeTicks.Value);
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("runtime", Convert.ToInt32(timespan.TotalMinutes).ToString(UsCulture));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 22:57:38 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(item.Tagline))
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-07 22:57:38 -07:00
|
|
|
|
writer.WriteElementString("tagline", item.Tagline);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-09 00:18:43 -07:00
|
|
|
|
foreach (var country in item.ProductionLocations)
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("country", country);
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
foreach (var genre in item.Genres)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("genre", genre);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var studio in item.Studios)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("studio", studio);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-02 10:43:29 -07:00
|
|
|
|
foreach (var tag in item.Tags)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-06-02 10:43:29 -07:00
|
|
|
|
if (item is MusicAlbum || item is MusicArtist)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-06-02 10:43:29 -07:00
|
|
|
|
writer.WriteElementString("style", tag);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("tag", tag);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-31 11:07:54 -07:00
|
|
|
|
foreach (var tag in item.Keywords)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-05-31 11:07:54 -07:00
|
|
|
|
writer.WriteElementString("plotkeyword", tag);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var hasAwards = item as IHasAwards;
|
|
|
|
|
if (hasAwards != null && !string.IsNullOrEmpty(hasAwards.AwardSummary))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("awardsummary", hasAwards.AwardSummary);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var externalId = item.GetProviderId(MetadataProviders.AudioDbArtist);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("audiodbartistid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.AudioDbArtist.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.AudioDbAlbum);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("audiodbalbumid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.AudioDbAlbum.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.Zap2It);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("zap2itid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.Zap2It.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbum);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("musicbrainzalbumid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.MusicBrainzAlbum.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbumArtist);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("musicbrainzalbumartistid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.MusicBrainzAlbumArtist.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.MusicBrainzArtist);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("musicbrainzartistid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.MusicBrainzArtist.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("musicbrainzreleasegroupid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.MusicBrainzReleaseGroup.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.Gamesdb);
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("gamesdbid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.Gamesdb.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
externalId = item.GetProviderId(MetadataProviders.TvRage);
|
|
|
|
|
if (!string.IsNullOrEmpty(externalId))
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("tvrageid", externalId);
|
2016-08-26 21:33:18 -07:00
|
|
|
|
writtenProviderIds.Add(MetadataProviders.TvRage.ToString());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 21:33:18 -07:00
|
|
|
|
if (item.ProviderIds != null)
|
2016-08-22 18:26:34 -07:00
|
|
|
|
{
|
2016-08-26 21:33:18 -07:00
|
|
|
|
foreach (var providerKey in item.ProviderIds.Keys)
|
|
|
|
|
{
|
|
|
|
|
var providerId = item.ProviderIds[providerKey];
|
|
|
|
|
if (!string.IsNullOrEmpty(providerId) && !writtenProviderIds.Contains(providerKey))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString(providerKey.ToLower() + "id", providerId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-22 18:26:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
if (options.SaveImagePathsInNfo)
|
|
|
|
|
{
|
2015-10-03 20:38:46 -07:00
|
|
|
|
AddImages(item, writer, libraryManager, config);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
AddUserData(item, writer, userManager, userDataRepo, options);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2015-06-20 20:35:22 -07:00
|
|
|
|
AddActors(people, writer, libraryManager, fileSystem, config);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
var folder = item as BoxSet;
|
|
|
|
|
if (folder != null)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
AddCollectionItems(folder, writer);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
public static void AddChapters(Video item, XmlWriter writer, IItemRepository repository)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
|
|
|
|
var chapters = repository.GetChapters(item.Id);
|
|
|
|
|
|
|
|
|
|
foreach (var chapter in chapters)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteStartElement("chapter");
|
|
|
|
|
writer.WriteElementString("name", chapter.Name);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
var time = TimeSpan.FromTicks(chapter.StartPositionTicks);
|
|
|
|
|
var ms = Convert.ToInt64(time.TotalMilliseconds);
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("startpositionms", ms.ToString(UsCulture));
|
|
|
|
|
writer.WriteEndElement();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
private static void AddCollectionItems(Folder item, XmlWriter writer)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
|
|
|
|
var items = item.LinkedChildren
|
2015-03-04 19:49:08 -07:00
|
|
|
|
.Where(i => i.Type == LinkedChildType.Manual)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var link in items)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteStartElement("collectionitem");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2015-03-04 19:49:08 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(link.Path))
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2015-03-04 19:49:08 -07:00
|
|
|
|
writer.WriteElementString("path", link.Path);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteEndElement();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the output trailer URL.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">The URL.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
private static string GetOutputTrailerUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
// This is what xbmc expects
|
|
|
|
|
|
2016-04-26 01:26:41 -07:00
|
|
|
|
return url.Replace("https://www.youtube.com/watch?v=",
|
2014-06-29 20:04:50 -07:00
|
|
|
|
"plugin://plugin.video.youtube/?action=play_video&videoid=",
|
|
|
|
|
StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 20:38:46 -07:00
|
|
|
|
private static void AddImages(BaseItem item, XmlWriter writer, ILibraryManager libraryManager, IServerConfigurationManager config)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteStartElement("art");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2015-10-16 10:06:31 -07:00
|
|
|
|
var image = item.GetImageInfo(ImageType.Primary, 0);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2015-10-16 10:06:31 -07:00
|
|
|
|
if (image != null && image.IsLocalFile)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2015-10-16 10:06:31 -07:00
|
|
|
|
writer.WriteElementString("poster", GetPathToSave(image.Path, libraryManager, config));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var backdrop in item.GetImages(ImageType.Backdrop))
|
|
|
|
|
{
|
2015-10-15 08:51:00 -07:00
|
|
|
|
if (backdrop.IsLocalFile)
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("fanart", GetPathToSave(backdrop.Path, libraryManager, config));
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteEndElement();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
private static void AddUserData(BaseItem item, XmlWriter writer, IUserManager userManager, IUserDataManager userDataRepo, XbmcMetadataOptions options)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
|
|
|
|
var userId = options.UserId;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(userId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-14 08:10:51 -07:00
|
|
|
|
var user = userManager.GetUserById(userId);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.IsFolder)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-30 15:05:13 -07:00
|
|
|
|
var userdata = userDataRepo.GetUserData(user, item);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-09-26 19:28:13 -07:00
|
|
|
|
writer.WriteElementString("isuserfavorite", userdata.IsFavorite.ToString().ToLower());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-09-26 19:28:13 -07:00
|
|
|
|
if (userdata.Rating.HasValue)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2014-09-26 19:28:13 -07:00
|
|
|
|
writer.WriteElementString("userrating", userdata.Rating.Value.ToString(CultureInfo.InvariantCulture).ToLower());
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 19:28:13 -07:00
|
|
|
|
if (!item.IsFolder)
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("playcount", userdata.PlayCount.ToString(UsCulture));
|
|
|
|
|
writer.WriteElementString("watched", userdata.Played.ToString().ToLower());
|
|
|
|
|
|
|
|
|
|
if (userdata.LastPlayedDate.HasValue)
|
|
|
|
|
{
|
2016-01-27 12:28:33 -07:00
|
|
|
|
writer.WriteElementString("lastplayed", userdata.LastPlayedDate.Value.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss").ToLower());
|
2014-09-26 19:28:13 -07:00
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-09-26 19:28:13 -07:00
|
|
|
|
writer.WriteStartElement("resume");
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-09-26 19:28:13 -07:00
|
|
|
|
var runTimeTicks = item.RunTimeTicks ?? 0;
|
|
|
|
|
|
|
|
|
|
writer.WriteElementString("position", TimeSpan.FromTicks(userdata.PlaybackPositionTicks).TotalSeconds.ToString(UsCulture));
|
|
|
|
|
writer.WriteElementString("total", TimeSpan.FromTicks(runTimeTicks).TotalSeconds.ToString(UsCulture));
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteEndElement();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-20 20:35:22 -07:00
|
|
|
|
private static void AddActors(List<PersonInfo> people, XmlWriter writer, ILibraryManager libraryManager, IFileSystem fileSystem, IServerConfigurationManager config)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2015-06-20 20:35:22 -07:00
|
|
|
|
var actors = people
|
2014-06-29 20:04:50 -07:00
|
|
|
|
.Where(i => !IsPersonType(i, PersonType.Director) && !IsPersonType(i, PersonType.Writer))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var person in actors)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteStartElement("actor");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(person.Name))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("name", person.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(person.Role))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("role", person.Role);
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(person.Type))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteElementString("type", person.Type);
|
|
|
|
|
}
|
2015-03-31 12:33:38 -07:00
|
|
|
|
|
2014-06-30 06:28:38 -07:00
|
|
|
|
if (person.SortOrder.HasValue)
|
|
|
|
|
{
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteElementString("sortorder", person.SortOrder.Value.ToString(UsCulture));
|
2014-06-30 06:28:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var personEntity = libraryManager.GetPerson(person.Name);
|
2015-10-16 10:06:31 -07:00
|
|
|
|
var image = personEntity.GetImageInfo(ImageType.Primary, 0);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2015-10-16 10:06:31 -07:00
|
|
|
|
if (image != null && image.IsLocalFile)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2015-10-16 10:06:31 -07:00
|
|
|
|
writer.WriteElementString("thumb", GetPathToSave(image.Path, libraryManager, config));
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
// Already logged in core
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
writer.WriteEndElement();
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 20:38:46 -07:00
|
|
|
|
private static string GetPathToSave(string path, ILibraryManager libraryManager, IServerConfigurationManager config)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-09-12 11:10:09 -07:00
|
|
|
|
return libraryManager.GetPathAfterNetworkSubstitution(path);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:46:11 -07:00
|
|
|
|
private static bool IsPersonType(PersonInfo person, string type)
|
|
|
|
|
{
|
|
|
|
|
return string.Equals(person.Type, type, StringComparison.OrdinalIgnoreCase) || string.Equals(person.Role, type, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 19:53:47 -07:00
|
|
|
|
private void AddCustomTags(string path, List<string> xmlTagsUsed, XmlWriter writer, ILogger logger, IFileSystem fileSystem)
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
var settings = XmlReaderSettingsFactory.Create(false);
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2016-10-25 19:53:47 -07:00
|
|
|
|
settings.CheckCharacters = false;
|
|
|
|
|
settings.IgnoreProcessingInstructions = true;
|
|
|
|
|
settings.IgnoreComments = true;
|
|
|
|
|
|
|
|
|
|
using (var fileStream = fileSystem.OpenRead(path))
|
2014-06-29 20:04:50 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
|
2014-07-08 17:46:11 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
// Use XmlReader for best performance
|
|
|
|
|
using (var reader = XmlReader.Create(streamReader, settings))
|
2014-07-11 19:31:08 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
try
|
2014-07-08 17:46:11 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.ErrorException("Error reading existing xml tags from {0}.", ex, path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
|
2016-10-25 19:53:47 -07:00
|
|
|
|
// Loop through each element
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
2014-07-08 17:46:11 -07:00
|
|
|
|
{
|
2016-10-25 19:53:47 -07:00
|
|
|
|
var name = reader.Name;
|
|
|
|
|
|
|
|
|
|
if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
writer.WriteNode(reader, false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
reader.Skip();
|
|
|
|
|
}
|
2014-07-08 17:46:11 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-29 20:04:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|