Made xml fetching task-based
This commit is contained in:
parent
c658ea7feb
commit
874469d476
|
@ -14,17 +14,14 @@ namespace MediaBrowser.Controller.Providers
|
||||||
return item is Folder;
|
return item is Folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
public async override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
var metadataFile = args.GetFileByName("folder.xml");
|
||||||
{
|
|
||||||
var metadataFile = args.GetFileByName("folder.xml");
|
|
||||||
|
|
||||||
if (metadataFile.HasValue)
|
if (metadataFile.HasValue)
|
||||||
{
|
{
|
||||||
new FolderXmlParser().Fetch(item as Folder, metadataFile.Value.Key);
|
await new FolderXmlParser().Fetch(item as Folder, metadataFile.Value.Key);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Xml
|
namespace MediaBrowser.Controller.Xml
|
||||||
{
|
{
|
||||||
|
@ -16,33 +17,37 @@ namespace MediaBrowser.Controller.Xml
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches metadata for an item from one xml file
|
/// Fetches metadata for an item from one xml file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Fetch(T item, string metadataFile)
|
public Task Fetch(T item, string metadataFile)
|
||||||
{
|
{
|
||||||
// Use XmlReader for best performance
|
// Wrapping this for now until I have a chance to async the whole process
|
||||||
using (XmlReader reader = XmlReader.Create(metadataFile))
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
reader.MoveToContent();
|
// Use XmlReader for best performance
|
||||||
|
using (XmlReader reader = XmlReader.Create(metadataFile))
|
||||||
// Loop through each element
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
{
|
||||||
if (reader.NodeType == XmlNodeType.Element)
|
reader.MoveToContent();
|
||||||
|
|
||||||
|
// Loop through each element
|
||||||
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
FetchDataFromXmlNode(reader, item);
|
if (reader.NodeType == XmlNodeType.Element)
|
||||||
|
{
|
||||||
|
FetchDataFromXmlNode(reader, item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If dates weren't supplied in metadata, use values from the xml file
|
// If dates weren't supplied in metadata, use values from the xml file
|
||||||
if (item.DateCreated == DateTime.MinValue)
|
if (item.DateCreated == DateTime.MinValue)
|
||||||
{
|
{
|
||||||
item.DateCreated = File.GetCreationTime(metadataFile);
|
item.DateCreated = File.GetCreationTime(metadataFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.DateModified == DateTime.MinValue)
|
if (item.DateModified == DateTime.MinValue)
|
||||||
{
|
{
|
||||||
item.DateModified = File.GetLastWriteTime(metadataFile);
|
item.DateModified = File.GetLastWriteTime(metadataFile);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -16,17 +16,14 @@ namespace MediaBrowser.Movies.Providers
|
||||||
return item is Movie;
|
return item is Movie;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
public async override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
var metadataFile = args.GetFileByName("movie.xml");
|
||||||
{
|
|
||||||
var metadataFile = args.GetFileByName("movie.xml");
|
|
||||||
|
|
||||||
if (metadataFile.HasValue)
|
if (metadataFile.HasValue)
|
||||||
{
|
{
|
||||||
new BaseItemXmlParser<Movie>().Fetch(item as Movie, metadataFile.Value.Key);
|
await new BaseItemXmlParser<Movie>().Fetch(item as Movie, metadataFile.Value.Key);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,21 +19,18 @@ namespace MediaBrowser.TV.Providers
|
||||||
return item is Episode;
|
return item is Episode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
public async override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
|
||||||
{
|
|
||||||
string metadataFolder = Path.Combine(args.Parent.Path, "metadata");
|
|
||||||
|
|
||||||
string episodeFileName = Path.GetFileName(item.Path);
|
string episodeFileName = Path.GetFileName(item.Path);
|
||||||
|
|
||||||
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(episodeFileName, ".xml"));
|
string metadataFile = Path.Combine(metadataFolder, Path.ChangeExtension(episodeFileName, ".xml"));
|
||||||
|
|
||||||
FetchMetadata(item as Episode, args.Parent as Season, metadataFile);
|
await FetchMetadata(item as Episode, args.Parent as Season, metadataFile);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FetchMetadata(Episode item, Season season, string metadataFile)
|
private async Task FetchMetadata(Episode item, Season season, string metadataFile)
|
||||||
{
|
{
|
||||||
if (season == null)
|
if (season == null)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +49,7 @@ namespace MediaBrowser.TV.Providers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new EpisodeXmlParser().Fetch(item, metadataFile);
|
await new EpisodeXmlParser().Fetch(item, metadataFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller.Events;
|
using MediaBrowser.Controller.Events;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Controller.Xml;
|
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.TV.Entities;
|
using MediaBrowser.TV.Entities;
|
||||||
|
using MediaBrowser.TV.Metadata;
|
||||||
|
|
||||||
namespace MediaBrowser.TV.Providers
|
namespace MediaBrowser.TV.Providers
|
||||||
{
|
{
|
||||||
|
@ -16,17 +16,14 @@ namespace MediaBrowser.TV.Providers
|
||||||
return item is Series;
|
return item is Series;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
public async override Task Fetch(BaseItem item, ItemResolveEventArgs args)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
var metadataFile = args.GetFileByName("series.xml");
|
||||||
{
|
|
||||||
var metadataFile = args.GetFileByName("series.xml");
|
|
||||||
|
|
||||||
if (metadataFile.HasValue)
|
if (metadataFile.HasValue)
|
||||||
{
|
{
|
||||||
new BaseItemXmlParser<Series>().Fetch(item as Series, metadataFile.Value.Key);
|
await new SeriesXmlParser().Fetch(item as Series, metadataFile.Value.Key);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user