tv metadata fixes

This commit is contained in:
Luke Pulverenti 2013-10-10 12:55:07 -04:00
parent 5897b2555f
commit 15046e5703
7 changed files with 112 additions and 46 deletions

View File

@ -233,6 +233,16 @@ namespace MediaBrowser.Controller.Providers
throw new ArgumentNullException("providerInfo");
}
if (NeedsRefreshBasedOnCompareDate(item, providerInfo))
{
return true;
}
if (RefreshOnFileSystemStampChange && item.LocationType == LocationType.FileSystem && HasFileSystemStampChanged(item, providerInfo))
{
return true;
}
if (RefreshOnVersionChange && !String.Equals(ProviderVersion, providerInfo.ProviderVersion))
{
return true;
@ -248,16 +258,6 @@ namespace MediaBrowser.Controller.Providers
return true;
}
if (NeedsRefreshBasedOnCompareDate(item, providerInfo))
{
return true;
}
if (RefreshOnFileSystemStampChange && item.LocationType == LocationType.FileSystem && HasFileSystemStampChanged(item, providerInfo))
{
return true;
}
return false;
}

View File

@ -72,15 +72,18 @@ namespace MediaBrowser.Providers.Games
var metaFile = GameXmlSaver.GetGameSavePath(game);
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
if (File.Exists(metaFile))
{
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
new BaseItemXmlParser<Game>(Logger).Fetch(game, metaFile, cancellationToken);
}
finally
{
XmlParsingResourcePool.Release();
try
{
new BaseItemXmlParser<Game>(Logger).Fetch(game, metaFile, cancellationToken);
}
finally
{
XmlParsingResourcePool.Release();
}
}
SetLastRefreshed(game, DateTime.UtcNow);

View File

@ -92,17 +92,20 @@ namespace MediaBrowser.Providers.Movies
var path = MovieXmlSaver.GetMovieSavePath(item);
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
try
if (File.Exists(path))
{
var video = (Video)item;
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
await new MovieXmlParser(Logger, _itemRepo).FetchAsync(video, path, cancellationToken).ConfigureAwait(false);
}
finally
{
XmlParsingResourcePool.Release();
try
{
var video = (Video)item;
await new MovieXmlParser(Logger, _itemRepo).FetchAsync(video, path, cancellationToken).ConfigureAwait(false);
}
finally
{
XmlParsingResourcePool.Release();
}
}
SetLastRefreshed(item, DateTime.UtcNow);

View File

@ -93,20 +93,18 @@ namespace MediaBrowser.Providers.TV
var file = item.ResolveArgs.Parent.ResolveArgs.GetMetaFileByPath(metadataFile);
if (file == null)
if (file != null)
{
return false;
}
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
await XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
try
{
await new EpisodeXmlParser(Logger, _itemRepo).FetchAsync((Episode)item, metadataFile, cancellationToken).ConfigureAwait(false);
}
finally
{
XmlParsingResourcePool.Release();
try
{
await new EpisodeXmlParser(Logger, _itemRepo).FetchAsync((Episode)item, metadataFile, cancellationToken).ConfigureAwait(false);
}
finally
{
XmlParsingResourcePool.Release();
}
}
SetLastRefreshed(item, DateTime.UtcNow);

View File

@ -120,7 +120,7 @@ namespace MediaBrowser.Providers.TV
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
// Don't proceed if there's local metadata
if (HasLocalMeta(item) && !ConfigurationManager.Configuration.EnableTvDbUpdates)
if (!ConfigurationManager.Configuration.EnableTvDbUpdates && HasLocalMeta(item))
{
return false;
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
@ -162,7 +163,7 @@ namespace MediaBrowser.Providers.TV
}
}
protected override DateTime CompareDate(BaseItem item)
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
{
var seriesId = item.GetProviderId(MetadataProviders.Tvdb);
@ -180,16 +181,17 @@ namespace MediaBrowser.Providers.TV
if (files.Count > 0)
{
return files.Max();
return files.Max() > providerInfo.LastRefreshed;
}
}
catch (DirectoryNotFoundException)
{
// Don't blow up
return true;
}
}
return base.CompareDate(item);
return base.NeedsRefreshBasedOnCompareDate(item, providerInfo);
}
/// <summary>
@ -298,6 +300,66 @@ namespace MediaBrowser.Providers.TV
_zipClient.ExtractAll(ms, seriesDataPath, true);
}
}
foreach (var file in Directory.EnumerateFiles(seriesDataPath, "*.xml", SearchOption.AllDirectories).ToList())
{
await SanitizeXmlFile(file).ConfigureAwait(false);
}
}
/// <summary>
/// Sanitizes the XML file.
/// </summary>
/// <param name="file">The file.</param>
/// <returns>Task.</returns>
private async Task SanitizeXmlFile(string file)
{
string validXml;
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, true))
{
using (var reader = new StreamReader(fileStream))
{
var xml = await reader.ReadToEndAsync().ConfigureAwait(false);
validXml = StripInvalidXmlCharacters(xml);
}
}
using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, true))
{
using (var writer = new StreamWriter(fileStream))
{
await writer.WriteAsync(validXml).ConfigureAwait(false);
}
}
}
/// <summary>
/// Strips the invalid XML characters.
/// </summary>
/// <param name="inString">The in string.</param>
/// <returns>System.String.</returns>
public static string StripInvalidXmlCharacters(string inString)
{
if (inString == null) return null;
var sbOutput = new StringBuilder();
char ch;
for (int i = 0; i < inString.Length; i++)
{
ch = inString[i];
if ((ch >= 0x0020 && ch <= 0xD7FF) ||
(ch >= 0xE000 && ch <= 0xFFFD) ||
ch == 0x0009 ||
ch == 0x000A ||
ch == 0x000D)
{
sbOutput.Append(ch);
}
}
return sbOutput.ToString();
}
/// <summary>
@ -320,7 +382,7 @@ namespace MediaBrowser.Providers.TV
/// <returns>System.String.</returns>
internal static string GetSeriesDataPath(IApplicationPaths appPaths)
{
var dataPath = Path.Combine(appPaths.DataPath, "tvdb");
var dataPath = Path.Combine(appPaths.DataPath, "tvdb-v2");
return dataPath;
}

View File

@ -22,7 +22,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
private readonly object _syncLock = new object();
private Timer UpdateTimer { get; set; }
private const int UpdateDuration = 2000;
private const int UpdateDuration = 500;
private readonly Dictionary<Guid, List<string>> _changedKeys = new Dictionary<Guid, List<string>>();