update metadata parsing

This commit is contained in:
Luke Pulverenti 2015-08-02 13:31:08 -04:00
parent edecae6ed5
commit 6d13cec38e
31 changed files with 101 additions and 110 deletions

View File

@ -312,7 +312,6 @@
<Compile Include="Providers\ItemInfo.cs" />
<Compile Include="Providers\LiveTvProgramLookupInfo.cs" />
<Compile Include="Providers\LocalImageInfo.cs" />
<Compile Include="Providers\LocalMetadataResult.cs" />
<Compile Include="Providers\MetadataRefreshMode.cs" />
<Compile Include="Providers\MetadataResult.cs" />
<Compile Include="Providers\MovieInfo.cs" />

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.Controller.Providers
/// <param name="directoryService">The directory service.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{MetadataResult{`0}}.</returns>
Task<LocalMetadataResult<TItemType>> GetMetadata(ItemInfo info,
Task<MetadataResult<TItemType>> GetMetadata(ItemInfo info,
IDirectoryService directoryService,
CancellationToken cancellationToken);
}

View File

@ -1,18 +0,0 @@
using MediaBrowser.Controller.Entities;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Providers
{
public class LocalMetadataResult<T> : MetadataResult<T>
where T : IHasMetadata
{
public List<LocalImageInfo> Images { get; set; }
public List<UserItemData> UserDataLIst { get; set; }
public LocalMetadataResult()
{
Images = new List<LocalImageInfo>();
UserDataLIst = new List<UserItemData>();
}
}
}

View File

@ -1,10 +1,20 @@
using MediaBrowser.Controller.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Controller.Providers
{
public class MetadataResult<T>
{
public List<LocalImageInfo> Images { get; set; }
public List<UserItemData> UserDataList { get; set; }
public MetadataResult()
{
Images = new List<LocalImageInfo>();
}
public List<PersonInfo> People { get; set; }
public bool HasMetadata { get; set; }
@ -31,5 +41,27 @@ namespace MediaBrowser.Controller.Providers
}
People.Clear();
}
public UserItemData GetOrAddUserData(string userId)
{
if (UserDataList == null)
{
UserDataList = new List<UserItemData>();
}
var userData = UserDataList.FirstOrDefault(i => string.Equals(userId, i.UserId.ToString("N"), StringComparison.OrdinalIgnoreCase));
if (userData == null)
{
userData = new UserItemData()
{
UserId = new Guid(userId)
};
UserDataList.Add(userData);
}
return userData;
}
}
}

View File

@ -13,11 +13,11 @@ namespace MediaBrowser.LocalMetadata
{
protected IFileSystem FileSystem;
public async Task<LocalMetadataResult<T>> GetMetadata(ItemInfo info,
public async Task<MetadataResult<T>> GetMetadata(ItemInfo info,
IDirectoryService directoryService,
CancellationToken cancellationToken)
{
var result = new LocalMetadataResult<T>();
var result = new MetadataResult<T>();
var file = GetXmlFile(info, directoryService);
@ -47,7 +47,7 @@ namespace MediaBrowser.LocalMetadata
return result;
}
protected abstract void Fetch(LocalMetadataResult<T> result, string path, CancellationToken cancellationToken);
protected abstract void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken);
protected BaseXmlProvider(IFileSystem fileSystem)
{

View File

@ -1,10 +1,10 @@
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
namespace MediaBrowser.LocalMetadata.Parsers
{

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<BoxSet> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<BoxSet> result, string path, CancellationToken cancellationToken)
{
new BoxSetXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -20,7 +20,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Episode> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Episode> result, string path, CancellationToken cancellationToken)
{
var images = new List<LocalImageInfo>();
var chapters = new List<ChapterInfo>();

View File

@ -20,7 +20,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Folder> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Folder> result, string path, CancellationToken cancellationToken)
{
new BaseItemXmlParser<Folder>(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<GameSystem> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<GameSystem> result, string path, CancellationToken cancellationToken)
{
new GameSystemXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Game> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Game> result, string path, CancellationToken cancellationToken)
{
new GameXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Movie> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Movie> result, string path, CancellationToken cancellationToken)
{
new MovieXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<MusicVideo> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<MusicVideo> result, string path, CancellationToken cancellationToken)
{
new MusicVideoXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Person> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Person> result, string path, CancellationToken cancellationToken)
{
new BaseItemXmlParser<Person>(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Playlist> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Playlist> result, string path, CancellationToken cancellationToken)
{
new PlaylistXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Season> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Season> result, string path, CancellationToken cancellationToken)
{
new SeasonXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Series> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Series> result, string path, CancellationToken cancellationToken)
{
new SeriesXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.LocalMetadata.Providers
_logger = logger;
}
protected override void Fetch(LocalMetadataResult<Video> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Video> result, string path, CancellationToken cancellationToken)
{
new VideoXmlParser(_logger).Fetch(result, path, cancellationToken);
}

View File

@ -408,7 +408,10 @@ namespace MediaBrowser.Providers.Manager
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.ImageUpdate;
}
userDataList = localItem.UserDataLIst;
if (localItem.UserDataList != null)
{
userDataList.AddRange(localItem.UserDataList);
}
MergeData(localItem, temp, new List<MetadataFields>(), !options.ReplaceAllMetadata, true);
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataImport;

View File

@ -47,7 +47,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// </exception>
public void Fetch(LocalMetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
public void Fetch(MetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
{
if (item == null)
{
@ -82,7 +82,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// <param name="metadataFile">The metadata file.</param>
/// <param name="settings">The settings.</param>
/// <param name="cancellationToken">The cancellation token.</param>
private void Fetch(LocalMetadataResult<T> item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken)
private void Fetch(MetadataResult<T> item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken)
{
item.ResetPeople();
@ -184,7 +184,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
// http://www.themoviedb.org/movie/36557
}
protected virtual void FetchDataFromXmlNode(XmlReader reader, LocalMetadataResult<T> itemResult)
protected virtual void FetchDataFromXmlNode(XmlReader reader, MetadataResult<T> itemResult)
{
var item = itemResult.Item;
@ -927,19 +927,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
{
bool parsedValue;
if (bool.TryParse(val, out parsedValue))
{
if (!string.IsNullOrWhiteSpace(userDataUserId))
{
var userData = GetOrAdd(itemResult.UserDataLIst, userDataUserId);
var userData = GetOrAdd(itemResult, userDataUserId);
userData.Played = parsedValue;
}
}
}
break;
}
@ -947,14 +944,12 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
{
int parsedValue;
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out parsedValue))
{
if (!string.IsNullOrWhiteSpace(userDataUserId))
{
var userData = GetOrAdd(itemResult.UserDataLIst, userDataUserId);
var userData = GetOrAdd(itemResult, userDataUserId);
userData.PlayCount = parsedValue;
@ -964,7 +959,6 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
}
}
break;
}
@ -972,19 +966,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
{
DateTime parsedValue;
if (DateTime.TryParseExact(val, "yyyy-MM-dd HH:mm:ss", _usCulture, DateTimeStyles.None, out parsedValue))
{
if (!string.IsNullOrWhiteSpace(userDataUserId))
{
var userData = GetOrAdd(itemResult.UserDataLIst, userDataUserId);
var userData = GetOrAdd(itemResult, userDataUserId);
userData.LastPlayedDate = parsedValue;
}
}
}
break;
}
@ -994,7 +985,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
if (!string.IsNullOrWhiteSpace(userDataUserId))
{
var userData = GetOrAdd(itemResult.UserDataLIst, userDataUserId);
var userData = GetOrAdd(itemResult, userDataUserId);
FetchFromResumeNode(subtree, item, userData);
}
@ -1006,19 +997,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
{
bool parsedValue;
if (bool.TryParse(val, out parsedValue))
{
if (!string.IsNullOrWhiteSpace(userDataUserId))
{
var userData = GetOrAdd(itemResult.UserDataLIst, userDataUserId);
var userData = GetOrAdd(itemResult, userDataUserId);
userData.IsFavorite = parsedValue;
}
}
}
break;
}
@ -1026,19 +1014,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(userDataUserId))
{
double parsedValue;
if (double.TryParse(val, NumberStyles.Any, _usCulture, out parsedValue))
{
if (!string.IsNullOrWhiteSpace(userDataUserId))
{
var userData = GetOrAdd(itemResult.UserDataLIst, userDataUserId);
var userData = GetOrAdd(itemResult, userDataUserId);
userData.Rating = parsedValue;
}
}
}
break;
}
@ -1048,21 +1033,9 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
private UserItemData GetOrAdd(List<UserItemData> userDataList, string userId)
private UserItemData GetOrAdd(MetadataResult<T> result, string userId)
{
var userData = userDataList.FirstOrDefault(i => string.Equals(userId, i.UserId.ToString("N"), StringComparison.OrdinalIgnoreCase));
if (userData == null)
{
userData = new UserItemData()
{
UserId = new Guid(userId)
};
userDataList.Add(userData);
}
return userData;
return result.GetOrAddUserData(userId);
}
private void FetchFromResumeNode(XmlReader reader, T item, UserItemData userData)

View File

@ -17,7 +17,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{
}
public void Fetch(LocalMetadataResult<Episode> item,
public void Fetch(MetadataResult<Episode> item,
List<LocalImageInfo> images,
string metadataFile,
CancellationToken cancellationToken)
@ -32,7 +32,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="itemResult">The item result.</param>
protected override void FetchDataFromXmlNode(XmlReader reader, LocalMetadataResult<Episode> itemResult)
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Episode> itemResult)
{
var item = itemResult.Item;

View File

@ -28,7 +28,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="itemResult">The item result.</param>
protected override void FetchDataFromXmlNode(XmlReader reader, LocalMetadataResult<Video> itemResult)
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Video> itemResult)
{
var item = itemResult.Item;

View File

@ -18,7 +18,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="itemResult">The item result.</param>
protected override void FetchDataFromXmlNode(XmlReader reader, LocalMetadataResult<Season> itemResult)
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Season> itemResult)
{
var item = itemResult.Item;

View File

@ -1,12 +1,10 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Xml;
namespace MediaBrowser.XbmcMetadata.Parsers
@ -22,7 +20,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="itemResult">The item result.</param>
protected override void FetchDataFromXmlNode(XmlReader reader, LocalMetadataResult<Series> itemResult)
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Series> itemResult)
{
var item = itemResult.Item;

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
_config = config;
}
protected override void Fetch(LocalMetadataResult<MusicAlbum> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<MusicAlbum> result, string path, CancellationToken cancellationToken)
{
new BaseNfoParser<MusicAlbum>(_logger, _config).Fetch(result, path, cancellationToken);
}

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
_config = config;
}
protected override void Fetch(LocalMetadataResult<MusicArtist> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<MusicArtist> result, string path, CancellationToken cancellationToken)
{
new BaseNfoParser<MusicArtist>(_logger, _config).Fetch(result, path, cancellationToken);
}

View File

@ -14,11 +14,11 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
protected IFileSystem FileSystem;
public async Task<LocalMetadataResult<T>> GetMetadata(ItemInfo info,
public async Task<MetadataResult<T>> GetMetadata(ItemInfo info,
IDirectoryService directoryService,
CancellationToken cancellationToken)
{
var result = new LocalMetadataResult<T>();
var result = new MetadataResult<T>();
var file = GetXmlFile(info, directoryService);
@ -48,7 +48,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
return result;
}
protected abstract void Fetch(LocalMetadataResult<T> result, string path, CancellationToken cancellationToken);
protected abstract void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken);
protected BaseNfoProvider(IFileSystem fileSystem)
{

View File

@ -24,9 +24,9 @@ namespace MediaBrowser.XbmcMetadata.Providers
_config = config;
}
protected override void Fetch(LocalMetadataResult<T> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken)
{
var tmpItem = new LocalMetadataResult<Video>
var tmpItem = new MetadataResult<Video>
{
Item = result.Item
};
@ -34,7 +34,11 @@ namespace MediaBrowser.XbmcMetadata.Providers
result.Item = (T)tmpItem.Item;
result.People = tmpItem.People;
result.UserDataLIst = tmpItem.UserDataLIst;
if (tmpItem.UserDataList != null)
{
result.UserDataList = tmpItem.UserDataList;
}
}
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)

View File

@ -23,7 +23,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
_config = config;
}
protected override void Fetch(LocalMetadataResult<Episode> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Episode> result, string path, CancellationToken cancellationToken)
{
var images = new List<LocalImageInfo>();

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
_config = config;
}
protected override void Fetch(LocalMetadataResult<Season> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Season> result, string path, CancellationToken cancellationToken)
{
new SeasonNfoParser(_logger, _config).Fetch(result, path, cancellationToken);
}

View File

@ -21,7 +21,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
_config = config;
}
protected override void Fetch(LocalMetadataResult<Series> result, string path, CancellationToken cancellationToken)
protected override void Fetch(MetadataResult<Series> result, string path, CancellationToken cancellationToken)
{
new SeriesNfoParser(_logger, _config).Fetch(result, path, cancellationToken);
}