diff --git a/src/Jackett/Controllers/DownloadController.cs b/src/Jackett/Controllers/DownloadController.cs
index 9841843a4..e3cdc9686 100644
--- a/src/Jackett/Controllers/DownloadController.cs
+++ b/src/Jackett/Controllers/DownloadController.cs
@@ -10,6 +10,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
+using MonoTorrent.BEncoding;
namespace Jackett.Controllers
{
@@ -51,6 +52,10 @@ namespace Jackett.Controllers
var downloadBytes = await indexer.Download(target);
+ // This will fix torrents where the keys are not sorted, and thereby not supported by Sonarr.
+ var torrentDictionary = BEncodedDictionary.DecodeTorrent(downloadBytes);
+ downloadBytes = torrentDictionary.Encode();
+
var result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(downloadBytes);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-bittorrent");
diff --git a/src/Jackett/Jackett.csproj b/src/Jackett/Jackett.csproj
index b62444f8f..bc5a8c01c 100644
--- a/src/Jackett/Jackett.csproj
+++ b/src/Jackett/Jackett.csproj
@@ -110,6 +110,10 @@
..\packages\Microsoft.Owin.StaticFiles.3.0.1\lib\net45\Microsoft.Owin.StaticFiles.dll
True
+
+ ..\packages\MonoTorrent.0.9.0\lib\net20\MonoTorrent.dll
+ True
+
..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
True
diff --git a/src/Jackett/packages.config b/src/Jackett/packages.config
index b602742aa..427976d0d 100644
--- a/src/Jackett/packages.config
+++ b/src/Jackett/packages.config
@@ -22,6 +22,7 @@
+