update FolderXmlSaver

This commit is contained in:
Luke Pulverenti 2016-10-28 14:45:56 -04:00
parent b59614d439
commit 41dfa26501
2 changed files with 108 additions and 132 deletions

View File

@ -23,97 +23,116 @@ using MediaBrowser.Model.Xml;
namespace MediaBrowser.LocalMetadata.Savers
{
public abstract class BaseNfoSaver : IMetadataFileSaver
public abstract class BaseXmlSaver : IMetadataFileSaver
{
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
private static readonly Dictionary<string, string> CommonTags = new[] {
"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",
"country",
"audiodbalbumid",
"audiodbartistid",
"awardsummary",
"enddate",
"lockedfields",
"metascore",
"zap2itid",
"tvrageid",
"gamesdbid",
"Added",
"AspectRatio",
"AudioDbAlbumId",
"AudioDbArtistId",
"AwardSummary",
"BirthDate",
"Budget",
"musicbrainzartistid",
"musicbrainzalbumartistid",
"musicbrainzalbumid",
"musicbrainzreleasegroupid",
"tvdbid",
"collectionitem",
// Deprecated. No longer saving in this field.
"certification",
"isuserfavorite",
"userrating",
"Chapters",
"ContentRating",
"Countries",
"CustomRating",
"CriticRating",
"CriticRatingSummary",
"DeathDate",
"DisplayOrder",
"EndDate",
"Genres",
"Genre",
"GamesDbId",
"countrycode"
// Deprecated. No longer saving in this field.
"IMDB_ID",
"IMDB",
// Deprecated. No longer saving in this field.
"IMDbId",
"Language",
"LocalTitle",
"OriginalTitle",
"LockData",
"LockedFields",
"Format3D",
"Metascore",
// Deprecated. No longer saving in this field.
"MPAARating",
"MPAADescription",
"MusicBrainzArtistId",
"MusicBrainzAlbumArtistId",
"MusicBrainzAlbumId",
"MusicBrainzReleaseGroupId",
// Deprecated. No longer saving in this field.
"MusicbrainzId",
"Overview",
"ShortOverview",
"Persons",
"PlotKeywords",
"PremiereDate",
"ProductionYear",
"Rating",
"Revenue",
"RottenTomatoesId",
"RunningTime",
// Deprecated. No longer saving in this field.
"Runtime",
"SortTitle",
"Studios",
"Tags",
// Deprecated. No longer saving in this field.
"TagLine",
"Taglines",
"TMDbCollectionId",
"TMDbId",
// Deprecated. No longer saving in this field.
"Trailer",
"Trailers",
"TVcomId",
"TvDbId",
"Type",
"TVRageId",
"VoteCount",
"Website",
"Zap2ItId",
"CollectionItems",
"PlaylistItems",
"Shares"
}.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
protected BaseNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
public BaseXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
{
FileSystem = fileSystem;
ConfigurationManager = configurationManager;
LibraryManager = libraryManager;
UserManager = userManager;
UserDataManager = userDataManager;
Logger = logger;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
UserDataManager = userDataManager;
UserManager = userManager;
LibraryManager = libraryManager;
ConfigurationManager = configurationManager;
FileSystem = fileSystem;
}
protected IFileSystem FileSystem { get; private set; }
@ -136,15 +155,7 @@ namespace MediaBrowser.LocalMetadata.Savers
{
get
{
return SaverName;
}
}
public static string SaverName
{
get
{
return "Emby Xml";
return XmlProviderUtils.Name;
}
}

View File

@ -9,40 +9,28 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Xml;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.LocalMetadata.Savers
{
public class FolderXmlSaver : IMetadataFileSaver
public class FolderXmlSaver : BaseXmlSaver
{
public string Name
protected override string GetLocalSavePath(IHasMetadata item)
{
get
{
return XmlProviderUtils.Name;
}
return Path.Combine(item.Path, "folder.xml");
}
private readonly IServerConfigurationManager _config;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
public FolderXmlSaver(IServerConfigurationManager config, ILibraryManager libraryManager, IFileSystem fileSystem)
protected override string GetRootElementName(IHasMetadata item)
{
_config = config;
_libraryManager = libraryManager;
_fileSystem = fileSystem;
return "Item";
}
/// <summary>
/// Determines whether [is enabled for] [the specified item].
/// </summary>
/// <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 bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
public override bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
{
if (!item.SupportsLocalMetadata)
{
@ -63,35 +51,12 @@ namespace MediaBrowser.LocalMetadata.Savers
return false;
}
/// <summary>
/// Saves the specified item.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public void Save(IHasMetadata item, CancellationToken cancellationToken)
protected override void WriteCustomElements(IHasMetadata item, XmlWriter writer)
{
var builder = new StringBuilder();
builder.Append("<Item>");
XmlSaverHelpers.AddCommonNodes((Folder)item, _libraryManager, builder);
builder.Append("</Item>");
var xmlFilePath = GetSavePath(item);
XmlSaverHelpers.Save(builder, xmlFilePath, new List<string>(), _config, _fileSystem);
}
/// <summary>
/// Gets the save path.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>System.String.</returns>
public string GetSavePath(IHasMetadata item)
public FolderXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
return Path.Combine(item.Path, "folder.xml");
}
}
}