2016-03-27 17:11:27 -04:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2014-06-29 23:04:50 -04:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2014-07-07 21:41:03 -04:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-05-26 02:48:54 -04:00
|
|
|
|
|
2016-10-25 15:02:04 -04:00
|
|
|
|
using MediaBrowser.Controller.IO;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
2014-01-28 13:37:01 -05:00
|
|
|
|
|
2014-06-29 23:04:50 -04:00
|
|
|
|
namespace MediaBrowser.LocalMetadata
|
2014-01-28 13:37:01 -05:00
|
|
|
|
{
|
2016-04-27 21:59:09 -04:00
|
|
|
|
public abstract class BaseXmlProvider<T> : ILocalMetadataProvider<T>, IHasItemChangeMonitor, IHasOrder
|
2018-09-12 13:26:21 -04:00
|
|
|
|
where T : BaseItem, new()
|
2014-01-28 13:37:01 -05:00
|
|
|
|
{
|
|
|
|
|
protected IFileSystem FileSystem;
|
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
public Task<MetadataResult<T>> GetMetadata(ItemInfo info,
|
2014-10-25 14:32:58 -04:00
|
|
|
|
IDirectoryService directoryService,
|
|
|
|
|
CancellationToken cancellationToken)
|
2014-02-05 23:39:16 -05:00
|
|
|
|
{
|
2015-08-02 13:31:08 -04:00
|
|
|
|
var result = new MetadataResult<T>();
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
2014-10-25 14:32:58 -04:00
|
|
|
|
var file = GetXmlFile(info, directoryService);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
|
return Task.FromResult(result);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var path = file.FullName;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result.Item = new T();
|
|
|
|
|
|
2014-02-08 23:52:52 -05:00
|
|
|
|
Fetch(result, path, cancellationToken);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
result.HasMetadata = true;
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
result.HasMetadata = false;
|
|
|
|
|
}
|
2016-10-30 03:02:23 -04:00
|
|
|
|
catch (IOException)
|
2014-02-10 13:39:41 -05:00
|
|
|
|
{
|
|
|
|
|
result.HasMetadata = false;
|
|
|
|
|
}
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
return Task.FromResult(result);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 13:31:08 -04:00
|
|
|
|
protected abstract void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
2014-01-28 13:37:01 -05:00
|
|
|
|
protected BaseXmlProvider(IFileSystem fileSystem)
|
|
|
|
|
{
|
|
|
|
|
FileSystem = fileSystem;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 23:38:46 -04:00
|
|
|
|
protected abstract FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService);
|
2014-02-10 15:11:46 -05:00
|
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
|
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
2014-01-28 13:37:01 -05:00
|
|
|
|
{
|
2015-05-15 11:46:20 -04:00
|
|
|
|
var file = GetXmlFile(new ItemInfo(item), directoryService);
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-28 13:37:01 -05:00
|
|
|
|
|
2016-04-27 21:59:09 -04:00
|
|
|
|
return file.Exists && FileSystem.GetLastWriteTimeUtc(file) > item.DateLastSaved;
|
2014-01-28 13:37:01 -05:00
|
|
|
|
}
|
2014-01-29 11:16:24 -05:00
|
|
|
|
|
2014-02-05 23:39:16 -05:00
|
|
|
|
public string Name
|
2014-01-29 11:16:24 -05:00
|
|
|
|
{
|
2014-02-05 23:39:16 -05:00
|
|
|
|
get
|
|
|
|
|
{
|
2014-11-10 22:41:55 -05:00
|
|
|
|
return XmlProviderUtils.Name;
|
2014-02-05 23:39:16 -05:00
|
|
|
|
}
|
2014-01-29 11:16:24 -05:00
|
|
|
|
}
|
2014-11-10 22:41:55 -05:00
|
|
|
|
|
2016-08-05 17:15:48 -04:00
|
|
|
|
public virtual int Order
|
2015-01-10 00:53:35 -05:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
// After Nfo
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-28 13:37:01 -05:00
|
|
|
|
}
|
2014-02-05 23:39:16 -05:00
|
|
|
|
|
|
|
|
|
static class XmlProviderUtils
|
|
|
|
|
{
|
2014-11-10 22:41:55 -05:00
|
|
|
|
public static string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2015-04-01 00:23:34 -04:00
|
|
|
|
return "Emby Xml";
|
2014-11-10 22:41:55 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-05 23:39:16 -05:00
|
|
|
|
}
|
2014-01-28 13:37:01 -05:00
|
|
|
|
}
|