2013-10-31 14:03:23 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
2013-03-04 05:43:06 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-02-25 00:13:45 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-03-03 06:58:04 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-06-09 16:47:28 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-03-02 17:59:15 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
|
using System;
|
2013-10-14 17:34:54 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-10-12 01:47:44 +00:00
|
|
|
|
using System.Globalization;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2013-10-12 01:47:44 +00:00
|
|
|
|
using System.Text;
|
2013-09-14 21:19:32 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
2013-06-09 16:47:28 +00:00
|
|
|
|
namespace MediaBrowser.Providers.TV
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class RemoteEpisodeProvider
|
|
|
|
|
/// </summary>
|
2013-11-04 20:49:36 +00:00
|
|
|
|
class TvdbEpisodeProvider : BaseMetadataProvider
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _provider manager
|
|
|
|
|
/// </summary>
|
2013-03-08 05:08:27 +00:00
|
|
|
|
private readonly IProviderManager _providerManager;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2013-02-25 00:13:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the HTTP client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The HTTP client.</value>
|
|
|
|
|
protected IHttpClient HttpClient { get; private set; }
|
2013-10-31 14:03:23 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2013-02-25 00:13:45 +00:00
|
|
|
|
|
2013-11-04 20:49:36 +00:00
|
|
|
|
internal static TvdbEpisodeProvider Current;
|
2013-11-01 15:55:25 +00:00
|
|
|
|
|
2013-03-04 05:43:06 +00:00
|
|
|
|
/// <summary>
|
2013-11-04 20:49:36 +00:00
|
|
|
|
/// Initializes a new instance of the <see cref="TvdbEpisodeProvider" /> class.
|
2013-03-04 05:43:06 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="httpClient">The HTTP client.</param>
|
|
|
|
|
/// <param name="logManager">The log manager.</param>
|
|
|
|
|
/// <param name="configurationManager">The configuration manager.</param>
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <param name="providerManager">The provider manager.</param>
|
2013-11-04 20:49:36 +00:00
|
|
|
|
public TvdbEpisodeProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager, IFileSystem fileSystem)
|
2013-03-04 05:43:06 +00:00
|
|
|
|
: base(logManager, configurationManager)
|
2013-02-25 00:13:45 +00:00
|
|
|
|
{
|
|
|
|
|
HttpClient = httpClient;
|
2013-03-08 05:08:27 +00:00
|
|
|
|
_providerManager = providerManager;
|
2013-10-31 14:03:23 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2013-11-01 15:55:25 +00:00
|
|
|
|
Current = this;
|
2013-02-25 00:13:45 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supportses the specified item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
return item is Episode;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 01:22:21 +00:00
|
|
|
|
public override ItemUpdateType ItemUpdateType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-06-27 23:01:03 +00:00
|
|
|
|
return ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataDownload;
|
2013-06-25 01:22:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-26 21:00:58 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the priority.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
2013-06-13 18:45:58 +00:00
|
|
|
|
get { return MetadataProviderPriority.Third; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [requires internet].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [requires internet]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public override bool RequiresInternet
|
|
|
|
|
{
|
|
|
|
|
get { return true; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether [refresh on version change].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [refresh on version change]; otherwise, <c>false</c>.</value>
|
|
|
|
|
protected override bool RefreshOnVersionChange
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the provider version.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The provider version.</value>
|
|
|
|
|
protected override string ProviderVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2013-11-17 15:27:48 +00:00
|
|
|
|
return "5";
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Needses the refresh internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="providerInfo">The provider info.</param>
|
|
|
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
|
|
|
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
2013-10-25 16:14:32 +00:00
|
|
|
|
var locationType = item.LocationType;
|
|
|
|
|
|
|
|
|
|
// Always use tvdb updates for non-file system episodes
|
|
|
|
|
if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-10-25 16:14:32 +00:00
|
|
|
|
// Don't proceed if there's local metadata
|
|
|
|
|
if (!ConfigurationManager.Configuration.EnableTvDbUpdates && HasLocalMeta(item))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 23:39:17 +00:00
|
|
|
|
return base.NeedsRefreshInternal(item, providerInfo);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-14 15:08:33 +00:00
|
|
|
|
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
|
|
|
|
var episode = (Episode)item;
|
|
|
|
|
|
|
|
|
|
var seriesId = episode.Series != null ? episode.Series.GetProviderId(MetadataProviders.Tvdb) : null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
|
|
|
|
{
|
|
|
|
|
// Process images
|
2013-11-04 20:49:36 +00:00
|
|
|
|
var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId);
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2013-10-14 15:08:33 +00:00
|
|
|
|
var files = GetEpisodeXmlFiles(episode, seriesDataPath);
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2013-10-14 15:08:33 +00:00
|
|
|
|
if (files.Count > 0)
|
2013-06-20 14:48:49 +00:00
|
|
|
|
{
|
2013-10-31 14:03:23 +00:00
|
|
|
|
return files.Select(i => _fileSystem.GetLastWriteTimeUtc(i)).Max() > providerInfo.LastRefreshed;
|
2013-06-20 14:48:49 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2013-10-14 15:08:33 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the episode XML files.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="episode">The episode.</param>
|
|
|
|
|
/// <param name="seriesDataPath">The series data path.</param>
|
|
|
|
|
/// <returns>List{FileInfo}.</returns>
|
2013-11-01 15:55:25 +00:00
|
|
|
|
internal List<FileInfo> GetEpisodeXmlFiles(Episode episode, string seriesDataPath)
|
2013-10-14 15:08:33 +00:00
|
|
|
|
{
|
|
|
|
|
var files = new List<FileInfo>();
|
|
|
|
|
|
|
|
|
|
if (episode.IndexNumber == null)
|
|
|
|
|
{
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var episodeNumber = episode.IndexNumber.Value;
|
|
|
|
|
var seasonNumber = episode.ParentIndexNumber;
|
|
|
|
|
|
|
|
|
|
if (seasonNumber == null)
|
|
|
|
|
{
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber));
|
|
|
|
|
|
|
|
|
|
var fileInfo = new FileInfo(file);
|
|
|
|
|
var usingAbsoluteData = false;
|
|
|
|
|
|
|
|
|
|
if (fileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
files.Add(fileInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", episodeNumber));
|
|
|
|
|
fileInfo = new FileInfo(file);
|
|
|
|
|
if (fileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
files.Add(fileInfo);
|
|
|
|
|
usingAbsoluteData = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var end = episode.IndexNumberEnd ?? episodeNumber;
|
|
|
|
|
episodeNumber++;
|
|
|
|
|
|
|
|
|
|
while (episodeNumber <= end)
|
|
|
|
|
{
|
|
|
|
|
if (usingAbsoluteData)
|
|
|
|
|
{
|
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", episodeNumber));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fileInfo = new FileInfo(file);
|
|
|
|
|
if (fileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
files.Add(fileInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
episodeNumber++;
|
|
|
|
|
}
|
2013-08-26 21:00:58 +00:00
|
|
|
|
|
2013-10-14 15:08:33 +00:00
|
|
|
|
return files;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <param name="force">if set to <c>true</c> [force].</param>
|
2013-05-21 03:16:43 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
2013-12-06 20:07:34 +00:00
|
|
|
|
public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2013-10-26 22:01:21 +00:00
|
|
|
|
var status = ProviderRefreshStatus.Success;
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
var episode = (Episode)item;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
|
|
|
|
var seriesId = episode.Series != null ? episode.Series.GetProviderId(MetadataProviders.Tvdb) : null;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-11-04 20:49:36 +00:00
|
|
|
|
var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(ConfigurationManager.ApplicationPaths, seriesId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
try
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
status = await FetchEpisodeData(episode, seriesDataPath, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
// Don't fail the provider because this will just keep on going and going.
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2013-12-06 20:07:34 +00:00
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow, providerInfo, status);
|
2013-10-26 22:01:21 +00:00
|
|
|
|
return true;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the episode data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="episode">The episode.</param>
|
2013-10-12 01:47:44 +00:00
|
|
|
|
/// <param name="seriesDataPath">The series data path.</param>
|
2013-04-10 15:56:36 +00:00
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <returns>Task{System.Boolean}.</returns>
|
2013-10-12 01:47:44 +00:00
|
|
|
|
private async Task<ProviderRefreshStatus> FetchEpisodeData(Episode episode, string seriesDataPath, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-12 23:36:42 +00:00
|
|
|
|
var status = ProviderRefreshStatus.Success;
|
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (episode.IndexNumber == null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-12 23:36:42 +00:00
|
|
|
|
return status;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
var episodeNumber = episode.IndexNumber.Value;
|
2013-10-14 15:08:33 +00:00
|
|
|
|
var seasonNumber = episode.ParentIndexNumber;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
if (seasonNumber == null)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-05-21 03:16:43 +00:00
|
|
|
|
return status;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
var file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber));
|
|
|
|
|
var success = false;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
var usingAbsoluteData = false;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
status = await FetchMainEpisodeInfo(episode, file, cancellationToken).ConfigureAwait(false);
|
2013-05-06 19:31:57 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
success = true;
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
// Could be using absolute numbering
|
|
|
|
|
if (seasonNumber.Value != 1)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
throw;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
if (!success)
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", episodeNumber));
|
|
|
|
|
|
|
|
|
|
status = await FetchMainEpisodeInfo(episode, file, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
usingAbsoluteData = true;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
var end = episode.IndexNumberEnd ?? episodeNumber;
|
|
|
|
|
episodeNumber++;
|
|
|
|
|
|
|
|
|
|
while (episodeNumber <= end)
|
2013-06-18 18:54:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (usingAbsoluteData)
|
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", episodeNumber));
|
2013-06-18 18:54:06 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber));
|
|
|
|
|
}
|
2013-06-18 18:54:06 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FetchAdditionalPartInfo(episode, file, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
break;
|
2013-06-18 18:54:06 +00:00
|
|
|
|
}
|
2013-08-26 21:00:58 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
episodeNumber++;
|
2013-06-18 18:54:06 +00:00
|
|
|
|
}
|
2013-05-18 18:16:07 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
|
|
private async Task<ProviderRefreshStatus> FetchMainEpisodeInfo(Episode item, string xmlFile, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var status = ProviderRefreshStatus.Success;
|
|
|
|
|
|
|
|
|
|
using (var streamReader = new StreamReader(xmlFile, Encoding.UTF8))
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
item.People.Clear();
|
|
|
|
|
}
|
2013-06-28 20:25:58 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
// Use XmlReader for best performance
|
|
|
|
|
using (var reader = XmlReader.Create(streamReader, new XmlReaderSettings
|
|
|
|
|
{
|
|
|
|
|
CheckCharacters = false,
|
|
|
|
|
IgnoreProcessingInstructions = true,
|
|
|
|
|
IgnoreComments = true,
|
|
|
|
|
ValidationType = ValidationType.None
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
|
|
|
|
// Loop through each element
|
|
|
|
|
while (reader.Read())
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "id":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tvdb, val);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "IMDB_ID":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Imdb, val);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-15 21:31:33 +00:00
|
|
|
|
|
2013-11-17 15:27:48 +00:00
|
|
|
|
case "airsbefore_episode":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
|
|
|
|
|
{
|
|
|
|
|
item.AirsBeforeEpisodeNumber = rval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 21:31:33 +00:00
|
|
|
|
case "airsafter_season":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
|
|
|
|
|
{
|
2013-11-17 15:27:48 +00:00
|
|
|
|
item.AirsAfterSeasonNumber = rval;
|
2013-11-15 21:31:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-17 15:27:48 +00:00
|
|
|
|
|
2013-11-15 21:31:33 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "airsbefore_season":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
|
|
|
|
|
{
|
2013-11-17 15:27:48 +00:00
|
|
|
|
item.AirsBeforeSeasonNumber = rval;
|
2013-11-15 21:31:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-17 15:27:48 +00:00
|
|
|
|
|
2013-11-15 21:31:33 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-10-12 01:47:44 +00:00
|
|
|
|
|
|
|
|
|
case "EpisodeName":
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Name))
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.Name = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "filename":
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(item.PrimaryImagePath))
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var url = TVUtils.BannerUrl + val;
|
|
|
|
|
|
2013-11-04 20:49:36 +00:00
|
|
|
|
await _providerManager.SaveImage(item, url, TvdbSeriesProvider.Current.TvDbResourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch (HttpException)
|
|
|
|
|
{
|
|
|
|
|
status = ProviderRefreshStatus.CompletedWithErrors;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Overview":
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Overview))
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.Overview = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Rating":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
float rval;
|
|
|
|
|
|
|
|
|
|
// float.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (float.TryParse(val, NumberStyles.AllowDecimalPoint, _usCulture, out rval))
|
|
|
|
|
{
|
|
|
|
|
item.CommunityRating = rval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "RatingCount":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
|
|
// int.TryParse is local aware, so it can be probamatic, force us culture
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
|
|
|
|
|
{
|
|
|
|
|
item.VoteCount = rval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "FirstAired":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
DateTime date;
|
|
|
|
|
if (DateTime.TryParse(val, out date))
|
|
|
|
|
{
|
|
|
|
|
date = date.ToUniversalTime();
|
|
|
|
|
|
|
|
|
|
item.PremiereDate = date;
|
|
|
|
|
item.ProductionYear = date.Year;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Director":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
|
|
|
|
AddPeople(item, val, PersonType.Director);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "GuestStars":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
|
|
|
|
AddGuestStars(item, val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Writer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
|
|
|
|
AddPeople(item, val, PersonType.Writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-12 01:47:44 +00:00
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddPeople(BaseItem item, string val, string personType)
|
|
|
|
|
{
|
|
|
|
|
// Sometimes tvdb actors have leading spaces
|
|
|
|
|
foreach (var person in val.Split(new[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i))
|
|
|
|
|
.Select(str => new PersonInfo { Type = personType, Name = str.Trim() }))
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
item.AddPerson(person);
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
2013-10-05 16:16:19 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
private void AddGuestStars(BaseItem item, string val)
|
|
|
|
|
{
|
|
|
|
|
// Sometimes tvdb actors have leading spaces
|
|
|
|
|
//Regex Info:
|
|
|
|
|
//The first block are the posible delimitators (open-parentheses should be there cause if dont the next block will fail)
|
|
|
|
|
//The second block Allow the delimitators to be part of the text if they're inside parentheses
|
|
|
|
|
var persons = Regex.Matches(val, @"(?<delimitators>([^|,(])|(?<ignoreinParentheses>\([^)]*\)*))+")
|
|
|
|
|
.Cast<Match>()
|
|
|
|
|
.Select(m => m.Value)
|
|
|
|
|
.Where(i => !string.IsNullOrWhiteSpace(i) && !string.IsNullOrEmpty(i));
|
|
|
|
|
|
|
|
|
|
foreach (var person in persons.Select(str =>
|
2013-10-05 16:16:19 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
var nameGroup = str.Split(new[] { '(' }, 2, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
var name = nameGroup[0].Trim();
|
|
|
|
|
var roles = nameGroup.Count() > 1 ? nameGroup[1].Trim() : null;
|
|
|
|
|
if (roles != null)
|
|
|
|
|
roles = roles.EndsWith(")") ? roles.Substring(0, roles.Length - 1) : roles;
|
|
|
|
|
return new PersonInfo { Type = PersonType.GuestStar, Name = name, Role = roles };
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
item.AddPerson(person);
|
2013-10-05 16:16:19 +00:00
|
|
|
|
}
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
2013-10-05 16:16:19 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
private void FetchAdditionalPartInfo(Episode item, string xmlFile, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
using (var streamReader = new StreamReader(xmlFile, Encoding.UTF8))
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
// Use XmlReader for best performance
|
|
|
|
|
using (var reader = XmlReader.Create(streamReader, new XmlReaderSettings
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
CheckCharacters = false,
|
|
|
|
|
IgnoreProcessingInstructions = true,
|
|
|
|
|
IgnoreComments = true,
|
|
|
|
|
ValidationType = ValidationType.None
|
|
|
|
|
}))
|
2013-06-18 18:54:06 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
reader.MoveToContent();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
// Loop through each element
|
|
|
|
|
while (reader.Read())
|
2013-06-15 22:19:47 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
if (reader.NodeType == XmlNodeType.Element)
|
|
|
|
|
{
|
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "EpisodeName":
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Name))
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.Name += ", " + val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Overview":
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Overview))
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.Overview += Environment.NewLine + Environment.NewLine + val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Director":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
|
|
|
|
AddPeople(item, val, PersonType.Director);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "GuestStars":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
|
|
|
|
AddGuestStars(item, val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Writer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
|
|
|
|
AddPeople(item, val, PersonType.Writer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
reader.Skip();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-15 22:19:47 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether [has local meta] [the specified episode].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="episode">The episode.</param>
|
|
|
|
|
/// <returns><c>true</c> if [has local meta] [the specified episode]; otherwise, <c>false</c>.</returns>
|
2013-04-28 23:39:17 +00:00
|
|
|
|
private bool HasLocalMeta(BaseItem episode)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
return (episode.Parent.ResolveArgs.ContainsMetaFileByName(Path.GetFileNameWithoutExtension(episode.Path) + ".xml"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|