1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-03-10 06:03:09 +00:00

Added torrent downloading proxy

This commit is contained in:
zone117x 2015-04-16 21:53:52 -06:00
parent 907d556082
commit f5329d2400
6 changed files with 51 additions and 4 deletions

View file

@ -33,5 +33,7 @@ namespace Jackett
void LoadFromSavedConfiguration(JToken jsonConfig);
Task<ReleaseInfo[]> PerformQuery(TorznabQuery query);
Task<byte[]> Download(Uri link);
}
}

View file

@ -195,5 +195,10 @@ namespace Jackett
return releases.ToArray();
});
}
public Task<byte[]> Download(Uri link)
{
return client.GetByteArrayAsync(link);
}
}
}

View file

@ -135,5 +135,10 @@ namespace Jackett
return releases.ToArray();
});
}
public Task<byte[]> Download(Uri link)
{
throw new NotImplementedException();
}
}
}

View file

@ -131,5 +131,10 @@ namespace Jackett.Indexers
return releases.ToArray();
});
}
public Task<byte[]> Download(Uri link)
{
throw new NotImplementedException();
}
}
}

View file

@ -204,5 +204,11 @@ namespace Jackett.Indexers
return releases.ToArray();
});
}
public Task<byte[]> Download(Uri link)
{
throw new NotImplementedException();
}
}
}

View file

@ -84,8 +84,18 @@ namespace Jackett
var reader = new StreamReader(inputStream, context.Request.ContentEncoding);
var bytes = await reader.ReadToEndAsync();
var indexerId = context.Request.Url.AbsolutePath.Replace("/api", "").TrimStart('/').ToLower();
var indexerId = context.Request.Url.Segments[2].TrimEnd('/').ToLower();
var indexer = indexerManager.GetIndexer(indexerId);
if (context.Request.Url.Segments.Length > 4 && context.Request.Url.Segments[3] == "download/")
{
var downloadLink = Encoding.UTF8.GetString(Convert.FromBase64String((context.Request.Url.Segments[4].TrimEnd('/'))));
var downloadBytes = await indexer.Download(new Uri(downloadLink));
await context.Response.OutputStream.WriteAsync(downloadBytes, 0, downloadBytes.Length);
context.Response.Close();
return;
}
var torznabQuery = TorznabQuery.FromHttpQuery(query);
var severUrl = string.Format("{0}://{1}:{2}/", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port);
@ -101,6 +111,16 @@ namespace Jackett
});
var releases = await indexer.PerformQuery(torznabQuery);
// add Jackett proxy to download links...
foreach (var release in releases)
{
var originalLink = release.Link;
var encodedLink = Convert.ToBase64String(Encoding.UTF8.GetBytes(originalLink.ToString())) + "/download.torrent";
var proxyLink = string.Format("{0}api/{1}/download/{2}", severUrl, indexerId, encodedLink);
release.Link = new Uri(proxyLink);
}
resultPage.Releases.AddRange(releases);
var xml = resultPage.ToXml(new Uri(severUrl));
@ -118,9 +138,13 @@ namespace Jackett
exception = ex;
}
var errorBytes = Encoding.UTF8.GetBytes(exception.Message);
await context.Response.OutputStream.WriteAsync(errorBytes, 0, errorBytes.Length);
context.Response.Close();
try
{
var errorBytes = Encoding.UTF8.GetBytes(exception.Message);
await context.Response.OutputStream.WriteAsync(errorBytes, 0, errorBytes.Length);
context.Response.Close();
}
catch (Exception ex) { }
}