make nfo project portable

This commit is contained in:
Luke Pulverenti 2016-10-25 22:53:47 -04:00
parent b30c58f825
commit 21be035df0
29 changed files with 286 additions and 202 deletions

View File

View File

@ -452,6 +452,7 @@
<Compile Include="Users\UserAction.cs" />
<Compile Include="Users\UserActionType.cs" />
<Compile Include="Users\UserPolicy.cs" />
<Compile Include="Xml\IXmlReaderSettingsFactory.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -0,0 +1,9 @@
using System.Xml;
namespace MediaBrowser.Model.Xml
{
public interface IXmlReaderSettingsFactory
{
XmlReaderSettings Create(bool enableValidation);
}
}

View File

@ -363,6 +363,7 @@
<Compile Include="TV\TVSeriesManager.cs" />
<Compile Include="Udp\UdpMessageReceivedEventArgs.cs" />
<Compile Include="Udp\UdpServer.cs" />
<Compile Include="Xml\XmlReaderSettingsFactory.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Common.Implementations\MediaBrowser.Common.Implementations.csproj">

View File

@ -0,0 +1,20 @@
using System.Xml;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.Server.Implementations.Xml
{
public class XmlReaderSettingsFactory : IXmlReaderSettingsFactory
{
public XmlReaderSettings Create(bool enableValidation)
{
var settings = new XmlReaderSettings();
if (!enableValidation)
{
settings.ValidationType = ValidationType.None;
}
return settings;
}
}
}

View File

@ -113,6 +113,8 @@ using MediaBrowser.Model.Net;
using MediaBrowser.Model.News;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Social;
using MediaBrowser.Model.Xml;
using MediaBrowser.Server.Implementations.Xml;
namespace MediaBrowser.Server.Startup.Common
{
@ -631,6 +633,8 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
RegisterSingleInstance<IXmlReaderSettingsFactory>(new XmlReaderSettingsFactory());
UserDataManager = new UserDataManager(LogManager, ServerConfigurationManager);
RegisterSingleInstance(UserDataManager);

View File

@ -9,10 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MediaBrowser.XbmcMetadata</RootNamespace>
<AssemblyName>MediaBrowser.XbmcMetadata</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<TargetFrameworkProfile />
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -35,13 +36,6 @@
<Reference Include="Patterns.Logging">
<HintPath>..\packages\Patterns.Logging.1.0.0.2\lib\portable-net45+sl4+wp71+win8+wpa81\Patterns.Logging.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\SharedVersion.cs">
@ -88,7 +82,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -15,6 +15,8 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Parsers
{
@ -25,7 +27,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// The logger
/// </summary>
protected ILogger Logger { get; private set; }
protected IFileSystem FileSystem { get; private set; }
protected IProviderManager ProviderManager { get; private set; }
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IConfigurationManager _config;
@ -34,13 +38,13 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// <summary>
/// Initializes a new instance of the <see cref="BaseNfoParser{T}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="config">The configuration.</param>
public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
{
Logger = logger;
_config = config;
ProviderManager = providerManager;
FileSystem = fileSystem;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
/// <summary>
@ -63,15 +67,13 @@ namespace MediaBrowser.XbmcMetadata.Parsers
throw new ArgumentNullException();
}
var settings = new XmlReaderSettings
{
CheckCharacters = false,
IgnoreProcessingInstructions = true,
IgnoreComments = true,
ValidationType = ValidationType.None
};
var settings = XmlReaderSettingsFactory.Create(false);
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
settings.CheckCharacters = false;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreComments = true;
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
@ -108,85 +110,15 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
if (!SupportsUrlAfterClosingXmlTag)
{
using (var streamReader = BaseNfoSaver.GetStreamReader(metadataFile))
using (var fileStream = FileSystem.OpenRead(metadataFile))
{
// Use XmlReader for best performance
using (var reader = XmlReader.Create(streamReader, settings))
{
item.ResetPeople();
reader.MoveToContent();
// Loop through each element
while (reader.Read())
{
cancellationToken.ThrowIfCancellationRequested();
if (reader.NodeType == XmlNodeType.Element)
{
FetchDataFromXmlNode(reader, item);
}
}
}
}
return;
}
using (var streamReader = BaseNfoSaver.GetStreamReader(metadataFile))
{
item.ResetPeople();
// Need to handle a url after the xml data
// http://kodi.wiki/view/NFO_files/movies
var xml = streamReader.ReadToEnd();
// Find last closing Tag
// Need to do this in two steps to account for random > characters after the closing xml
var index = xml.LastIndexOf(@"</", StringComparison.Ordinal);
// If closing tag exists, move to end of Tag
if (index != -1)
{
index = xml.IndexOf('>', index);
}
if (index != -1)
{
var endingXml = xml.Substring(index);
ParseProviderLinks(item.Item, endingXml);
// If the file is just an imdb url, don't go any further
if (index == 0)
{
return;
}
xml = xml.Substring(0, index + 1);
}
else
{
// If the file is just an Imdb url, handle that
ParseProviderLinks(item.Item, xml);
return;
}
using (var ms = new MemoryStream())
{
var bytes = Encoding.UTF8.GetBytes(xml);
ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
// These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
try
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
// Use XmlReader for best performance
using (var reader = XmlReader.Create(ms, settings))
using (var reader = XmlReader.Create(streamReader, settings))
{
item.ResetPeople();
reader.MoveToContent();
// Loop through each element
@ -201,9 +133,85 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
}
catch (XmlException)
{
}
return;
}
using (var fileStream = FileSystem.OpenRead(metadataFile))
{
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
item.ResetPeople();
// Need to handle a url after the xml data
// http://kodi.wiki/view/NFO_files/movies
var xml = streamReader.ReadToEnd();
// Find last closing Tag
// Need to do this in two steps to account for random > characters after the closing xml
var index = xml.LastIndexOf(@"</", StringComparison.Ordinal);
// If closing tag exists, move to end of Tag
if (index != -1)
{
index = xml.IndexOf('>', index);
}
if (index != -1)
{
var endingXml = xml.Substring(index);
ParseProviderLinks(item.Item, endingXml);
// If the file is just an imdb url, don't go any further
if (index == 0)
{
return;
}
xml = xml.Substring(0, index + 1);
}
else
{
// If the file is just an Imdb url, handle that
ParseProviderLinks(item.Item, xml);
return;
}
using (var ms = new MemoryStream())
{
var bytes = Encoding.UTF8.GetBytes(xml);
ms.Write(bytes, 0, bytes.Length);
ms.Position = 0;
// These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
try
{
// Use XmlReader for best performance
using (var reader = XmlReader.Create(ms, settings))
{
reader.MoveToContent();
// Loop through each element
while (reader.Read())
{
cancellationToken.ThrowIfCancellationRequested();
if (reader.NodeType == XmlNodeType.Element)
{
FetchDataFromXmlNode(reader, item);
}
}
}
}
catch (XmlException)
{
}
}
}
}

View File

@ -7,15 +7,13 @@ using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Xml;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Parsers
{
public class EpisodeNfoParser : BaseNfoParser<Episode>
{
public EpisodeNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(logger, config, providerManager)
{
}
public void Fetch(MetadataResult<Episode> item,
List<LocalImageInfo> images,
string metadataFile,
@ -230,5 +228,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
break;
}
}
public EpisodeNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -5,16 +5,13 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System.Xml;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Parsers
{
class MovieNfoParser : BaseNfoParser<Video>
{
public MovieNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(logger, config, providerManager)
{
}
protected override bool SupportsUrlAfterClosingXmlTag
{
get
@ -103,5 +100,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
break;
}
}
public MovieNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -4,15 +4,13 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
using System.Globalization;
using System.Xml;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Parsers
{
public class SeasonNfoParser : BaseNfoParser<Season>
{
public SeasonNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(logger, config, providerManager)
{
}
/// <summary>
/// Fetches the data from XML node.
/// </summary>
@ -45,5 +43,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
break;
}
}
public SeasonNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -6,15 +6,13 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Xml;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Parsers
{
public class SeriesNfoParser : BaseNfoParser<Series>
{
public SeriesNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(logger, config, providerManager)
{
}
/// <summary>
/// Fetches the data from XML node.
/// </summary>
@ -108,5 +106,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
break;
}
}
public SeriesNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -8,6 +8,7 @@ using System.Threading;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Providers
{
@ -16,6 +17,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
public AlbumNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
@ -27,7 +29,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
protected override void Fetch(MetadataResult<MusicAlbum> result, string path, CancellationToken cancellationToken)
{
new BaseNfoParser<MusicAlbum>(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
new BaseNfoParser<MusicAlbum>(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -8,6 +8,7 @@ using System.Threading;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Providers
{
@ -16,18 +17,20 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
public ArtistNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
public ArtistNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<MusicArtist> result, string path, CancellationToken cancellationToken)
{
new BaseNfoParser<MusicArtist>(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
new BaseNfoParser<MusicArtist>(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -41,7 +41,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
result.HasMetadata = false;
}
catch (DirectoryNotFoundException)
catch (IOException)
{
result.HasMetadata = false;
}

View File

@ -9,6 +9,7 @@ using System.Threading;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Providers
{
@ -18,13 +19,15 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken)
@ -33,7 +36,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
Item = result.Item
};
new MovieNfoParser(_logger, _config, _providerManager).Fetch(tmpItem, path, cancellationToken);
new MovieNfoParser(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(tmpItem, path, cancellationToken);
result.Item = (T)tmpItem.Item;
result.People = tmpItem.People;

View File

@ -9,6 +9,7 @@ using System.Threading;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Providers
{
@ -17,20 +18,22 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
public EpisodeNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
public EpisodeNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<Episode> result, string path, CancellationToken cancellationToken)
{
var images = new List<LocalImageInfo>();
new EpisodeNfoParser(_logger, _config, _providerManager).Fetch(result, images, path, cancellationToken);
new EpisodeNfoParser(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, images, path, cancellationToken);
result.Images = images;
}

View File

@ -6,26 +6,27 @@ using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Providers
{
public class MovieNfoProvider : BaseVideoNfoProvider<Movie>
{
public MovieNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(fileSystem, logger, config, providerManager)
public MovieNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, logger, config, providerManager, xmlReaderSettingsFactory)
{
}
}
public class MusicVideoNfoProvider : BaseVideoNfoProvider<MusicVideo>
{
public MusicVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(fileSystem, logger, config, providerManager)
public MusicVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, logger, config, providerManager, xmlReaderSettingsFactory)
{
}
}
public class VideoNfoProvider : BaseVideoNfoProvider<Video>
{
public VideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager) : base(fileSystem, logger, config, providerManager)
public VideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, logger, config, providerManager, xmlReaderSettingsFactory)
{
}
}

View File

@ -8,6 +8,7 @@ using System.Threading;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Providers
{
@ -16,18 +17,20 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
public SeasonNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
public SeasonNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<Season> result, string path, CancellationToken cancellationToken)
{
new SeasonNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
new SeasonNfoParser(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -8,6 +8,7 @@ using System.Threading;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Providers
{
@ -16,18 +17,22 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
private readonly IFileSystem _fileSystem;
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
public SeriesNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
public SeriesNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem1, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
_fileSystem = fileSystem1;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<Series> result, string path, CancellationToken cancellationToken)
{
new SeriesNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
new SeriesNfoParser(_logger, _config, _providerManager, _fileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -12,15 +12,12 @@ using System.Xml;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
public class AlbumNfoSaver : BaseNfoSaver
{
public AlbumNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
protected override string GetLocalSavePath(IHasMetadata item)
{
return Path.Combine(item.Path, "album.nfo");
@ -99,5 +96,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
public AlbumNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -12,15 +12,12 @@ using System.Xml;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
public class ArtistNfoSaver : BaseNfoSaver
{
public ArtistNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
protected override string GetLocalSavePath(IHasMetadata item)
{
return Path.Combine(item.Path, "artist.nfo");
@ -92,5 +89,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
public ArtistNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -22,6 +22,7 @@ using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
@ -107,9 +108,10 @@ namespace MediaBrowser.XbmcMetadata.Savers
}.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
protected BaseNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
protected BaseNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
{
Logger = logger;
XmlReaderSettingsFactory = xmlReaderSettingsFactory;
UserDataManager = userDataManager;
UserManager = userManager;
LibraryManager = libraryManager;
@ -123,6 +125,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
protected IUserManager UserManager { get; private set; }
protected IUserDataManager UserDataManager { get; private set; }
protected ILogger Logger { get; private set; }
protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
protected ItemUpdateType MinimumUpdateType
{
@ -205,16 +208,16 @@ namespace MediaBrowser.XbmcMetadata.Savers
{
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
var file = new FileInfo(path);
var file = FileSystem.GetFileInfo(path);
var wasHidden = false;
// This will fail if the file is hidden
if (file.Exists)
{
if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
if (file.IsHidden)
{
file.Attributes &= ~FileAttributes.Hidden;
FileSystem.SetHidden(path, false);
wasHidden = true;
}
@ -227,10 +230,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
if (wasHidden || ConfigurationManager.Configuration.SaveMetadataHidden)
{
file.Refresh();
// Add back the attribute
file.Attributes |= FileAttributes.Hidden;
FileSystem.SetHidden(path, true);
}
}
@ -271,13 +271,13 @@ namespace MediaBrowser.XbmcMetadata.Savers
try
{
AddCustomTags(xmlPath, tagsUsed, writer, Logger);
AddCustomTags(xmlPath, tagsUsed, writer, Logger, FileSystem);
}
catch (FileNotFoundException)
{
}
catch (DirectoryNotFoundException)
catch (IOException)
{
}
@ -430,7 +430,7 @@ namespace MediaBrowser.XbmcMetadata.Savers
/// <returns>Task.</returns>
public static void AddCommonNodes(BaseItem item, XmlWriter writer, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataRepo, IFileSystem fileSystem, IServerConfigurationManager config)
{
var writtenProviderIds = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
var writtenProviderIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var overview = (item.Overview ?? string.Empty)
.StripHtml()
@ -1036,56 +1036,51 @@ namespace MediaBrowser.XbmcMetadata.Savers
return string.Equals(person.Type, type, StringComparison.OrdinalIgnoreCase) || string.Equals(person.Role, type, StringComparison.OrdinalIgnoreCase);
}
private static void AddCustomTags(string path, List<string> xmlTagsUsed, XmlWriter writer, ILogger logger)
private void AddCustomTags(string path, List<string> xmlTagsUsed, XmlWriter writer, ILogger logger, IFileSystem fileSystem)
{
var settings = new XmlReaderSettings
{
CheckCharacters = false,
IgnoreProcessingInstructions = true,
IgnoreComments = true,
ValidationType = ValidationType.None
};
var settings = XmlReaderSettingsFactory.Create(false);
using (var streamReader = GetStreamReader(path))
settings.CheckCharacters = false;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreComments = true;
using (var fileStream = fileSystem.OpenRead(path))
{
// Use XmlReader for best performance
using (var reader = XmlReader.Create(streamReader, settings))
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
try
// Use XmlReader for best performance
using (var reader = XmlReader.Create(streamReader, settings))
{
reader.MoveToContent();
}
catch (Exception ex)
{
logger.ErrorException("Error reading existing xml tags from {0}.", ex, path);
return;
}
// Loop through each element
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
try
{
var name = reader.Name;
reader.MoveToContent();
}
catch (Exception ex)
{
logger.ErrorException("Error reading existing xml tags from {0}.", ex, path);
return;
}
if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase))
// Loop through each element
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
writer.WriteNode(reader, false);
}
else
{
reader.Skip();
var name = reader.Name;
if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase))
{
writer.WriteNode(reader, false);
}
else
{
reader.Skip();
}
}
}
}
}
}
}
public static StreamReader GetStreamReader(string path)
{
return new StreamReader(path, Encoding.UTF8);
}
}
}

View File

@ -11,15 +11,12 @@ using System.Xml;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
public class EpisodeNfoSaver : BaseNfoSaver
{
public EpisodeNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
protected override string GetLocalSavePath(IHasMetadata item)
{
return Path.ChangeExtension(item.Path, ".nfo");
@ -131,5 +128,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
public EpisodeNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -13,15 +13,12 @@ using System.Xml;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
public class MovieNfoSaver : BaseNfoSaver
{
public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
protected override string GetLocalSavePath(IHasMetadata item)
{
return GetMovieSavePaths(new ItemInfo(item), FileSystem).FirstOrDefault();
@ -128,5 +125,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -10,15 +10,12 @@ using System.Xml;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
public class SeasonNfoSaver : BaseNfoSaver
{
public SeasonNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
protected override string GetLocalSavePath(IHasMetadata item)
{
return Path.Combine(item.Path, "season.nfo");
@ -62,5 +59,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
public SeasonNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -11,15 +11,12 @@ using System.Xml;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Xml;
namespace MediaBrowser.XbmcMetadata.Savers
{
public class SeriesNfoSaver : BaseNfoSaver
{
public SeriesNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
protected override string GetLocalSavePath(IHasMetadata item)
{
return Path.Combine(item.Path, "tvshow.nfo");
@ -111,5 +108,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
public SeriesNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
{
}
}
}

View File

@ -0,0 +1,7 @@
{
"supports": {},
"dependencies": {},
"frameworks": {
".NETPortable,Version=v4.5,Profile=Profile7": {}
}
}

View File

@ -0,0 +1,12 @@
{
"locked": false,
"version": 1,
"targets": {
".NETPortable,Version=v4.5,Profile=Profile7": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"": [],
".NETPortable,Version=v4.5,Profile=Profile7": []
}
}