mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-25 02:30:20 +02:00
Fixed rss datetime bug
This commit is contained in:
parent
e6fb02fac6
commit
a8815cd5ea
3
.gitignore
vendored
3
.gitignore
vendored
@ -32,4 +32,5 @@ _ReSharper*/
|
|||||||
/[Pp]ackage/
|
/[Pp]ackage/
|
||||||
#NZBDrone specific
|
#NZBDrone specific
|
||||||
*.db
|
*.db
|
||||||
*Web.Publish.xml
|
*Web.Publish.xml
|
||||||
|
NzbDrone.Web/NzbDrone.Web.Publish.xml
|
@ -28,11 +28,9 @@ public void parse_feed_xml(string fileName)
|
|||||||
{
|
{
|
||||||
var mocker = new AutoMoqer();
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
var xmlReader = XmlReader.Create(File.OpenRead(".\\Files\\Rss\\" + fileName));
|
|
||||||
|
|
||||||
mocker.GetMock<HttpProvider>()
|
mocker.GetMock<HttpProvider>()
|
||||||
.Setup(h => h.DownloadXml(It.IsAny<String>()))
|
.Setup(h => h.DownloadStream(It.IsAny<String>()))
|
||||||
.Returns(xmlReader);
|
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
|
||||||
|
|
||||||
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
|
||||||
mocker.GetMock<IndexerProvider>()
|
mocker.GetMock<IndexerProvider>()
|
||||||
|
@ -25,8 +25,6 @@ protected override void Write(LogEventInfo logEvent)
|
|||||||
log.Method = logEvent.UserStackFrame.GetMethod().Name;
|
log.Method = logEvent.UserStackFrame.GetMethod().Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
log.Logger = logEvent.LoggerName;
|
log.Logger = logEvent.LoggerName;
|
||||||
|
|
||||||
if (logEvent.Exception != null)
|
if (logEvent.Exception != null)
|
||||||
|
@ -166,6 +166,7 @@
|
|||||||
<Compile Include="Instrumentation\SubsonicTarget.cs" />
|
<Compile Include="Instrumentation\SubsonicTarget.cs" />
|
||||||
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />
|
<Compile Include="Instrumentation\ExceptioneerTarget.cs" />
|
||||||
<Compile Include="Instrumentation\NlogWriter.cs" />
|
<Compile Include="Instrumentation\NlogWriter.cs" />
|
||||||
|
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs" />
|
||||||
<Compile Include="Providers\Indexer\NzbMatrixProvider.cs" />
|
<Compile Include="Providers\Indexer\NzbMatrixProvider.cs" />
|
||||||
<Compile Include="Providers\Jobs\NewSeriesUpdate.cs" />
|
<Compile Include="Providers\Jobs\NewSeriesUpdate.cs" />
|
||||||
<Compile Include="Providers\Jobs\JobProvider.cs" />
|
<Compile Include="Providers\Jobs\JobProvider.cs" />
|
||||||
|
@ -1,80 +1,54 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Xml;
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers.Core
|
namespace NzbDrone.Core.Providers.Core
|
||||||
{
|
{
|
||||||
public class HttpProvider
|
public class HttpProvider
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public virtual string DownloadString(string request)
|
public virtual string DownloadString(string address)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new WebClient().DownloadString(request);
|
return new WebClient().DownloadString(address);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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.TraceException(ex.Message, ex);
|
Logger.TraceException(ex.Message, ex);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void DownloadFile(string request, string filename, string username, string password)
|
public virtual string DownloadString(string address, string username, string password)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var webClient = new WebClient();
|
var webClient = new WebClient();
|
||||||
webClient.Credentials = new NetworkCredential(username, password);
|
webClient.Credentials = new NetworkCredential(username, password);
|
||||||
webClient.DownloadFile(request, filename);
|
return webClient.DownloadString(address);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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);
|
Logger.TraceException(ex.Message, ex);
|
||||||
throw;
|
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 @@ public List<Exception> Fetch()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.Trace("Downloading RSS " + url);
|
_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)
|
foreach (var item in feed)
|
||||||
{
|
{
|
||||||
@ -135,17 +137,17 @@ internal void ProcessItem(SyndicationItem feedItem)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sabTitle = _sabProvider.GetSabTitle(parseResult);
|
//var sabTitle = _sabProvider.GetSabTitle(parseResult);
|
||||||
|
|
||||||
if (_sabProvider.IsInQueue(sabTitle))
|
//if (_sabProvider.IsInQueue(sabTitle))
|
||||||
{
|
//{
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle))
|
//if (!_sabProvider.AddByUrl(NzbDownloadUrl(feedItem), sabTitle))
|
||||||
{
|
//{
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
foreach (var episode in episodes)
|
foreach (var episode in episodes)
|
||||||
{
|
{
|
||||||
|
67
NzbDrone.Core/Providers/Indexer/SyndicationFeedXmlReader.cs
Normal file
67
NzbDrone.Core/Providers/Indexer/SyndicationFeedXmlReader.cs
Normal file
@ -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
Block a user