mirror of
https://github.com/Radarr/Radarr
synced 2026-05-02 04:42:14 +02:00
fix: address code review findings
- Fix Torznab default definition protocol (Usenet -> Torrent) - Add try-catch around JSON deserialization in MAM parser - Add logging for author info parse failures - Add null check for JSON response
This commit is contained in:
parent
2045f39037
commit
fb6e131d68
3 changed files with 23 additions and 5 deletions
|
|
@ -29,7 +29,7 @@ public override IIndexerRequestGenerator GetRequestGenerator()
|
|||
|
||||
public override IParseIndexerResponse GetParser()
|
||||
{
|
||||
return new MyAnonamouseParser(Settings);
|
||||
return new MyAnonamouseParser(Settings, _logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers.Exceptions;
|
||||
|
|
@ -14,10 +15,12 @@ namespace NzbDrone.Core.Indexers.MyAnonamouse
|
|||
public class MyAnonamouseParser : IParseIndexerResponse
|
||||
{
|
||||
private readonly MyAnonamouseSettings _settings;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public MyAnonamouseParser(MyAnonamouseSettings settings)
|
||||
public MyAnonamouseParser(MyAnonamouseSettings settings, Logger logger = null)
|
||||
{
|
||||
_settings = settings;
|
||||
_logger = logger ?? LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
||||
|
|
@ -36,7 +39,21 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
|||
indexerResponse.HttpResponse.StatusCode);
|
||||
}
|
||||
|
||||
var jsonResponse = JsonConvert.DeserializeObject<MyAnonamouseResponse>(indexerResponse.Content);
|
||||
MyAnonamouseResponse jsonResponse;
|
||||
|
||||
try
|
||||
{
|
||||
jsonResponse = JsonConvert.DeserializeObject<MyAnonamouseResponse>(indexerResponse.Content);
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
throw new IndexerException(indexerResponse, "Failed to parse JSON response from MyAnonamouse: {0}", ex.Message);
|
||||
}
|
||||
|
||||
if (jsonResponse == null)
|
||||
{
|
||||
throw new IndexerException(indexerResponse, "Empty response from MyAnonamouse");
|
||||
}
|
||||
|
||||
if (jsonResponse.Error.IsNotNullOrWhiteSpace() && jsonResponse.Error.StartsWithIgnoreCase("Nothing returned, out of"))
|
||||
{
|
||||
|
|
@ -67,8 +84,9 @@ public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
|||
title += " by " + author;
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (JsonException ex)
|
||||
{
|
||||
_logger.Debug(ex, "Failed to parse author info for torrent {0}", id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ private IndexerDefinition GetDefinition(string name, TorznabSettings settings)
|
|||
Name = name,
|
||||
Implementation = GetType().Name,
|
||||
Settings = settings,
|
||||
Protocol = DownloadProtocol.Usenet,
|
||||
Protocol = DownloadProtocol.Torrent,
|
||||
SupportsRss = SupportsRss,
|
||||
SupportsSearch = SupportsSearch
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue