mirror of
https://github.com/Jackett/Jackett
synced 2025-01-01 04:38:20 +00:00
Interim commit
This commit is contained in:
parent
33a97b148f
commit
e518a3b58e
6 changed files with 88 additions and 54 deletions
|
@ -50,6 +50,11 @@ namespace Jackett
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DumpToJson(this CookieContainer cookies, string uri, JToken json)
|
||||||
|
{
|
||||||
|
DumpToJson(cookies, new Uri(uri), json);
|
||||||
|
}
|
||||||
|
|
||||||
public static void DumpToJson(this CookieContainer cookies, Uri uri, JToken json)
|
public static void DumpToJson(this CookieContainer cookies, Uri uri, JToken json)
|
||||||
{
|
{
|
||||||
json["cookie_header"] = cookies.GetCookieHeader(uri);
|
json["cookie_header"] = cookies.GetCookieHeader(uri);
|
||||||
|
|
|
@ -11,12 +11,6 @@ namespace Jackett
|
||||||
{
|
{
|
||||||
public interface IndexerInterface
|
public interface IndexerInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
// Invoked when the indexer configuration has been applied and verified so the cookie needs to be saved
|
|
||||||
event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
|
||||||
|
|
||||||
event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
|
||||||
|
|
||||||
string DisplayName { get; }
|
string DisplayName { get; }
|
||||||
string DisplayDescription { get; }
|
string DisplayDescription { get; }
|
||||||
Uri SiteLink { get; }
|
Uri SiteLink { get; }
|
||||||
|
|
|
@ -12,56 +12,40 @@ using System.Net.Http.Headers;
|
||||||
using Jackett.Utils;
|
using Jackett.Utils;
|
||||||
using Jackett.Models;
|
using Jackett.Models;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using Jackett.Services;
|
||||||
|
|
||||||
namespace Jackett.Indexers
|
namespace Jackett.Indexers
|
||||||
{
|
{
|
||||||
public class AlphaRatio : IndexerInterface
|
public class AlphaRatio : BaseIndexer
|
||||||
{
|
{
|
||||||
public string DisplayName
|
private string LoginUrl;
|
||||||
{
|
private string SearchUrl;
|
||||||
get { return "AlphaRatio"; }
|
private string DownloadUrl;
|
||||||
}
|
private string GuidUrl;
|
||||||
|
|
||||||
public string DisplayDescription
|
|
||||||
{
|
|
||||||
get { return "Legendary"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Uri SiteLink
|
|
||||||
{
|
|
||||||
get { return new Uri(BaseUrl); }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
|
||||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
|
||||||
|
|
||||||
public bool IsConfigured { get; private set; }
|
|
||||||
|
|
||||||
static string BaseUrl = "https://alpharatio.cc";
|
|
||||||
|
|
||||||
static string LoginUrl = BaseUrl + "/login.php";
|
|
||||||
|
|
||||||
static string SearchUrl = BaseUrl + "/ajax.php?action=browse&searchstr=";
|
|
||||||
|
|
||||||
static string DownloadUrl = BaseUrl + "/torrents.php?action=download&id=";
|
|
||||||
|
|
||||||
static string GuidUrl = BaseUrl + "/torrents.php?torrentid=";
|
|
||||||
|
|
||||||
static string chromeUserAgent = BrowserUtil.ChromeUserAgent;
|
|
||||||
|
|
||||||
CookieContainer cookies;
|
CookieContainer cookies;
|
||||||
HttpClientHandler handler;
|
HttpClientHandler handler;
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
Logger logger;
|
Logger logger;
|
||||||
|
private IIndexerManagerService managementService;
|
||||||
|
|
||||||
string cookieHeader;
|
string cookieHeader;
|
||||||
|
|
||||||
public AlphaRatio(Logger l)
|
public AlphaRatio(Logger l, IIndexerManagerService m):
|
||||||
|
base(name: "AlphaRatio",
|
||||||
|
description: "Legendary",
|
||||||
|
link: new Uri("https://alpharatio.cc"),
|
||||||
|
logger:l)
|
||||||
{
|
{
|
||||||
logger = l;
|
logger = l;
|
||||||
IsConfigured = false;
|
managementService = m;
|
||||||
cookies = new CookieContainer();
|
|
||||||
|
LoginUrl = SiteLink.ToString() + "/login.php";
|
||||||
|
SearchUrl = SiteLink.ToString() + "/ajax.php?action=browse&searchstr=";
|
||||||
|
DownloadUrl = SiteLink.ToString() + "/torrents.php?action=download&id=";
|
||||||
|
GuidUrl = SiteLink.ToString() + "/torrents.php?torrentid=";
|
||||||
|
|
||||||
|
cookies = new CookieContainer();
|
||||||
handler = new HttpClientHandler
|
handler = new HttpClientHandler
|
||||||
{
|
{
|
||||||
CookieContainer = cookies,
|
CookieContainer = cookies,
|
||||||
|
@ -72,17 +56,16 @@ namespace Jackett.Indexers
|
||||||
client = new HttpClient(handler);
|
client = new HttpClient(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
public override Task<ConfigurationData> GetConfigurationForSetup()
|
||||||
{
|
{
|
||||||
var config = new ConfigurationDataBasicLogin();
|
var config = new ConfigurationDataBasicLogin();
|
||||||
return Task.FromResult<ConfigurationData>(config);
|
return Task.FromResult<ConfigurationData>(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ApplyConfiguration(JToken configJson)
|
public override async Task ApplyConfiguration(JToken configJson)
|
||||||
{
|
{
|
||||||
var configSaveData = new JObject();
|
var configSaveData = new JObject();
|
||||||
if (OnSaveConfigurationRequested != null)
|
managementService.SaveConfig(this, configSaveData);
|
||||||
OnSaveConfigurationRequested(this, configSaveData);
|
|
||||||
|
|
||||||
var config = new ConfigurationDataBasicLogin();
|
var config = new ConfigurationDataBasicLogin();
|
||||||
config.LoadValuesFromJson(configJson);
|
config.LoadValuesFromJson(configJson);
|
||||||
|
@ -129,9 +112,7 @@ namespace Jackett.Indexers
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (OnSaveConfigurationRequested != null)
|
managementService.SaveConfig(this, configSaveData);
|
||||||
OnSaveConfigurationRequested(this, configSaveData);
|
|
||||||
|
|
||||||
IsConfigured = true;
|
IsConfigured = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,11 +122,11 @@ namespace Jackett.Indexers
|
||||||
var message = new HttpRequestMessage();
|
var message = new HttpRequestMessage();
|
||||||
message.Method = HttpMethod.Post;
|
message.Method = HttpMethod.Post;
|
||||||
message.RequestUri = uri;
|
message.RequestUri = uri;
|
||||||
message.Headers.UserAgent.ParseAdd(chromeUserAgent);
|
message.Headers.UserAgent.ParseAdd(BrowserUtil.ChromeUserAgent);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
public override void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||||
{
|
{
|
||||||
cookies.FillFromJson(SiteLink, jsonConfig, logger);
|
cookies.FillFromJson(SiteLink, jsonConfig, logger);
|
||||||
cookieHeader = cookies.GetCookieHeader(SiteLink);
|
cookieHeader = cookies.GetCookieHeader(SiteLink);
|
||||||
|
@ -163,7 +144,7 @@ namespace Jackett.Indexers
|
||||||
release.Link = new Uri(DownloadUrl + id);
|
release.Link = new Uri(DownloadUrl + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
public override async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||||
{
|
{
|
||||||
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
List<ReleaseInfo> releases = new List<ReleaseInfo>();
|
||||||
|
|
||||||
|
@ -225,7 +206,7 @@ namespace Jackett.Indexers
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OnResultParsingError(this, results, ex);
|
LogParseError(results, ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,7 +221,7 @@ namespace Jackett.Indexers
|
||||||
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
|
return new DateTime(unixStart.Ticks + unixTimeStampInTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<byte[]> Download(Uri link)
|
public override async Task<byte[]> Download(Uri link)
|
||||||
{
|
{
|
||||||
if (WebServer.IsWindows)
|
if (WebServer.IsWindows)
|
||||||
{
|
{
|
||||||
|
|
43
src/Jackett/Indexers/BaseIndexer.cs
Normal file
43
src/Jackett/Indexers/BaseIndexer.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jackett.Models;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
|
namespace Jackett.Indexers
|
||||||
|
{
|
||||||
|
public abstract class BaseIndexer: IndexerInterface
|
||||||
|
{
|
||||||
|
public string DisplayDescription { get; }
|
||||||
|
public string DisplayName { get; }
|
||||||
|
public bool IsConfigured { get; protected set; }
|
||||||
|
public Uri SiteLink { get; }
|
||||||
|
|
||||||
|
public abstract Task ApplyConfiguration(JToken configJson);
|
||||||
|
public abstract Task<byte[]> Download(Uri link);
|
||||||
|
public abstract Task<ConfigurationData> GetConfigurationForSetup();
|
||||||
|
public abstract void LoadFromSavedConfiguration(JToken jsonConfig);
|
||||||
|
public abstract Task<ReleaseInfo[]> PerformQuery(TorznabQuery query);
|
||||||
|
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
public BaseIndexer(string name, string description, Uri link, Logger logger)
|
||||||
|
{
|
||||||
|
DisplayName = name;
|
||||||
|
DisplayDescription = description;
|
||||||
|
SiteLink = link;
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void LogParseError(string results, Exception ex)
|
||||||
|
{
|
||||||
|
var fileName = string.Format("Error on {0} for {1}.txt", DateTime.Now.ToString("yyyyMMddHHmmss"), DisplayName);
|
||||||
|
var spacing = string.Join("", Enumerable.Repeat(Environment.NewLine, 5));
|
||||||
|
var fileContents = string.Format("{0}{1}{2}", ex, spacing, results);
|
||||||
|
logger.Error(fileName + fileContents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -133,6 +133,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Indexers\BaseIndexer.cs" />
|
||||||
<Compile Include="Models\ApiKey.cs" />
|
<Compile Include="Models\ApiKey.cs" />
|
||||||
<Compile Include="Utils\BrowserUtil.cs" />
|
<Compile Include="Utils\BrowserUtil.cs" />
|
||||||
<Compile Include="Models\CachedResult.cs" />
|
<Compile Include="Models\CachedResult.cs" />
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Jackett.Models;
|
using Jackett.Models;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -16,6 +17,7 @@ namespace Jackett.Services
|
||||||
void DeleteIndexer(string name);
|
void DeleteIndexer(string name);
|
||||||
IndexerInterface GetIndexer(string name);
|
IndexerInterface GetIndexer(string name);
|
||||||
IEnumerable<IndexerInterface> GetAllIndexers();
|
IEnumerable<IndexerInterface> GetAllIndexers();
|
||||||
|
void SaveConfig(IndexerInterface indexer, JToken obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IndexerManagerService : IIndexerManagerService
|
public class IndexerManagerService : IIndexerManagerService
|
||||||
|
@ -64,5 +66,13 @@ namespace Jackett.Services
|
||||||
{
|
{
|
||||||
return Path.Combine(configService.GetIndexerConfigDir(), indexer.GetType().Name.ToLower() + ".json");
|
return Path.Combine(configService.GetIndexerConfigDir(), indexer.GetType().Name.ToLower() + ".json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SaveConfig(IndexerInterface indexer, JToken obj)
|
||||||
|
{
|
||||||
|
var configFilePath = GetIndexerConfigFilePath(indexer);
|
||||||
|
if (!Directory.Exists(configService.GetIndexerConfigDir()))
|
||||||
|
Directory.CreateDirectory(configService.GetIndexerConfigDir());
|
||||||
|
File.WriteAllText(configFilePath, obj.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue