jellyfin-server/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs

919 lines
36 KiB
C#
Raw Normal View History

2013-02-21 01:33:05 +00:00
using System;
using System.Collections.Generic;
using System.Globalization;
2013-02-21 01:33:05 +00:00
using System.IO;
using System.Linq;
using System.Text;
2013-02-21 01:33:05 +00:00
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
2016-10-25 19:02:04 +00:00
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
2016-10-27 07:58:33 +00:00
using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
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>
2016-05-26 17:18:58 +00:00
class TvdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>
2013-02-21 01:33:05 +00:00
{
2015-09-19 21:25:19 +00:00
private static readonly string FullIdKey = MetadataProviders.Tvdb + "-Full";
internal static TvdbEpisodeProvider Current;
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;
2016-10-27 07:58:33 +00:00
private readonly IXmlReaderSettingsFactory _xmlSettings;
2016-10-27 07:58:33 +00:00
public TvdbEpisodeProvider(IFileSystem fileSystem, IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IXmlReaderSettingsFactory xmlSettings)
2013-02-25 00:13:45 +00:00
{
_fileSystem = fileSystem;
_config = config;
2015-01-27 06:50:40 +00:00
_httpClient = httpClient;
2015-05-07 03:11:51 +00:00
_logger = logger;
2016-10-27 07:58:33 +00:00
_xmlSettings = xmlSettings;
Current = this;
2013-02-25 00:13:45 +00:00
}
2013-02-21 01:33:05 +00:00
2017-05-26 06:48:54 +00:00
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
{
var list = new List<RemoteSearchResult>();
2016-10-27 07:58:33 +00:00
// The search query must either provide an episode number or date
if (!searchInfo.IndexNumber.HasValue && !searchInfo.PremiereDate.HasValue)
{
2017-05-26 06:48:54 +00:00
return Task.FromResult((IEnumerable<RemoteSearchResult>)list);
2016-10-27 07:58:33 +00:00
}
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds))
{
2015-11-24 18:45:52 +00:00
var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, searchInfo.SeriesProviderIds);
2014-03-05 02:59:59 +00:00
try
{
2018-09-12 17:26:21 +00:00
var metadataResult = FetchEpisodeData(searchInfo, seriesDataPath, cancellationToken);
2015-06-29 01:10:45 +00:00
if (metadataResult.HasMetadata)
{
2015-06-29 01:10:45 +00:00
var item = metadataResult.Item;
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.
}
2016-10-27 07:58:33 +00:00
catch (IOException)
2014-12-23 03:58:14 +00:00
{
// Don't fail the provider because this will just keep on going and going.
}
}
2017-05-26 06:48:54 +00:00
return Task.FromResult((IEnumerable<RemoteSearchResult>)list);
}
public string Name => "TheTVDB";
2013-02-21 01:33:05 +00:00
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo searchInfo, CancellationToken cancellationToken)
{
var result = new MetadataResult<Episode>();
result.QueriedById = true;
2013-02-21 01:33:05 +00:00
2016-10-27 07:58:33 +00:00
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds) &&
(searchInfo.IndexNumber.HasValue || searchInfo.PremiereDate.HasValue))
2015-11-24 18:45:52 +00:00
{
2018-09-12 17:26:21 +00:00
var seriesDataPath = await TvdbSeriesProvider.Current.EnsureSeriesInfo(searchInfo.SeriesProviderIds, null, null, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
2015-11-24 18:45:52 +00:00
2018-09-12 17:26:21 +00:00
if (string.IsNullOrEmpty(seriesDataPath))
2016-10-27 07:58:33 +00:00
{
2018-09-12 17:26:21 +00:00
return result;
2016-10-27 07:58:33 +00:00
}
try
2013-10-25 16:14:32 +00:00
{
2018-09-12 17:26:21 +00:00
result = FetchEpisodeData(searchInfo, seriesDataPath, cancellationToken);
}
catch (FileNotFoundException)
{
// Don't fail the provider because this will just keep on going and going.
2013-10-25 16:14:32 +00:00
}
2016-10-27 07:58:33 +00:00
catch (IOException)
2014-12-23 03:58:14 +00:00
{
// 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.LogDebug("No series identity found for {0}", searchInfo.Name);
2015-05-07 03:11:51 +00:00
}
2013-02-21 01:33:05 +00:00
return result;
2013-02-21 01:33:05 +00:00
}
/// <summary>
/// Gets the episode XML files.
/// </summary>
/// <param name="seriesDataPath">The series data path.</param>
2016-01-25 04:12:47 +00:00
/// <param name="searchInfo">The search information.</param>
/// <returns>List{FileInfo}.</returns>
2019-01-07 23:24:34 +00:00
internal List<XmlReader> GetEpisodeXmlNodes(string seriesDataPath, EpisodeInfo searchInfo)
{
2016-10-27 07:58:33 +00:00
var seriesXmlPath = TvdbSeriesProvider.Current.GetSeriesXmlPath(searchInfo.SeriesProviderIds, searchInfo.MetadataLanguage);
try
{
return GetXmlNodes(seriesXmlPath, searchInfo);
}
catch (FileNotFoundException)
{
return new List<XmlReader>();
}
catch (IOException)
{
return new List<XmlReader>();
}
}
2013-02-21 01:33:05 +00:00
/// <summary>
/// Fetches the episode data.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="seriesDataPath">The series data path.</param>
/// <param name="cancellationToken">The cancellation token.</param>
2013-02-21 01:33:05 +00:00
/// <returns>Task{System.Boolean}.</returns>
2018-09-12 17:26:21 +00:00
private MetadataResult<Episode> FetchEpisodeData(EpisodeInfo id, string seriesDataPath, CancellationToken cancellationToken)
2013-02-21 01:33:05 +00:00
{
2016-10-27 07:58:33 +00:00
var result = new MetadataResult<Episode>()
{
Item = new Episode
{
IndexNumber = id.IndexNumber,
ParentIndexNumber = id.ParentIndexNumber,
IndexNumberEnd = id.IndexNumberEnd
}
};
2016-10-27 07:58:33 +00:00
var xmlNodes = GetEpisodeXmlNodes(seriesDataPath, id);
2016-10-27 07:58:33 +00:00
if (xmlNodes.Count > 0)
{
2018-09-12 17:26:21 +00:00
FetchMainEpisodeInfo(result, xmlNodes[0], id.SeriesDisplayOrder, cancellationToken);
2013-02-21 01:33:05 +00:00
2016-10-27 07:58:33 +00:00
result.HasMetadata = true;
}
2016-10-27 07:58:33 +00:00
foreach (var node in xmlNodes.Skip(1))
{
FetchAdditionalPartInfo(result, node, cancellationToken);
}
2015-06-29 01:10:45 +00:00
return result;
}
2016-10-27 07:58:33 +00:00
private List<XmlReader> GetXmlNodes(string xmlFile, EpisodeInfo searchInfo)
{
var list = new List<XmlReader>();
2016-10-27 07:58:33 +00:00
if (searchInfo.IndexNumber.HasValue)
{
2018-09-12 17:26:21 +00:00
var files = GetEpisodeXmlFiles(searchInfo.SeriesDisplayOrder, searchInfo.ParentIndexNumber, searchInfo.IndexNumber, searchInfo.IndexNumberEnd, _fileSystem.GetDirectoryName(xmlFile));
2016-10-27 07:58:33 +00:00
list = files.Select(GetXmlReader).ToList();
}
2016-10-27 07:58:33 +00:00
if (list.Count == 0 && searchInfo.PremiereDate.HasValue)
{
list = GetXmlNodesByPremiereDate(xmlFile, searchInfo.PremiereDate.Value);
}
2016-10-27 07:58:33 +00:00
return list;
}
2018-09-12 17:26:21 +00:00
private string GetEpisodeFileName(string seriesDisplayOrder, int? seasonNumber, int? episodeNumber)
{
if (string.Equals(seriesDisplayOrder, "absolute", StringComparison.OrdinalIgnoreCase))
{
return string.Format("episode-abs-{0}.xml", episodeNumber);
}
else if (string.Equals(seriesDisplayOrder, "dvd", StringComparison.OrdinalIgnoreCase))
{
return string.Format("episode-dvd-{0}-{1}.xml", seasonNumber.Value, episodeNumber);
}
else
{
return string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber);
}
}
private FileSystemMetadata GetEpisodeFileInfoWithFallback(string seriesDataPath, string seriesDisplayOrder, int? seasonNumber, int? episodeNumber)
{
var file = Path.Combine(seriesDataPath, GetEpisodeFileName(seriesDisplayOrder, seasonNumber, episodeNumber));
var fileInfo = _fileSystem.GetFileInfo(file);
if (fileInfo.Exists)
{
return fileInfo;
}
if (!seasonNumber.HasValue)
{
return fileInfo;
}
// revert to aired order
if (string.Equals(seriesDisplayOrder, "absolute", StringComparison.OrdinalIgnoreCase) || string.Equals(seriesDisplayOrder, "dvd", StringComparison.OrdinalIgnoreCase))
{
file = Path.Combine(seriesDataPath, GetEpisodeFileName(null, seasonNumber, episodeNumber));
return _fileSystem.GetFileInfo(file);
}
return fileInfo;
}
private List<FileSystemMetadata> GetEpisodeXmlFiles(string seriesDisplayOrder, int? seasonNumber, int? episodeNumber, int? endingEpisodeNumber, string seriesDataPath)
2016-10-27 07:58:33 +00:00
{
var files = new List<FileSystemMetadata>();
2016-10-27 07:58:33 +00:00
if (episodeNumber == null)
{
return files;
}
2018-09-12 17:26:21 +00:00
if (!seasonNumber.HasValue)
{
2018-09-12 17:26:21 +00:00
seriesDisplayOrder = "absolute";
}
2018-09-12 17:26:21 +00:00
var fileInfo = GetEpisodeFileInfoWithFallback(seriesDataPath, seriesDisplayOrder, seasonNumber, episodeNumber);
if (fileInfo.Exists)
{
2018-09-12 17:26:21 +00:00
files.Add(fileInfo);
}
2016-10-27 07:58:33 +00:00
var end = endingEpisodeNumber ?? episodeNumber;
episodeNumber++;
2016-10-27 07:58:33 +00:00
while (episodeNumber <= end)
{
2018-09-12 17:26:21 +00:00
fileInfo = GetEpisodeFileInfoWithFallback(seriesDataPath, seriesDisplayOrder, seasonNumber, episodeNumber);
2016-10-27 07:58:33 +00:00
if (fileInfo.Exists)
{
files.Add(fileInfo);
}
else
{
break;
}
episodeNumber++;
}
return files;
}
private XmlReader GetXmlReader(FileSystemMetadata xmlFile)
{
return GetXmlReader(_fileSystem.ReadAllText(xmlFile.FullName, Encoding.UTF8));
}
private XmlReader GetXmlReader(string xml)
2016-10-27 07:58:33 +00:00
{
var streamReader = new StringReader(xml);
var settings = _xmlSettings.Create(false);
settings.CheckCharacters = false;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreComments = true;
return XmlReader.Create(streamReader, settings);
}
private List<XmlReader> GetXmlNodesByPremiereDate(string xmlFile, DateTime premiereDate)
{
var list = new List<XmlReader>();
using (var fileStream = _fileSystem.GetFileStream(xmlFile, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
{
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
// Use XmlReader for best performance
var settings = _xmlSettings.Create(false);
settings.CheckCharacters = false;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreComments = true;
using (var reader = XmlReader.Create(streamReader, settings))
{
reader.MoveToContent();
2016-12-02 20:10:35 +00:00
reader.Read();
2016-10-27 07:58:33 +00:00
// Loop through each element
2016-12-03 21:46:06 +00:00
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2016-10-27 07:58:33 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "Episode":
{
var outerXml = reader.ReadOuterXml();
var airDate = GetEpisodeAirDate(outerXml);
if (airDate.HasValue && premiereDate.Date == airDate.Value.Date)
{
list.Add(GetXmlReader(outerXml));
return list;
}
break;
}
default:
reader.Skip();
break;
}
}
2016-12-02 20:10:35 +00:00
else
{
reader.Read();
}
2016-10-27 07:58:33 +00:00
}
}
}
}
return list;
}
private DateTime? GetEpisodeAirDate(string xml)
{
using (var streamReader = new StringReader(xml))
{
var settings = _xmlSettings.Create(false);
settings.CheckCharacters = false;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreComments = true;
// Use XmlReader for best performance
using (var reader = XmlReader.Create(streamReader, settings))
{
reader.MoveToContent();
2016-12-02 20:10:35 +00:00
reader.Read();
2016-10-27 07:58:33 +00:00
// Loop through each element
2016-12-03 21:46:06 +00:00
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2016-10-27 07:58:33 +00:00
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "FirstAired":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
DateTime date;
if (DateTime.TryParse(val, out date))
{
date = date.ToUniversalTime();
return date;
}
}
break;
}
default:
reader.Skip();
break;
}
}
2016-12-02 20:10:35 +00:00
else
{
reader.Read();
}
2016-10-27 07:58:33 +00:00
}
}
}
return null;
}
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
2018-09-12 17:26:21 +00:00
private void FetchMainEpisodeInfo(MetadataResult<Episode> result, XmlReader reader, string seriesOrder, CancellationToken cancellationToken)
{
2015-06-29 01:10:45 +00:00
var item = result.Item;
2018-09-12 17:26:21 +00:00
int? episodeNumber = null;
int? seasonNumber = null;
int? combinedEpisodeNumber = null;
int? combinedSeasonNumber = null;
2016-10-27 07:58:33 +00:00
// Use XmlReader for best performance
using (reader)
{
result.ResetPeople();
2016-12-02 20:10:35 +00:00
reader.MoveToContent();
reader.Read();
2016-10-27 07:58:33 +00:00
// Loop through each element
2016-12-03 21:46:06 +00:00
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2016-10-27 07:58:33 +00:00
{
cancellationToken.ThrowIfCancellationRequested();
2016-10-27 07:58:33 +00:00
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "id":
{
2016-10-27 07:58:33 +00:00
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
item.SetProviderId(MetadataProviders.Tvdb, val);
}
break;
}
2016-10-27 07:58:33 +00:00
case "IMDB_ID":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
2016-10-27 07:58:33 +00:00
item.SetProviderId(MetadataProviders.Imdb, val);
}
2016-10-27 07:58:33 +00:00
break;
}
2018-09-12 17:26:21 +00:00
case "EpisodeNumber":
2016-10-27 07:58:33 +00:00
{
var val = reader.ReadElementContentAsString();
2016-10-27 07:58:33 +00:00
if (!string.IsNullOrWhiteSpace(val))
{
2018-09-12 17:26:21 +00:00
int rval;
2016-10-27 07:58:33 +00:00
2018-09-12 17:26:21 +00:00
// int.TryParse is local aware, so it can be probamatic, force us culture
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
2016-10-27 07:58:33 +00:00
{
2018-09-12 17:26:21 +00:00
episodeNumber = rval;
2016-10-27 07:58:33 +00:00
}
}
break;
}
2018-09-12 17:26:21 +00:00
case "SeasonNumber":
2016-10-27 07:58:33 +00:00
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
2018-09-12 17:26:21 +00:00
int rval;
2016-10-27 07:58:33 +00:00
2018-09-12 17:26:21 +00:00
// int.TryParse is local aware, so it can be probamatic, force us culture
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
2016-10-27 07:58:33 +00:00
{
2018-09-12 17:26:21 +00:00
seasonNumber = rval;
2016-10-27 07:58:33 +00:00
}
}
break;
}
2018-09-12 17:26:21 +00:00
case "Combined_episodenumber":
2016-10-27 07:58:33 +00:00
{
2016-12-02 20:10:35 +00:00
var val = reader.ReadElementContentAsString();
2018-09-12 17:26:21 +00:00
if (!string.IsNullOrWhiteSpace(val))
2016-10-27 07:58:33 +00:00
{
2018-09-12 17:26:21 +00:00
float num;
2016-12-02 20:10:35 +00:00
2018-09-12 17:26:21 +00:00
if (float.TryParse(val, NumberStyles.Any, _usCulture, out num))
2016-10-27 07:58:33 +00:00
{
2018-09-12 17:26:21 +00:00
combinedEpisodeNumber = Convert.ToInt32(num);
2016-10-27 07:58:33 +00:00
}
}
break;
}
2018-09-12 17:26:21 +00:00
case "Combined_season":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
2018-09-12 17:26:21 +00:00
float num;
2018-09-12 17:26:21 +00:00
if (float.TryParse(val, NumberStyles.Any, _usCulture, out num))
{
2018-09-12 17:26:21 +00:00
combinedSeasonNumber = Convert.ToInt32(num);
}
}
2016-10-27 07:58:33 +00:00
break;
}
2016-10-27 07:58:33 +00:00
case "airsbefore_episode":
{
var val = reader.ReadElementContentAsString();
2016-10-27 07:58:33 +00:00
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;
}
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))
{
2016-10-27 07:58:33 +00:00
item.AirsAfterSeasonNumber = rval;
}
}
2016-10-27 07:58:33 +00:00
break;
}
2016-10-27 07:58:33 +00:00
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))
{
item.AirsBeforeSeasonNumber = rval;
}
}
break;
}
case "EpisodeName":
{
2016-12-02 20:10:35 +00:00
var val = reader.ReadElementContentAsString();
2016-10-27 07:58:33 +00:00
if (!item.LockedFields.Contains(MetadataFields.Name))
{
if (!string.IsNullOrWhiteSpace(val))
{
item.Name = val;
}
}
break;
}
case "Overview":
{
2016-12-02 20:10:35 +00:00
var val = reader.ReadElementContentAsString();
2016-10-27 07:58:33 +00:00
if (!item.LockedFields.Contains(MetadataFields.Overview))
{
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))
{
2017-06-03 07:36:32 +00:00
//item.VoteCount = rval;
2016-10-27 07:58:33 +00:00
}
}
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(result, val, PersonType.Director);
}
}
2016-10-27 07:58:33 +00:00
break;
}
case "GuestStars":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
if (!item.LockedFields.Contains(MetadataFields.Cast))
{
AddGuestStars(result, val);
}
}
break;
}
case "Writer":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
if (!item.LockedFields.Contains(MetadataFields.Cast))
{
2017-02-10 20:06:52 +00:00
//AddPeople(result, val, PersonType.Writer);
2016-10-27 07:58:33 +00:00
}
}
break;
}
case "Language":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
result.ResultLanguage = val;
}
break;
}
default:
reader.Skip();
break;
}
}
2016-12-02 20:10:35 +00:00
else
{
reader.Read();
}
2016-10-27 07:58:33 +00:00
}
}
2018-09-12 17:26:21 +00:00
if (string.Equals(seriesOrder, "dvd", StringComparison.OrdinalIgnoreCase))
{
episodeNumber = combinedEpisodeNumber ?? episodeNumber;
seasonNumber = combinedSeasonNumber ?? seasonNumber;
}
if (episodeNumber.HasValue)
{
item.IndexNumber = episodeNumber;
}
if (seasonNumber.HasValue)
{
item.ParentIndexNumber = seasonNumber;
}
}
2015-06-29 01:10:45 +00:00
private void AddPeople<T>(MetadataResult<T> result, string val, string personType)
{
// Sometimes tvdb actors have leading spaces
2016-05-11 02:20:49 +00:00
foreach (var person in val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
.Where(i => !string.IsNullOrWhiteSpace(i))
.Select(str => new PersonInfo { Type = personType, Name = str.Trim() }))
{
2015-07-24 02:48:10 +00:00
result.AddPerson(person);
}
}
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
{
2018-09-12 17:26:21 +00:00
// example:
// <GuestStars>|Mark C. Thomas| Dennis Kiefer| David Nelson (David)| Angela Nicholas| Tzi Ma| Kevin P. Kearns (Pasco)|</GuestStars>
var persons = val.Split('|')
.Select(i => i.Trim())
.Where(i => !string.IsNullOrWhiteSpace(i))
.ToList();
foreach (var person in persons)
{
2018-09-12 17:26:21 +00:00
var index = person.IndexOf('(');
string role = null;
var name = person;
if (index != -1)
{
2018-09-12 17:26:21 +00:00
role = person.Substring(index + 1).Trim().TrimEnd(')');
name = person.Substring(0, index).Trim();
}
2018-09-12 17:26:21 +00:00
result.AddPerson(new PersonInfo
{
Type = PersonType.GuestStar,
Name = name,
Role = role
});
2013-10-05 16:16:19 +00:00
}
}
2013-10-05 16:16:19 +00:00
2016-10-27 07:58:33 +00:00
private void FetchAdditionalPartInfo(MetadataResult<Episode> result, XmlReader reader, CancellationToken cancellationToken)
{
2015-06-29 01:10:45 +00:00
var item = result.Item;
2016-10-27 07:58:33 +00:00
// Use XmlReader for best performance
using (reader)
{
reader.MoveToContent();
2016-12-02 20:10:35 +00:00
reader.Read();
2016-10-27 07:58:33 +00:00
// Loop through each element
2016-12-03 21:46:06 +00:00
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
2016-10-27 07:58:33 +00:00
{
cancellationToken.ThrowIfCancellationRequested();
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "EpisodeName":
{
2016-12-02 20:10:35 +00:00
var val = reader.ReadElementContentAsString();
2016-10-27 07:58:33 +00:00
if (!item.LockedFields.Contains(MetadataFields.Name))
{
if (!string.IsNullOrWhiteSpace(val))
{
item.Name += ", " + val;
}
}
break;
}
case "Overview":
{
2016-12-02 20:10:35 +00:00
var val = reader.ReadElementContentAsString();
2016-10-27 07:58:33 +00:00
if (!item.LockedFields.Contains(MetadataFields.Overview))
{
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(result, val, PersonType.Director);
}
}
break;
}
case "GuestStars":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
if (!item.LockedFields.Contains(MetadataFields.Cast))
{
AddGuestStars(result, val);
}
}
break;
}
case "Writer":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
if (!item.LockedFields.Contains(MetadataFields.Cast))
{
2017-02-10 20:06:52 +00:00
//AddPeople(result, val, PersonType.Writer);
2016-10-27 07:58:33 +00:00
}
}
break;
}
default:
reader.Skip();
break;
}
}
2016-12-02 20:10:35 +00:00
else
{
reader.Read();
}
2016-10-27 07:58:33 +00:00
}
}
2013-02-21 01:33:05 +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,
2017-04-30 02:37:51 +00:00
Url = url
2015-01-27 06:50:40 +00:00
});
}
public int Order => 0;
2013-02-21 01:33:05 +00:00
}
}