mirror of https://github.com/Jackett/Jackett
improve BEncode error handling
This commit is contained in:
parent
ec4afda184
commit
3468e7d404
|
@ -34,6 +34,9 @@ namespace Jackett.Common.Indexers
|
|||
public string Type { get; protected set; }
|
||||
public virtual string ID { get { return GetIndexerID(GetType()); } }
|
||||
|
||||
[JsonConverter(typeof(EncodingJsonConverter))]
|
||||
public Encoding Encoding { get; protected set; }
|
||||
|
||||
public virtual bool IsConfigured { get; protected set; }
|
||||
protected Logger logger;
|
||||
protected IIndexerConfigurationService configurationService;
|
||||
|
@ -835,8 +838,6 @@ namespace Jackett.Common.Indexers
|
|||
|
||||
public override TorznabCapabilities TorznabCaps { get; protected set; }
|
||||
|
||||
[JsonConverter(typeof(EncodingJsonConverter))]
|
||||
public Encoding Encoding { get; protected set; }
|
||||
|
||||
private List<CategoryMapping> categoryMapping = new List<CategoryMapping>();
|
||||
protected WebClient webclient;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Jackett.Common.Models;
|
||||
using Jackett.Common.Models.IndexerConfig;
|
||||
|
@ -30,6 +31,7 @@ namespace Jackett.Common.Indexers
|
|||
string Language { get; }
|
||||
string LastError { get; set; }
|
||||
string ID { get; }
|
||||
Encoding Encoding { get; }
|
||||
|
||||
TorznabCapabilities TorznabCaps { get; }
|
||||
|
||||
|
|
|
@ -71,9 +71,19 @@ namespace Jackett.Controllers
|
|||
}
|
||||
|
||||
// This will fix torrents where the keys are not sorted, and thereby not supported by Sonarr.
|
||||
var parser = new BencodeParser();
|
||||
var torrentDictionary = parser.Parse(downloadBytes);
|
||||
byte[] sortedDownloadBytes = torrentDictionary.EncodeAsBytes();
|
||||
byte[] sortedDownloadBytes = null;
|
||||
try
|
||||
{
|
||||
var parser = new BencodeParser();
|
||||
var torrentDictionary = parser.Parse(downloadBytes);
|
||||
sortedDownloadBytes = torrentDictionary.EncodeAsBytes();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var content = indexer.Encoding.GetString(downloadBytes);
|
||||
logger.Error(content);
|
||||
throw new Exception("BencodeParser failed", e);
|
||||
}
|
||||
|
||||
var result = new HttpResponseMessage(HttpStatusCode.OK);
|
||||
result.Content = new ByteArrayContent(sortedDownloadBytes);
|
||||
|
|
Loading…
Reference in New Issue