jellyfin/MediaBrowser.Providers/Music/AlbumXmlProvider.cs
2014-02-03 00:35:43 -05:00

60 lines
1.6 KiB
C#

using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.Music
{
class AlbumXmlProvider : BaseXmlProvider, ILocalMetadataProvider<MusicAlbum>
{
private readonly ILogger _logger;
public AlbumXmlProvider(IFileSystem fileSystem, ILogger logger)
: base(fileSystem)
{
_logger = logger;
}
public async Task<MetadataResult<MusicAlbum>> GetMetadata(string path, CancellationToken cancellationToken)
{
path = GetXmlFile(path).FullName;
var result = new MetadataResult<MusicAlbum>();
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
var item = new MusicAlbum();
new BaseItemXmlParser<MusicAlbum>(_logger).Fetch(item, path, cancellationToken);
result.HasMetadata = true;
result.Item = item;
}
catch (FileNotFoundException)
{
result.HasMetadata = false;
}
finally
{
XmlParsingResourcePool.Release();
}
return result;
}
public string Name
{
get { return "Media Browser Xml"; }
}
protected override FileInfo GetXmlFile(string path)
{
return new FileInfo(Path.Combine(path, "album.xml"));
}
}
}