2013-10-31 14:03:23 +00:00
|
|
|
|
using MediaBrowser.Common.IO;
|
2014-02-20 04:53:15 +00:00
|
|
|
|
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-06-09 16:47:28 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2015-05-07 03:11:51 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-02-20 04:53:15 +00:00
|
|
|
|
using MediaBrowser.Model.Providers;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
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;
|
2015-10-04 04:23:11 +00:00
|
|
|
|
using CommonIO;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-06-09 16:47:28 +00:00
|
|
|
|
namespace MediaBrowser.Providers.TV
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class RemoteEpisodeProvider
|
|
|
|
|
/// </summary>
|
2015-09-19 21:25:19 +00:00
|
|
|
|
class TvdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IItemIdentityProvider<EpisodeInfo>, IHasChangeMonitor
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
private const string FullIdFormat = "{0}:{1}:{2}"; // seriesId:seasonIndex:episodeNumbers
|
|
|
|
|
private static readonly string FullIdKey = MetadataProviders.Tvdb + "-Full";
|
|
|
|
|
|
2013-11-04 20:49:36 +00:00
|
|
|
|
internal static TvdbEpisodeProvider Current;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
private readonly IFileSystem _fileSystem;
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
2015-01-27 06:50:40 +00:00
|
|
|
|
private readonly IHttpClient _httpClient;
|
2015-05-07 03:11:51 +00:00
|
|
|
|
private readonly ILogger _logger;
|
2013-11-01 15:55:25 +00:00
|
|
|
|
|
2015-05-07 03:11:51 +00:00
|
|
|
|
public TvdbEpisodeProvider(IFileSystem fileSystem, IServerConfigurationManager config, IHttpClient httpClient, ILogger logger)
|
2013-02-25 00:13:45 +00:00
|
|
|
|
{
|
2013-10-31 14:03:23 +00:00
|
|
|
|
_fileSystem = fileSystem;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
_config = config;
|
2015-01-27 06:50:40 +00:00
|
|
|
|
_httpClient = httpClient;
|
2015-05-07 03:11:51 +00:00
|
|
|
|
_logger = logger;
|
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
|
|
|
|
|
2014-02-20 04:53:15 +00:00
|
|
|
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2015-10-21 05:09:50 +00:00
|
|
|
|
var seriesProviderIds = searchInfo.SeriesProviderIds;
|
|
|
|
|
|
2014-02-20 04:53:15 +00:00
|
|
|
|
var list = new List<RemoteSearchResult>();
|
|
|
|
|
|
2015-09-19 22:56:59 +00:00
|
|
|
|
var identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
|
2015-09-19 21:25:19 +00:00
|
|
|
|
|
|
|
|
|
if (identity == null)
|
|
|
|
|
{
|
|
|
|
|
await Identify(searchInfo).ConfigureAwait(false);
|
2015-09-19 22:56:59 +00:00
|
|
|
|
identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
|
2015-09-19 21:25:19 +00:00
|
|
|
|
}
|
2014-02-20 04:53:15 +00:00
|
|
|
|
|
2014-05-06 02:00:16 +00:00
|
|
|
|
if (identity != null)
|
2014-02-20 04:53:15 +00:00
|
|
|
|
{
|
2015-10-21 05:09:50 +00:00
|
|
|
|
seriesProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
seriesProviderIds[MetadataProviders.Tvdb.ToString()] = identity.Value.SeriesId;
|
|
|
|
|
}
|
2014-03-05 02:59:59 +00:00
|
|
|
|
|
2015-10-21 05:09:50 +00:00
|
|
|
|
if (TvdbSeriesProvider.IsValidSeries(seriesProviderIds))
|
|
|
|
|
{
|
|
|
|
|
var seriesDataPath = await TvdbSeriesProvider.Current.EnsureSeriesInfo(seriesProviderIds, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
2014-02-20 04:53:15 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-10-21 05:09:50 +00:00
|
|
|
|
var metadataResult = FetchEpisodeData(searchInfo, identity, seriesDataPath, searchInfo.SeriesProviderIds, cancellationToken);
|
2014-02-20 04:53:15 +00:00
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
if (metadataResult.HasMetadata)
|
2014-02-20 04:53:15 +00:00
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
var item = metadataResult.Item;
|
|
|
|
|
|
2014-02-20 04:53:15 +00:00
|
|
|
|
list.Add(new RemoteSearchResult
|
|
|
|
|
{
|
|
|
|
|
IndexNumber = item.IndexNumber,
|
|
|
|
|
Name = item.Name,
|
|
|
|
|
ParentIndexNumber = item.ParentIndexNumber,
|
|
|
|
|
PremiereDate = item.PremiereDate,
|
|
|
|
|
ProductionYear = item.ProductionYear,
|
|
|
|
|
ProviderIds = item.ProviderIds,
|
|
|
|
|
SearchProviderName = Name,
|
|
|
|
|
IndexNumberEnd = item.IndexNumberEnd
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
// Don't fail the provider because this will just keep on going and going.
|
|
|
|
|
}
|
2014-12-23 03:58:14 +00:00
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
// Don't fail the provider because this will just keep on going and going.
|
|
|
|
|
}
|
2014-02-20 04:53:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
public string Name
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2014-02-04 20:19:29 +00:00
|
|
|
|
get { return "TheTVDB"; }
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 02:00:16 +00:00
|
|
|
|
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
2013-06-25 01:22:21 +00:00
|
|
|
|
{
|
2015-09-19 22:56:59 +00:00
|
|
|
|
var identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
|
2015-09-19 21:25:19 +00:00
|
|
|
|
|
|
|
|
|
if (identity == null)
|
|
|
|
|
{
|
|
|
|
|
await Identify(searchInfo).ConfigureAwait(false);
|
2015-09-19 22:56:59 +00:00
|
|
|
|
identity = Identity.ParseIdentity(searchInfo.GetProviderId(FullIdKey));
|
2015-09-19 21:25:19 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
var result = new MetadataResult<Episode>();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-05-06 02:00:16 +00:00
|
|
|
|
if (identity != null)
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, identity.Value.SeriesId);
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
try
|
2013-10-25 16:14:32 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
result = FetchEpisodeData(searchInfo, identity.Value, seriesDataPath, searchInfo.SeriesProviderIds, cancellationToken);
|
2014-02-04 20:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
// Don't fail the provider because this will just keep on going and going.
|
2013-10-25 16:14:32 +00:00
|
|
|
|
}
|
2014-12-23 03:58:14 +00:00
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
// Don't fail the provider because this will just keep on going and going.
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
2015-05-07 03:11:51 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("No series identity found for {0}", searchInfo.Name);
|
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2014-05-06 02:00:16 +00:00
|
|
|
|
return result;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 18:39:41 +00:00
|
|
|
|
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2014-02-08 22:38:02 +00:00
|
|
|
|
// Only enable for virtual items
|
|
|
|
|
if (item.LocationType != LocationType.Virtual)
|
2014-02-07 00:43:45 +00:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 03:16:43 +00:00
|
|
|
|
var episode = (Episode)item;
|
2014-02-04 20:19:29 +00:00
|
|
|
|
var series = episode.Series;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
var seriesId = series != null ? series.GetProviderId(MetadataProviders.Tvdb) : null;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(seriesId))
|
|
|
|
|
{
|
|
|
|
|
// Process images
|
2014-02-04 20:19:29 +00:00
|
|
|
|
var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, seriesId);
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
var files = GetEpisodeXmlFiles(episode.ParentIndexNumber, episode.IndexNumber, episode.IndexNumberEnd, seriesDataPath);
|
2013-05-21 03:16:43 +00:00
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
return files.Any(i => _fileSystem.GetLastWriteTimeUtc(i) > date);
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2014-02-04 20:19:29 +00:00
|
|
|
|
|
2013-10-14 15:08:33 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the episode XML files.
|
|
|
|
|
/// </summary>
|
2014-02-04 20:19:29 +00:00
|
|
|
|
/// <param name="seasonNumber">The season number.</param>
|
|
|
|
|
/// <param name="episodeNumber">The episode number.</param>
|
|
|
|
|
/// <param name="endingEpisodeNumber">The ending episode number.</param>
|
2013-10-14 15:08:33 +00:00
|
|
|
|
/// <param name="seriesDataPath">The series data path.</param>
|
|
|
|
|
/// <returns>List{FileInfo}.</returns>
|
2015-10-04 03:38:46 +00:00
|
|
|
|
internal List<FileSystemMetadata> GetEpisodeXmlFiles(int? seasonNumber, int? episodeNumber, int? endingEpisodeNumber, string seriesDataPath)
|
2013-10-14 15:08:33 +00:00
|
|
|
|
{
|
2015-10-04 03:38:46 +00:00
|
|
|
|
var files = new List<FileSystemMetadata>();
|
2013-10-14 15:08:33 +00:00
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
if (episodeNumber == null)
|
2013-10-14 15:08:33 +00:00
|
|
|
|
{
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (seasonNumber == null)
|
|
|
|
|
{
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber));
|
|
|
|
|
|
2015-10-04 03:38:46 +00:00
|
|
|
|
var fileInfo = _fileSystem.GetFileInfo(file);
|
2013-10-14 15:08:33 +00:00
|
|
|
|
var usingAbsoluteData = false;
|
|
|
|
|
|
|
|
|
|
if (fileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
files.Add(fileInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", episodeNumber));
|
2015-10-04 03:38:46 +00:00
|
|
|
|
fileInfo = _fileSystem.GetFileInfo(file);
|
2013-10-14 15:08:33 +00:00
|
|
|
|
if (fileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
files.Add(fileInfo);
|
|
|
|
|
usingAbsoluteData = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 20:19:29 +00:00
|
|
|
|
var end = endingEpisodeNumber ?? episodeNumber;
|
2013-10-14 15:08:33 +00:00
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-04 03:38:46 +00:00
|
|
|
|
fileInfo = _fileSystem.GetFileInfo(file);
|
2013-10-14 15:08:33 +00:00
|
|
|
|
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 the episode data.
|
|
|
|
|
/// </summary>
|
2014-02-04 20:19:29 +00:00
|
|
|
|
/// <param name="id">The identifier.</param>
|
2014-12-23 03:58:14 +00:00
|
|
|
|
/// <param name="identity">The identity.</param>
|
2013-10-12 01:47:44 +00:00
|
|
|
|
/// <param name="seriesDataPath">The series data path.</param>
|
2014-12-23 03:58:14 +00:00
|
|
|
|
/// <param name="seriesProviderIds">The series provider ids.</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>
|
2015-10-21 05:09:50 +00:00
|
|
|
|
private MetadataResult<Episode> FetchEpisodeData(EpisodeInfo id, Identity? identity, string seriesDataPath, Dictionary<string, string> seriesProviderIds, CancellationToken cancellationToken)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
2015-10-21 05:09:50 +00:00
|
|
|
|
var episodeNumber = identity.HasValue ? (identity.Value.EpisodeNumber) : id.IndexNumber.Value;
|
2014-03-27 02:14:06 +00:00
|
|
|
|
var seasonOffset = TvdbSeriesProvider.GetSeriesOffset(seriesProviderIds) ?? 0;
|
2015-10-21 05:09:50 +00:00
|
|
|
|
var seasonNumber = identity.HasValue ? (identity.Value.SeasonIndex + seasonOffset) : id.ParentIndexNumber;
|
2014-06-19 20:35:35 +00:00
|
|
|
|
|
|
|
|
|
string file;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
var usingAbsoluteData = false;
|
2014-02-06 04:39:16 +00:00
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
var result = new MetadataResult<Episode>()
|
2014-02-06 04:39:16 +00:00
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
Item = new Episode
|
|
|
|
|
{
|
|
|
|
|
IndexNumber = id.IndexNumber,
|
|
|
|
|
ParentIndexNumber = id.ParentIndexNumber,
|
|
|
|
|
IndexNumberEnd = id.IndexNumberEnd
|
|
|
|
|
}
|
2014-02-06 04:39:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2014-06-19 20:35:35 +00:00
|
|
|
|
if (seasonNumber != null)
|
|
|
|
|
{
|
|
|
|
|
file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber));
|
2015-06-29 01:10:45 +00:00
|
|
|
|
FetchMainEpisodeInfo(result, file, cancellationToken);
|
2013-05-06 19:31:57 +00:00
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
result.HasMetadata = true;
|
2014-06-19 20:35:35 +00:00
|
|
|
|
}
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
2013-05-21 03:16:43 +00:00
|
|
|
|
{
|
2013-10-12 01:47:44 +00:00
|
|
|
|
// Could be using absolute numbering
|
2014-06-19 20:35:35 +00:00
|
|
|
|
if (seasonNumber.HasValue && 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
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
if (!result.HasMetadata)
|
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));
|
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
FetchMainEpisodeInfo(result, file, cancellationToken);
|
|
|
|
|
result.HasMetadata = true;
|
2013-10-12 01:47:44 +00:00
|
|
|
|
usingAbsoluteData = true;
|
2013-05-21 03:16:43 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2015-10-21 05:09:50 +00:00
|
|
|
|
var end = identity.HasValue ? (identity.Value.EpisodeNumberEnd ?? episodeNumber) : (id.IndexNumberEnd ?? episodeNumber);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
FetchAdditionalPartInfo(result, file, cancellationToken);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
break;
|
2013-06-18 18:54:06 +00:00
|
|
|
|
}
|
2014-12-23 03:58:14 +00:00
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
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
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
return result;
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
private void FetchMainEpisodeInfo(MetadataResult<Episode> result, string xmlFile, CancellationToken cancellationToken)
|
2013-10-12 01:47:44 +00:00
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
var item = result.Item;
|
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
CheckCharacters = false,
|
|
|
|
|
IgnoreProcessingInstructions = true,
|
|
|
|
|
IgnoreComments = true,
|
|
|
|
|
ValidationType = ValidationType.None
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
reader.MoveToContent();
|
|
|
|
|
|
2015-07-24 02:48:10 +00:00
|
|
|
|
result.ResetPeople();
|
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
// 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-12-08 18:07:45 +00:00
|
|
|
|
case "DVD_episodenumber":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2013-12-08 20:33:24 +00:00
|
|
|
|
float num;
|
2013-12-08 18:07:45 +00:00
|
|
|
|
|
2013-12-08 20:33:24 +00:00
|
|
|
|
if (float.TryParse(val, NumberStyles.Any, _usCulture, out num))
|
2013-12-08 18:07:45 +00:00
|
|
|
|
{
|
2013-12-08 22:16:59 +00:00
|
|
|
|
item.DvdEpisodeNumber = num;
|
2013-12-08 18:07:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "DVD_season":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
2013-12-08 20:33:24 +00:00
|
|
|
|
float num;
|
2013-12-08 18:07:45 +00:00
|
|
|
|
|
2013-12-08 20:33:24 +00:00
|
|
|
|
if (float.TryParse(val, NumberStyles.Any, _usCulture, out num))
|
2013-12-08 18:07:45 +00:00
|
|
|
|
{
|
2013-12-08 20:33:24 +00:00
|
|
|
|
item.DvdSeasonNumber = Convert.ToInt32(num);
|
2013-12-08 18:07:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 20:42:42 +00:00
|
|
|
|
case "absolute_number":
|
|
|
|
|
{
|
|
|
|
|
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.AbsoluteEpisodeNumber = rval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-04 20:19:29 +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 "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))
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
AddPeople(result, val, PersonType.Director);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "GuestStars":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
AddGuestStars(result, val);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Writer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
AddPeople(result, val, PersonType.Writer);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
private void AddPeople<T>(MetadataResult<T> result, string val, string personType)
|
2013-10-12 01:47:44 +00:00
|
|
|
|
{
|
|
|
|
|
// 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
|
|
|
|
{
|
2015-07-24 02:48:10 +00:00
|
|
|
|
result.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
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
private void AddGuestStars<T>(MetadataResult<T> result, string val)
|
|
|
|
|
where T : BaseItem
|
2013-10-12 01:47:44 +00:00
|
|
|
|
{
|
|
|
|
|
// 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;
|
2014-05-23 23:58:28 +00:00
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
return new PersonInfo { Type = PersonType.GuestStar, Name = name, Role = roles };
|
|
|
|
|
}))
|
|
|
|
|
{
|
2014-05-23 23:58:28 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(person.Name))
|
|
|
|
|
{
|
2015-07-24 02:48:10 +00:00
|
|
|
|
result.AddPerson(person);
|
2014-05-23 23:58:28 +00:00
|
|
|
|
}
|
2013-10-05 16:16:19 +00:00
|
|
|
|
}
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
2013-10-05 16:16:19 +00:00
|
|
|
|
|
2015-06-29 01:10:45 +00:00
|
|
|
|
private void FetchAdditionalPartInfo(MetadataResult<Episode> result, string xmlFile, CancellationToken cancellationToken)
|
2013-10-12 01:47:44 +00:00
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
var item = result.Item;
|
|
|
|
|
|
2013-10-12 01:47:44 +00:00
|
|
|
|
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))
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
AddPeople(result, val, PersonType.Director);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "GuestStars":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
AddGuestStars(result, val);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "Writer":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
if (!item.LockedFields.Contains(MetadataFields.Cast))
|
|
|
|
|
{
|
2015-06-29 01:10:45 +00:00
|
|
|
|
AddPeople(result, val, PersonType.Writer);
|
2013-10-12 01:47:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2014-02-20 04:53:15 +00:00
|
|
|
|
|
|
|
|
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2015-01-27 06:50:40 +00:00
|
|
|
|
return _httpClient.GetResponse(new HttpRequestOptions
|
|
|
|
|
{
|
|
|
|
|
CancellationToken = cancellationToken,
|
|
|
|
|
Url = url,
|
|
|
|
|
ResourcePool = TvdbSeriesProvider.Current.TvDbResourcePool
|
|
|
|
|
});
|
2014-02-20 04:53:15 +00:00
|
|
|
|
}
|
2014-05-06 02:00:16 +00:00
|
|
|
|
|
2015-09-19 21:25:19 +00:00
|
|
|
|
public Task Identify(EpisodeInfo info)
|
2014-05-06 02:00:16 +00:00
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
if (info.ProviderIds.ContainsKey(FullIdKey))
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult<object>(null);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 02:00:16 +00:00
|
|
|
|
string seriesTvdbId;
|
|
|
|
|
info.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out seriesTvdbId);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(seriesTvdbId) || info.IndexNumber == null)
|
|
|
|
|
{
|
2015-09-19 21:25:19 +00:00
|
|
|
|
return Task.FromResult<object>(null);
|
2014-05-06 02:00:16 +00:00
|
|
|
|
}
|
2015-09-19 21:25:19 +00:00
|
|
|
|
|
2015-09-19 22:56:59 +00:00
|
|
|
|
var id = new Identity(seriesTvdbId, info.ParentIndexNumber, info.IndexNumber.Value, info.IndexNumberEnd);
|
|
|
|
|
info.SetProviderId(FullIdKey, id.ToString());
|
2014-05-06 02:00:16 +00:00
|
|
|
|
|
|
|
|
|
return Task.FromResult(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Order { get { return 0; } }
|
2015-09-19 21:25:19 +00:00
|
|
|
|
|
2015-09-19 22:56:59 +00:00
|
|
|
|
public struct Identity
|
2015-09-19 21:25:19 +00:00
|
|
|
|
{
|
|
|
|
|
public string SeriesId { get; private set; }
|
|
|
|
|
public int? SeasonIndex { get; private set; }
|
|
|
|
|
public int EpisodeNumber { get; private set; }
|
|
|
|
|
public int? EpisodeNumberEnd { get; private set; }
|
|
|
|
|
|
2015-09-19 22:56:59 +00:00
|
|
|
|
public Identity(string id)
|
|
|
|
|
: this()
|
|
|
|
|
{
|
|
|
|
|
this = ParseIdentity(id).Value;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-19 21:25:19 +00:00
|
|
|
|
public Identity(string seriesId, int? seasonIndex, int episodeNumber, int? episodeNumberEnd)
|
2015-09-19 22:56:59 +00:00
|
|
|
|
: this()
|
2015-09-19 21:25:19 +00:00
|
|
|
|
{
|
|
|
|
|
SeriesId = seriesId;
|
|
|
|
|
SeasonIndex = seasonIndex;
|
|
|
|
|
EpisodeNumber = episodeNumber;
|
|
|
|
|
EpisodeNumberEnd = episodeNumberEnd;
|
|
|
|
|
}
|
2015-09-19 22:56:59 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return string.Format("{0}:{1}:{2}",
|
|
|
|
|
SeriesId,
|
|
|
|
|
SeasonIndex != null ? SeasonIndex.Value.ToString() : "A",
|
|
|
|
|
EpisodeNumber + (EpisodeNumberEnd != null ? "-" + EpisodeNumberEnd.Value.ToString() : ""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Identity? ParseIdentity(string id)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(id))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var parts = id.Split(':');
|
|
|
|
|
var series = parts[0];
|
|
|
|
|
var season = parts[1] != "A" ? (int?)int.Parse(parts[1]) : null;
|
|
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
int? indexEnd;
|
|
|
|
|
|
|
|
|
|
if (parts[2].Contains("-")) {
|
|
|
|
|
var split = parts[2].IndexOf("-", StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
index = int.Parse(parts[2].Substring(0, split));
|
|
|
|
|
indexEnd = int.Parse(parts[2].Substring(split + 1));
|
|
|
|
|
} else {
|
|
|
|
|
index = int.Parse(parts[2]);
|
|
|
|
|
indexEnd = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Identity(series, season, index, indexEnd);
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-19 21:25:19 +00:00
|
|
|
|
}
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|