mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 01:37:07 +00:00
Fixed an issue where publish date could not be parsed for rss items.
This commit is contained in:
parent
7e7835f3f7
commit
e0f901dbe7
1 changed files with 27 additions and 25 deletions
|
@ -9,59 +9,61 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers.Indexer
|
namespace NzbDrone.Core.Providers.Indexer
|
||||||
{
|
{
|
||||||
|
|
||||||
public class SyndicationFeedXmlReader : XmlTextReader
|
public class SyndicationFeedXmlReader : XmlTextReader
|
||||||
{
|
{
|
||||||
readonly string[] Rss20DateTimeHints = { "pubDate" };
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
readonly string[] Atom10DateTimeHints = { "updated", "published", "lastBuildDate" };
|
|
||||||
private bool isRss2DateTime = false;
|
private static readonly string[] rss20DateTimeHints = { "pubDate" };
|
||||||
private bool isAtomDateTime = false;
|
private static readonly string[] atom10DateTimeHints = { "updated", "published", "lastBuildDate" };
|
||||||
|
private bool _isRss2DateTime;
|
||||||
|
private bool _isAtomDateTime;
|
||||||
|
|
||||||
|
private static readonly MethodInfo rss20FeedFormatterMethodInfo = typeof(Rss20FeedFormatter).GetMethod("DateFromString", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
private static readonly MethodInfo atom10FeedFormatterMethodInfo = typeof(Atom10FeedFormatter).GetMethod("DateFromString", BindingFlags.NonPublic | BindingFlags.Static);
|
||||||
|
|
||||||
public SyndicationFeedXmlReader(Stream stream) : base(stream) { }
|
public SyndicationFeedXmlReader(Stream stream) : base(stream) { }
|
||||||
|
|
||||||
public override bool IsStartElement(string localname, string ns)
|
public override bool IsStartElement(string localname, string ns)
|
||||||
{
|
{
|
||||||
isRss2DateTime = false;
|
_isRss2DateTime = rss20DateTimeHints.Contains(localname);
|
||||||
isAtomDateTime = false;
|
_isAtomDateTime = atom10DateTimeHints.Contains(localname);
|
||||||
|
|
||||||
if (Rss20DateTimeHints.Contains(localname)) isRss2DateTime = true;
|
|
||||||
if (Atom10DateTimeHints.Contains(localname)) isAtomDateTime = true;
|
|
||||||
|
|
||||||
return base.IsStartElement(localname, ns);
|
return base.IsStartElement(localname, ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ReadString()
|
public override string ReadString()
|
||||||
{
|
{
|
||||||
string dateVal = base.ReadString();
|
var dateVal = base.ReadString();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (isRss2DateTime)
|
if (_isRss2DateTime)
|
||||||
{
|
{
|
||||||
MethodInfo objMethod = typeof(Rss20FeedFormatter).GetMethod("DateFromString", BindingFlags.NonPublic | BindingFlags.Static);
|
rss20FeedFormatterMethodInfo.Invoke(null, new object[] { dateVal, this });
|
||||||
Debug.Assert(objMethod != null);
|
}
|
||||||
objMethod.Invoke(null, new object[] { dateVal, this });
|
if (_isAtomDateTime)
|
||||||
|
{
|
||||||
|
atom10FeedFormatterMethodInfo.Invoke(new Atom10FeedFormatter(), new object[] { dateVal, this });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (TargetInvocationException e)
|
||||||
|
{
|
||||||
|
DateTime parsedDate;
|
||||||
|
|
||||||
}
|
if (!DateTime.TryParse(dateVal, new CultureInfo("en-US"), DateTimeStyles.None, out parsedDate))
|
||||||
if (isAtomDateTime)
|
|
||||||
{
|
{
|
||||||
MethodInfo objMethod = typeof(Atom10FeedFormatter).GetMethod("DateFromString", BindingFlags.NonPublic | BindingFlags.Instance);
|
parsedDate = DateTime.UtcNow;
|
||||||
Debug.Assert(objMethod != null);
|
logger.WarnException("Unable to parse Feed date " + dateVal, e);
|
||||||
objMethod.Invoke(new Atom10FeedFormatter(), new object[] { dateVal, this });
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (TargetInvocationException)
|
dateVal = parsedDate.ToString(CultureInfo.CurrentCulture.DateTimeFormat.RFC1123Pattern);
|
||||||
{
|
|
||||||
DateTimeFormatInfo dtfi = CultureInfo.CurrentCulture.DateTimeFormat;
|
|
||||||
return DateTimeOffset.UtcNow.ToString(dtfi.RFC1123Pattern);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return dateVal;
|
return dateVal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue