mirror of https://github.com/Radarr/Radarr
Fixed rss datetime bug
This commit is contained in:
parent
e6fb02fac6
commit
a8815cd5ea
|
@ -33,3 +33,4 @@ _ReSharper*/
|
|||
#NZBDrone specific
|
||||
*.db
|
||||
*Web.Publish.xml
|
||||
NzbDrone.Web/NzbDrone.Web.Publish.xml
|
|
@ -28,11 +28,9 @@ namespace NzbDrone.Core.Test
|
|||
{
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
var xmlReader = XmlReader.Create(File.OpenRead(".\\Files\\Rss\\" + fileName));
|
||||
|
||||
mocker.GetMock<HttpProvider>()
|
||||
.Setup(h => h.DownloadXml(It.IsAny<String>()))
|
||||
.Returns(xmlReader);
|
||||
.Setup(h => h.DownloadStream(It.IsAny<String>()))
|
||||
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
|
||||
|
||||
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
||||
mocker.GetMock<IndexerProvider>()
|
||||
|
|
|
@ -25,8 +25,6 @@ namespace NzbDrone.Core.Instrumentation
|
|||
log.Method = logEvent.UserStackFrame.GetMethod().Name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
log.Logger = logEvent.LoggerName;
|
||||
|
||||
if (logEvent.Exception != null)
|
||||
|
|
|
@ -166,6 +166,7 @@
|
|||
<Compile Include="Instrumentation\SubsonicTarget.cs" />
|
||||
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />
|
||||
<Compile Include="Instrumentation\NlogWriter.cs" />
|
||||
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
|
||||
<Compile Include="Providers\Indexer\NzbMatrixProvider.cs" />
|
||||
<Compile Include="Providers\Jobs\NewSeriesUpdate.cs" />
|
||||
<Compile Include="Providers\Jobs\JobProvider.cs" />
|
||||
|
|
|
@ -1,80 +1,54 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using NLog;
|
||||
|
||||
|
||||
namespace NzbDrone.Core.Providers.Core
|
||||
{
|
||||
public class HttpProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public virtual string DownloadString(string request)
|
||||
public virtual string DownloadString(string address)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new WebClient().DownloadString(request);
|
||||
return new WebClient().DownloadString(address);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Failed to get response from: {0}", request);
|
||||
Logger.TraceException(ex.Message, ex);
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public virtual string DownloadString(string request, string username, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
var webClient = new WebClient();
|
||||
webClient.Credentials = new NetworkCredential(username, password);
|
||||
return webClient.DownloadString(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Failed to get response from: {0}", request);
|
||||
Logger.TraceException(ex.Message, ex);
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public virtual void DownloadFile(string request, string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
var webClient = new WebClient();
|
||||
webClient.DownloadFile(request, filename);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Failed to get response from: {0}", request);
|
||||
Logger.Warn("Failed to get response from: {0}", address);
|
||||
Logger.TraceException(ex.Message, ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DownloadFile(string request, string filename, string username, string password)
|
||||
public virtual string DownloadString(string address, string username, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
var webClient = new WebClient();
|
||||
webClient.Credentials = new NetworkCredential(username, password);
|
||||
webClient.DownloadFile(request, filename);
|
||||
return webClient.DownloadString(address);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Failed to get response from: {0}", request);
|
||||
Logger.Warn("Failed to get response from: {0}", address);
|
||||
Logger.TraceException(ex.Message, ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual XmlReader DownloadXml(string url)
|
||||
public virtual Stream DownloadStream(string url)
|
||||
{
|
||||
return XmlReader.Create(url);
|
||||
var request = WebRequest.Create(url);
|
||||
|
||||
var response = request.GetResponse();
|
||||
|
||||
return response.GetResponseStream();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -69,7 +69,9 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||
try
|
||||
{
|
||||
_logger.Trace("Downloading RSS " + url);
|
||||
var feed = SyndicationFeed.Load(_httpProvider.DownloadXml(url)).Items;
|
||||
|
||||
var reader = new SyndicationFeedXmlReader(_httpProvider.DownloadStream(url));
|
||||
var feed = SyndicationFeed.Load(reader).Items;
|
||||
|
||||
foreach (var item in feed)
|
||||
{
|
||||
|
@ -135,17 +137,17 @@ namespace NzbDrone.Core.Providers.Indexer
|
|||
return;
|
||||
}
|
||||
|
||||
var sabTitle = _sabProvider.GetSabTitle(parseResult);
|
||||
//var sabTitle = _sabProvider.GetSabTitle(parseResult);
|
||||
|
||||
if (_sabProvider.IsInQueue(sabTitle))
|
||||
{
|
||||
return;
|
||||
}
|
||||
//if (_sabProvider.IsInQueue(sabTitle))
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle))
|
||||
{
|
||||
return;
|
||||
}
|
||||
//if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle))
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
foreach (var episode in episodes)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
//http://stackoverflow.com/questions/210375/problems-reading-rss-with-c-and-net-3-5
|
||||
//https://connect.microsoft.com/VisualStudio/feedback/details/325421/syndicationfeed-load-fails-to-parse-datetime-against-a-real-world-feeds-ie7-can-read
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.ServiceModel.Syndication;
|
||||
using System.Xml;
|
||||
|
||||
namespace NzbDrone.Core.Providers.Indexer
|
||||
{
|
||||
|
||||
public class SyndicationFeedXmlReader : XmlTextReader
|
||||
{
|
||||
readonly string[] Rss20DateTimeHints = { "pubDate" };
|
||||
readonly string[] Atom10DateTimeHints = { "updated", "published", "lastBuildDate" };
|
||||
private bool isRss2DateTime = false;
|
||||
private bool isAtomDateTime = false;
|
||||
|
||||
public SyndicationFeedXmlReader(Stream stream) : base(stream) { }
|
||||
|
||||
public override bool IsStartElement(string localname, string ns)
|
||||
{
|
||||
isRss2DateTime = false;
|
||||
isAtomDateTime = false;
|
||||
|
||||
if (Rss20DateTimeHints.Contains(localname)) isRss2DateTime = true;
|
||||
if (Atom10DateTimeHints.Contains(localname)) isAtomDateTime = true;
|
||||
|
||||
return base.IsStartElement(localname, ns);
|
||||
}
|
||||
|
||||
public override string ReadString()
|
||||
{
|
||||
string dateVal = base.ReadString();
|
||||
|
||||
try
|
||||
{
|
||||
if (isRss2DateTime)
|
||||
{
|
||||
MethodInfo objMethod = typeof(Rss20FeedFormatter).GetMethod("DateFromString", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
Debug.Assert(objMethod != null);
|
||||
objMethod.Invoke(null, new object[] { dateVal, this });
|
||||
|
||||
}
|
||||
if (isAtomDateTime)
|
||||
{
|
||||
MethodInfo objMethod = typeof(Atom10FeedFormatter).GetMethod("DateFromString", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
Debug.Assert(objMethod != null);
|
||||
objMethod.Invoke(new Atom10FeedFormatter(), new object[] { dateVal, this });
|
||||
}
|
||||
}
|
||||
catch (TargetInvocationException)
|
||||
{
|
||||
DateTimeFormatInfo dtfi = CultureInfo.CurrentCulture.DateTimeFormat;
|
||||
return DateTimeOffset.UtcNow.ToString(dtfi.RFC1123Pattern);
|
||||
}
|
||||
|
||||
return dateVal;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue