mirror of
https://github.com/Jackett/Jackett
synced 2025-03-10 06:03:09 +00:00
IPTorrents completed
This commit is contained in:
parent
1318039fb3
commit
ec41863630
5 changed files with 220 additions and 142 deletions
|
@ -63,7 +63,7 @@ namespace Jackett
|
|||
|
||||
public string DisplayName { get { return "BitMeTV"; } }
|
||||
public string DisplayDescription { get { return "TV Episode specialty tracker"; } }
|
||||
public Uri SiteLink { get { return new Uri("https://bitmetv.org"); } }
|
||||
public Uri SiteLink { get { return new Uri(BaseUrl); } }
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Jackett
|
|||
|
||||
public string DisplayDescription { get { return "Our goal is to provide the latest stuff in the TV show domain"; } }
|
||||
|
||||
public Uri SiteLink { get { return new Uri("https://freshon.tv/"); } }
|
||||
public Uri SiteLink { get { return new Uri(BaseUrl); } }
|
||||
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
|
@ -169,7 +169,7 @@ namespace Jackett
|
|||
else if (dateString.StartsWith("Yesterday "))
|
||||
pubDate = (DateTime.UtcNow + TimeSpan.Parse(dateString.Split(' ')[1]) - TimeSpan.FromDays(1)).ToLocalTime();
|
||||
else
|
||||
pubDate = DateTime.ParseExact(dateString, "dd-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
||||
pubDate = DateTime.ParseExact(dateString, "d-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();
|
||||
release.PublishDate = pubDate;
|
||||
|
||||
release.Seeders = int.Parse(qRow.Find("td.table_seeders").Text().Trim());
|
||||
|
@ -187,9 +187,12 @@ namespace Jackett
|
|||
return releases.ToArray();
|
||||
}
|
||||
|
||||
public Task<byte[]> Download(Uri link)
|
||||
public async Task<byte[]> Download(Uri link)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var request = CreateHttpRequest(link);
|
||||
var response = await client.SendAsync(request);
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Net;
|
|||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Jackett.Indexers
|
||||
{
|
||||
|
@ -19,13 +20,17 @@ namespace Jackett.Indexers
|
|||
|
||||
public string DisplayDescription { get { return "Always a step ahead"; } }
|
||||
|
||||
public Uri SiteLink { get { return new Uri("https://iptorrents.com"); } }
|
||||
public Uri SiteLink { get { return new Uri(BaseUrl); } }
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
|
||||
static string chromeUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36";
|
||||
|
||||
|
||||
static string BaseUrl = "https://iptorrents.com";
|
||||
|
||||
static string chromeUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36";
|
||||
string SearchUrl = BaseUrl + "/t?q=";
|
||||
|
||||
|
||||
CookieContainer cookies;
|
||||
HttpClientHandler handler;
|
||||
|
@ -44,20 +49,16 @@ namespace Jackett.Indexers
|
|||
client = new HttpClient(handler);
|
||||
}
|
||||
|
||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
return Task.Run(async () =>
|
||||
public async Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
await client.GetAsync(new Uri(BaseUrl));
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
return (ConfigurationData)config;
|
||||
});
|
||||
}
|
||||
|
||||
public Task ApplyConfiguration(Newtonsoft.Json.Linq.JToken configJson)
|
||||
{
|
||||
return Task.Run(async () =>
|
||||
public async Task ApplyConfiguration(Newtonsoft.Json.Linq.JToken configJson)
|
||||
{
|
||||
|
||||
var config = new ConfigurationDataBasicLogin();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
|
@ -98,17 +99,23 @@ namespace Jackett.Indexers
|
|||
|
||||
IsConfigured = true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
HttpRequestMessage CreateHttpRequest(Uri uri)
|
||||
{
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Get;
|
||||
message.RequestUri = uri;
|
||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||
return message;
|
||||
}
|
||||
|
||||
public Task VerifyConnection()
|
||||
{
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var message = new HttpRequestMessage();
|
||||
message.Method = HttpMethod.Get;
|
||||
message.RequestUri = new Uri(BaseUrl);
|
||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
||||
var message = CreateHttpRequest(new Uri(BaseUrl));
|
||||
|
||||
var response = await client.SendAsync(message);
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
|
@ -123,18 +130,85 @@ namespace Jackett.Indexers
|
|||
IsConfigured = true;
|
||||
}
|
||||
|
||||
public Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
return Task<ReleaseInfo[]>.Run(async () =>
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
|
||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||
return releases.ToArray();
|
||||
});
|
||||
|
||||
|
||||
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
|
||||
{
|
||||
|
||||
var searchString = title + " " + query.GetEpisodeSearchString();
|
||||
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
|
||||
|
||||
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
|
||||
var response = await client.SendAsync(request);
|
||||
var results = await response.Content.ReadAsStringAsync();
|
||||
|
||||
CQ dom = results;
|
||||
|
||||
var rows = dom["table.torrents > tbody > tr"];
|
||||
foreach (var row in rows.Skip(1))
|
||||
{
|
||||
var release = new ReleaseInfo();
|
||||
|
||||
var qRow = row.Cq();
|
||||
|
||||
var qTitleLink = qRow.Find("a.t_title").First();
|
||||
release.Title = qTitleLink.Text().Trim();
|
||||
release.Description = release.Title;
|
||||
release.Guid = new Uri(BaseUrl + qTitleLink.Attr("href"));
|
||||
release.Comments = release.Guid;
|
||||
|
||||
DateTime pubDate;
|
||||
var descString = qRow.Find(".t_ctime").Text();
|
||||
var dateString = descString.Split('|').Last().Trim();
|
||||
dateString = dateString.Split(new string[] { " by " }, StringSplitOptions.None)[0];
|
||||
var dateValue = float.Parse(dateString.Split(' ')[0]);
|
||||
var dateUnit = dateString.Split(' ')[1];
|
||||
if (dateUnit.Contains("minute"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromMinutes(dateValue);
|
||||
else if (dateUnit.Contains("hour"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromHours(dateValue);
|
||||
else if (dateUnit.Contains("day"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(dateValue);
|
||||
else if (dateUnit.Contains("week"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(7 * dateValue);
|
||||
else if (dateUnit.Contains("month"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(30 * dateValue);
|
||||
else if (dateUnit.Contains("year"))
|
||||
pubDate = DateTime.Now - TimeSpan.FromDays(365 * dateValue);
|
||||
else
|
||||
pubDate = DateTime.MinValue;
|
||||
release.PublishDate = pubDate;
|
||||
|
||||
var qLink = row.ChildElements.ElementAt(3).Cq().Children("a");
|
||||
release.Link = new Uri(BaseUrl + qLink.Attr("href"));
|
||||
|
||||
var sizeStr = row.ChildElements.ElementAt(5).Cq().Text().Trim();
|
||||
var sizeVal = float.Parse(sizeStr.Split(' ')[0]);
|
||||
var sizeUnit = sizeStr.Split(' ')[1];
|
||||
release.Size = ReleaseInfo.GetBytes(sizeUnit, sizeVal);
|
||||
|
||||
release.Seeders = int.Parse(qRow.Find(".t_seeders").Text().Trim());
|
||||
release.Peers = int.Parse(qRow.Find(".t_leechers").Text().Trim()) + release.Seeders;
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
|
||||
public Task<byte[]> Download(Uri link)
|
||||
}
|
||||
|
||||
return releases.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public async Task<byte[]> Download(Uri link)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var request = CreateHttpRequest(link);
|
||||
var response = await client.SendAsync(request);
|
||||
var bytes = await response.Content.ReadAsByteArrayAsync();
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,27 +60,45 @@ namespace Jackett
|
|||
|
||||
async void ProcessHttpRequest(HttpListenerContext context)
|
||||
{
|
||||
if (webApi.HandleRequest(context))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.Request.Url.AbsolutePath.StartsWith("/api/"))
|
||||
{
|
||||
ProcessTorznab(context);
|
||||
return;
|
||||
}
|
||||
|
||||
var responseBytes = Encoding.UTF8.GetBytes("Invalid request");
|
||||
await context.Response.OutputStream.WriteAsync(responseBytes, 0, responseBytes.Length);
|
||||
context.Response.Close();
|
||||
}
|
||||
|
||||
async void ProcessTorznab(HttpListenerContext context)
|
||||
{
|
||||
Exception exception;
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
if (await webApi.HandleRequest(context))
|
||||
{
|
||||
|
||||
}
|
||||
else if (context.Request.Url.AbsolutePath.StartsWith("/api/"))
|
||||
{
|
||||
await ProcessTorznab(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
var responseBytes = Encoding.UTF8.GetBytes("Invalid request");
|
||||
await context.Response.OutputStream.WriteAsync(responseBytes, 0, responseBytes.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var errorBytes = Encoding.UTF8.GetBytes(exception.Message);
|
||||
await context.Response.OutputStream.WriteAsync(errorBytes, 0, errorBytes.Length);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
context.Response.Close();
|
||||
|
||||
}
|
||||
|
||||
async Task ProcessTorznab(HttpListenerContext context)
|
||||
{
|
||||
|
||||
var query = HttpUtility.ParseQueryString(context.Request.Url.Query);
|
||||
var inputStream = context.Request.InputStream;
|
||||
var reader = new StreamReader(inputStream, context.Request.ContentEncoding);
|
||||
|
@ -94,7 +112,6 @@ namespace Jackett
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -135,21 +152,7 @@ namespace Jackett
|
|||
context.Response.ContentLength64 = responseBytes.LongLength;
|
||||
context.Response.ContentType = "application/rss+xml";
|
||||
await context.Response.OutputStream.WriteAsync(responseBytes, 0, responseBytes.Length);
|
||||
context.Response.Close();
|
||||
return;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var errorBytes = Encoding.UTF8.GetBytes(exception.Message);
|
||||
await context.Response.OutputStream.WriteAsync(errorBytes, 0, errorBytes.Length);
|
||||
context.Response.Close();
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Jackett
|
|||
this.sonarrApi = sonarrApi;
|
||||
}
|
||||
|
||||
public bool HandleRequest(HttpListenerContext context)
|
||||
public async Task<bool> HandleRequest(HttpListenerContext context)
|
||||
{
|
||||
string path = context.Request.Url.AbsolutePath.TrimStart('/');
|
||||
if (path == "")
|
||||
|
@ -57,21 +57,21 @@ namespace Jackett
|
|||
var sysPath = Path.Combine(WebContentFolder, path.Replace("/", Path.DirectorySeparatorChar.ToString()));
|
||||
if (Array.IndexOf(StaticFiles, sysPath) > -1)
|
||||
{
|
||||
ServeStaticFile(context, path);
|
||||
await ServeStaticFile(context, path);
|
||||
return true;
|
||||
}
|
||||
|
||||
WebApi.WebApiMethod apiMethod;
|
||||
if (WebApi.WebApiMethods.TryGetValue(path, out apiMethod))
|
||||
{
|
||||
ProcessWebApiRequest(context, apiMethod);
|
||||
await ProcessWebApiRequest(context, apiMethod);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async void ServeStaticFile(HttpListenerContext context, string file)
|
||||
async Task ServeStaticFile(HttpListenerContext context, string file)
|
||||
{
|
||||
var contentFile = File.ReadAllBytes(Path.Combine(WebContentFolder, file));
|
||||
context.Response.ContentType = MimeMapping.GetMimeMapping(file);
|
||||
|
@ -79,7 +79,6 @@ namespace Jackett
|
|||
try
|
||||
{
|
||||
await context.Response.OutputStream.WriteAsync(contentFile, 0, contentFile.Length);
|
||||
context.Response.OutputStream.Close();
|
||||
}
|
||||
catch (HttpListenerException) { }
|
||||
}
|
||||
|
@ -92,7 +91,7 @@ namespace Jackett
|
|||
|
||||
delegate Task<JToken> HandlerTask(HttpListenerContext context);
|
||||
|
||||
async void ProcessWebApiRequest(HttpListenerContext context, WebApiMethod method)
|
||||
async Task ProcessWebApiRequest(HttpListenerContext context, WebApiMethod method)
|
||||
{
|
||||
var query = HttpUtility.ParseQueryString(context.Request.Url.Query);
|
||||
|
||||
|
@ -139,7 +138,6 @@ namespace Jackett
|
|||
{
|
||||
byte[] jsonBytes = Encoding.UTF8.GetBytes(json.ToString());
|
||||
await context.Response.OutputStream.WriteAsync(jsonBytes, 0, jsonBytes.Length);
|
||||
context.Response.OutputStream.Close();
|
||||
}
|
||||
|
||||
async Task<JToken> HandleTestSonarr(HttpListenerContext context)
|
||||
|
|
Loading…
Add table
Reference in a new issue