Refactored to use the RageID lookup disabled, removed Sonarr API setup

This commit is contained in:
unknown
2015-07-18 14:35:02 -06:00
parent 974565d907
commit 7f2aa4ccad
30 changed files with 922 additions and 1257 deletions

View File

@@ -20,6 +20,8 @@ namespace Jackett
string DisplayDescription { get; }
Uri SiteLink { get; }
bool RequiresRageIDLookupDisabled { get; }
// Whether this indexer has been configured, verified and saved in the past and has the settings required for functioning
bool IsConfigured { get; }

View File

@@ -29,6 +29,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
@@ -161,11 +163,7 @@ namespace Jackett.Indexers
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
string results;
@@ -223,7 +221,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -58,6 +58,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
const string BaseUrl = "https://animebytes.tv";
const string LoginUrl = BaseUrl + "/user/login";
const string SearchUrl = BaseUrl + "/torrents.php?filter_cat[1]=1";
@@ -196,15 +198,12 @@ namespace Jackett.Indexers
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
{
// The result list
var releases = new ConcurrentBag<ReleaseInfo>();
var titles = query.ShowTitles ?? new string[] { query.SearchTerm??string.Empty };
var releases = new List<ReleaseInfo>();
var tasks = titles.Select(async item =>
foreach (var result in await GetResults(query.SanitizedSearchTerm))
{
foreach (var result in await GetResults(item))
releases.Add(result);
});
await Task.WhenAll(tasks);
}
return releases.ToArray();
}

View File

@@ -32,6 +32,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
const string BaseUrl = "https://beyondhd.me";
@@ -100,9 +102,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
var results = await client.GetStringAsync(episodeSearchUrl);
@@ -168,7 +168,7 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -31,6 +31,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
static string BaseUrl = "https://www.bit-hdtv.com";
static string LoginUrl = BaseUrl + "/takelogin.php";
static string SearchUrl = BaseUrl + "/torrents.php?cat=0&search=";
@@ -109,9 +111,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
var results = await client.GetStringAsync(episodeSearchUrl);
try
@@ -155,7 +155,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -71,6 +71,8 @@ namespace Jackett
public Uri SiteLink { get { return new Uri(BaseUrl); } }
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
public async Task<ConfigurationData> GetConfigurationForSetup()
@@ -130,11 +132,7 @@ namespace Jackett
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
var results = await client.GetStringAsync(episodeSearchUrl);
try
@@ -187,7 +185,6 @@ namespace Jackett
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();

View File

@@ -44,9 +44,10 @@ namespace Jackett.Indexers
public Uri SiteLink
{
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
const string BaseUrl = "http://www.frenchtorrentdb.com/";
const string MainUrl = BaseUrl + "?section=INDEX";
@@ -114,9 +115,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
var message = new HttpRequestMessage();
@@ -160,7 +159,7 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -37,6 +37,8 @@ namespace Jackett
public Uri SiteLink { get { return new Uri(BaseUrl); } }
public bool RequiresRageIDLookupDisabled { get { return true; } }
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
public Freshon()
@@ -118,15 +120,13 @@ namespace Jackett
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
string episodeSearchUrl;
if (string.IsNullOrEmpty(title))
if (string.IsNullOrEmpty(query.SanitizedSearchTerm))
episodeSearchUrl = SearchUrl;
else
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
episodeSearchUrl = string.Format("{0}?search={1}&cat=0", SearchUrl, HttpUtility.UrlEncode(searchString));
}
@@ -180,7 +180,6 @@ namespace Jackett
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -58,6 +58,8 @@ namespace Jackett.Indexers
get { return new Uri(DefaultUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured
{
get;
@@ -131,10 +133,9 @@ namespace Jackett.Indexers
List<ReleaseInfo> releases = new List<ReleaseInfo>();
List<string> searchurls = new List<string>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
for (int page = 0; page < MAXPAGES; page++)
{
searchurls.Add(string.Format(SearchUrl, HttpUtility.UrlEncode(searchString.Trim()), page));
}

View File

@@ -24,6 +24,8 @@ namespace Jackett.Indexers
public Uri SiteLink { get { return new Uri(BaseUrl); } }
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
static string chromeUserAgent = BrowserUtil.ChromeUserAgent;
@@ -120,10 +122,7 @@ namespace Jackett.Indexers
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
var request = CreateHttpRequest(new Uri(episodeSearchUrl));
@@ -189,8 +188,6 @@ namespace Jackett.Indexers
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -29,6 +29,7 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
@@ -145,10 +146,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString);
string results;
@@ -206,7 +204,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -31,6 +31,8 @@ namespace Jackett.Indexers
get { return new Uri("https://rarbg.com"); }
}
public bool RequiresRageIDLookupDisabled { get { return false; } }
public bool IsConfigured { get; private set; }
const string DefaultUrl = "http://torrentapi.org";
@@ -127,7 +129,7 @@ namespace Jackett.Indexers
if (query.RageID != 0)
searchUrl = string.Format(baseUrl + SearchTVRageUrl, query.RageID, token);
else
searchUrl = string.Format(baseUrl + SearchQueryUrl, query.SearchTerm, token);
searchUrl = string.Format(baseUrl + SearchQueryUrl, query.SanitizedSearchTerm, token);
var request = CreateHttpRequest(searchUrl);
var response = await client.SendAsync(request);

View File

@@ -31,6 +31,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
const string BaseUrl = "https://sceneaccess.eu";
const string LoginUrl = BaseUrl + "/login";
const string SearchUrl = BaseUrl + "/{0}?method=1&c{1}=1&search={2}";
@@ -125,9 +127,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var searchSection = string.IsNullOrEmpty(query.Episode) ? "archive" : "browse";
var searchCategory = string.IsNullOrEmpty(query.Episode) ? "26" : "27";
@@ -183,7 +183,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -33,6 +33,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
const string BaseUrl = "https://www.scenetime.com";
@@ -118,9 +120,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var searchContent = GetSearchFormData(searchString);
var response = await client.PostAsync(SearchUrl, searchContent);
@@ -167,7 +167,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -33,6 +33,8 @@ namespace Jackett.Indexers
get { return new Uri(DefaultUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
const string DefaultUrl = "http://showrss.info";
const string searchAllUrl = DefaultUrl + "/feeds/all.rss";
string BaseUrl;
@@ -117,9 +119,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(searchAllUrl);
XmlDocument xmlDoc = new XmlDocument();
@@ -167,7 +167,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, xml, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -32,6 +32,8 @@ namespace Jackett.Indexers
get { return new Uri(DefaultUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
const string DefaultUrl = "https://getstrike.net";
@@ -98,9 +100,9 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { "2015" })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchTerm = query.SanitizedSearchTerm ?? "2015";
var searchString = searchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = baseUrl + string.Format(SearchUrl, HttpUtility.UrlEncode(searchString.Trim()));
var results = await client.GetStringAsync(episodeSearchUrl);
try
@@ -138,7 +140,7 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -34,6 +34,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
const string BaseUrl = "http://www.t411.io";
@@ -136,9 +138,8 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { "%20" })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchTerm = string.IsNullOrEmpty(query.SanitizedSearchTerm) ? "%20" : query.SanitizedSearchTerm;
var searchString = searchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
var message = new HttpRequestMessage();
@@ -182,7 +183,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -26,6 +26,8 @@ namespace Jackett.Indexers
public Uri SiteLink { get { return new Uri(DefaultUrl); } }
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
const string DefaultUrl = "https://thepiratebay.mn";
@@ -93,18 +95,9 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
List<string> searchUrls = new List<string>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var queryStr = HttpUtility.UrlEncode(searchString);
var episodeSearchUrl = baseUrl + string.Format(SearchUrl, queryStr);
searchUrls.Add(episodeSearchUrl);
}
foreach (var episodeSearchUrl in searchUrls)
{
string results;
@@ -185,9 +178,7 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -33,6 +33,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
public bool IsConfigured { get; private set; }
const string BaseUrl = "https://torrentday.eu";
@@ -126,9 +128,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
var results = await client.GetStringAsync(episodeSearchUrl);
try
@@ -183,7 +183,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -33,6 +33,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
const string BaseUrl = "http://www.torrentleech.org";
const string LoginUrl = BaseUrl + "/user/account/login/";
const string SearchUrl = BaseUrl + "/torrents/browse/index/query/{0}/categories/2%2C26%2C27%2C32/orderby/added?";
@@ -109,10 +111,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
var results = await client.GetStringAsync(episodeSearchUrl);
try
@@ -161,9 +160,6 @@ namespace Jackett.Indexers
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -33,6 +33,8 @@ namespace Jackett.Indexers
get { return new Uri(BaseUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
const string BaseUrl = "http://torrentshack.me";
const string LoginUrl = BaseUrl + "/login.php";
const string SearchUrl = BaseUrl + "/torrents.php?searchstr={0}&release_type=both&searchtags=&tags_type=0&order_by=s3&order_way=desc&torrent_preset=all&filter_cat%5B600%5D=1&filter_cat%5B620%5D=1&filter_cat%5B700%5D=1&filter_cat%5B981%5D=1&filter_cat%5B980%5D=1";
@@ -111,9 +113,8 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString));
var results = await client.GetStringAsync(episodeSearchUrl);
try
@@ -174,7 +175,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, results, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -32,6 +32,8 @@ namespace Jackett.Indexers
get { return new Uri(DefaultUrl); }
}
public bool RequiresRageIDLookupDisabled { get { return true; } }
const string DefaultUrl = "https://torrentz.eu";
const string SearchUrl = DefaultUrl + "/feed_verifiedP?f={0}";
string BaseUrl;
@@ -104,9 +106,7 @@ namespace Jackett.Indexers
{
List<ReleaseInfo> releases = new List<ReleaseInfo>();
foreach (var title in query.ShowTitles ?? new string[] { string.Empty })
{
var searchString = title + " " + query.GetEpisodeSearchString();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = string.Format(SearchUrl, HttpUtility.UrlEncode(searchString.Trim()));
XmlDocument xmlDoc = new XmlDocument();
@@ -154,7 +154,6 @@ namespace Jackett.Indexers
OnResultParsingError(this, xml, ex);
throw ex;
}
}
return releases.ToArray();
}

View File

@@ -133,9 +133,7 @@
<Compile Include="ResultPage.cs" />
<Compile Include="Server.cs" />
<Compile Include="ServerUtil.cs" />
<Compile Include="SonarApi.cs" />
<Compile Include="TorznabQuery.cs" />
<Compile Include="TVRage.cs" />
<Compile Include="WebApi.cs" />
<Compile Include="CurlHelper.cs" />
<Compile Include="Indexers\AlphaRatio.cs" />
@@ -242,7 +240,6 @@
<Content Include="WebContent\jquery-2.1.3.min.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="WebContent\logos\freshon.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@@ -23,7 +23,6 @@ namespace Jackett
HttpListener listener;
IndexerManager indexerManager;
WebApi webApi;
SonarrApi sonarrApi;
public Server()
@@ -34,11 +33,8 @@ namespace Jackett
ReadServerSettingsFile();
LoadApiKey();
indexerManager = new IndexerManager();
sonarrApi = new SonarrApi();
webApi = new WebApi(indexerManager, sonarrApi);
webApi = new WebApi(indexerManager);
}
void LoadApiKey()
@@ -206,10 +202,10 @@ namespace Jackett
var torznabQuery = TorznabQuery.FromHttpQuery(query);
if (torznabQuery.RageID != 0)
torznabQuery.ShowTitles = await sonarrApi.GetShowTitle(torznabQuery.RageID);
else if (!string.IsNullOrEmpty(torznabQuery.SearchTerm))
torznabQuery.ShowTitles = new string[] { torznabQuery.SearchTerm };
if (torznabQuery.RageIDLookupEnabled && indexer.RequiresRageIDLookupDisabled)
{
throw new ArgumentException("This indexer requires RageID lookup disabled");
}
var releases = await indexer.PerformQuery(torznabQuery);

View File

@@ -1,169 +0,0 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
public class SonarrApi
{
public class ConfigurationSonarr : ConfigurationData
{
public StringItem Host { get; private set; }
public StringItem Port { get; private set; }
public StringItem ApiKey { get; private set; }
DisplayItem ApiInfo;
public ConfigurationSonarr()
{
Host = new StringItem { Name = "Host", Value = "http://localhost" };
Port = new StringItem { Name = "Port", Value = "8989" };
ApiKey = new StringItem { Name = "API Key" };
ApiInfo = new DisplayItem("API Key can be found in Sonarr > Settings > General > Security") { Name = "API Info" };
}
public override Item[] GetItems()
{
return new Item[] { Host, Port, ApiKey, ApiInfo };
}
}
static string SonarrConfigFile = Path.Combine(Program.AppConfigDirectory, "sonarr_api.json");
string Host;
int Port;
string ApiKey;
CookieContainer cookies;
HttpClientHandler handler;
HttpClient client;
ConcurrentDictionary<int, string[]> IdNameMappings;
public SonarrApi()
{
LoadSettings();
cookies = new CookieContainer();
handler = new HttpClientHandler
{
CookieContainer = cookies,
AllowAutoRedirect = true,
UseCookies = true,
};
client = new HttpClient(handler);
IdNameMappings = new ConcurrentDictionary<int, string[]>();
}
async Task ReloadNameMappings(string host, int port, string apiKey)
{
Uri hostUri = new Uri(host);
var queryUrl = string.Format("http://{0}:{1}/api/series?apikey={2}", hostUri.Host, port, apiKey);
var response = await client.GetStringAsync(queryUrl);
var json = JArray.Parse(response);
IdNameMappings.Clear();
foreach (var item in json)
{
var titles = new List<string>();
titles.Add(SanitizeTitle((string)item["title"]));
foreach (var t in item["alternateTitles"])
{
titles.Add(SanitizeTitle((string)t["title"]));
}
IdNameMappings.TryAdd((int)item["tvRageId"], titles.ToArray());
}
}
string SanitizeTitle(string title)
{
char[] arr = title.ToCharArray();
arr = Array.FindAll<char>(arr, c => (char.IsLetterOrDigit(c)
|| char.IsWhiteSpace(c)
|| c == '-'
|| c == '.'
));
title = new string(arr);
return title;
}
void LoadSettings()
{
try
{
if (File.Exists(SonarrConfigFile))
{
var json = JObject.Parse(File.ReadAllText(SonarrConfigFile));
Host = (string)json["host"];
Port = (int)json["port"];
ApiKey = (string)json["api_key"];
}
}
catch (Exception) { }
}
void SaveSettings()
{
JObject json = new JObject();
json["host"] = Host;
json["port"] = Port;
json["api_key"] = ApiKey;
File.WriteAllText(SonarrConfigFile, json.ToString());
}
public ConfigurationSonarr GetConfiguration()
{
var config = new ConfigurationSonarr();
if (ApiKey != null)
{
config.Host.Value = Host;
config.Port.Value = Port.ToString();
config.ApiKey.Value = ApiKey;
}
return config;
}
public async Task ApplyConfiguration(JToken configJson)
{
var config = new ConfigurationSonarr();
config.LoadValuesFromJson(configJson);
await ReloadNameMappings(config.Host.Value, ParseUtil.CoerceInt(config.Port.Value), config.ApiKey.Value);
Host = "http://" + new Uri(config.Host.Value).Host;
Port = ParseUtil.CoerceInt(config.Port.Value);
ApiKey = config.ApiKey.Value;
SaveSettings();
}
public async Task TestConnection()
{
await ReloadNameMappings(Host, Port, ApiKey);
}
public async Task<string[]> GetShowTitle(int rid)
{
if (rid == 0)
return null;
int tries = 0;
while (tries < 2)
{
string[] titles;
if (IdNameMappings.TryGetValue(rid, out titles))
return titles;
await ReloadNameMappings(Host, Port, ApiKey);
tries++;
}
return null;
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett
{
class TVRage
{
}
}

View File

@@ -17,10 +17,12 @@ namespace Jackett
public int Limit { get; private set; }
public int Offset { get; private set; }
public int RageID { get; private set; }
public bool RageIDLookupEnabled { get; private set; }
public int Season { get; private set; }
public string Episode { get; private set; }
public string[] ShowTitles { get; set; }
public string SearchTerm { get; set; }
public string SearchTerm { get; private set; }
public string SanitizedSearchTerm { get; private set; }
public string GetEpisodeSearchString()
{
@@ -39,13 +41,39 @@ namespace Jackett
return episodeString;
}
static string SanitizeSearchTerm(string title)
{
char[] arr = title.ToCharArray();
arr = Array.FindAll<char>(arr, c => (char.IsLetterOrDigit(c)
|| char.IsWhiteSpace(c)
|| c == '-'
|| c == '.'
));
title = new string(arr);
return title;
}
public static TorznabQuery FromHttpQuery(NameValueCollection query)
{
//{t=tvsearch&cat=5030%2c5040&extended=1&apikey=test&offset=0&limit=100&rid=24493&season=5&ep=1}
var q = new TorznabQuery();
q.QueryType = query["t"];
if (query["q"] == null)
{
q.SearchTerm = string.Empty;
q.SanitizedSearchTerm = string.Empty;
}
else
{
q.SearchTerm = query["q"];
q.SanitizedSearchTerm = SanitizeSearchTerm(q.SearchTerm);
}
q.RageIDLookupEnabled = query["rid_enabled"] != "0";
if (query["cat"] != null)
{
q.Categories = query["cat"].Split(',');
@@ -65,11 +93,17 @@ namespace Jackett
q.Offset = ParseUtil.CoerceInt(query["offset"]);
}
int temp;
if (int.TryParse(query["rid"], out temp))
q.RageID = temp;
if (int.TryParse(query["season"], out temp))
q.Season = temp;
int rageId;
if (int.TryParse(query["rid"], out rageId))
{
q.RageID = rageId;
}
int season;
if (int.TryParse(query["season"], out season))
{
q.Season = season;
}
q.Episode = query["ep"];

View File

@@ -27,7 +27,6 @@ namespace Jackett
DeleteIndexer,
GetSonarrConfig,
ApplySonarrConfig,
TestSonarr,
GetJackettConfig,
ApplyJackettConfig,
JackettRestart,
@@ -41,19 +40,16 @@ namespace Jackett
{ "delete_indexer", WebApiMethod.DeleteIndexer },
{ "get_sonarr_config", WebApiMethod.GetSonarrConfig },
{ "apply_sonarr_config", WebApiMethod.ApplySonarrConfig },
{ "test_sonarr", WebApiMethod.TestSonarr },
{ "get_jackett_config",WebApiMethod.GetJackettConfig},
{ "apply_jackett_config",WebApiMethod.ApplyJackettConfig},
{ "jackett_restart", WebApiMethod.JackettRestart },
};
IndexerManager indexerManager;
SonarrApi sonarrApi;
public WebApi(IndexerManager indexerManager, SonarrApi sonarrApi)
public WebApi(IndexerManager indexerManager)
{
this.indexerManager = indexerManager;
this.sonarrApi = sonarrApi;
}
public async Task<bool> HandleRequest(HttpListenerContext context)
@@ -125,15 +121,6 @@ namespace Jackett
case WebApiMethod.DeleteIndexer:
handlerTask = HandleDeleteIndexer;
break;
case WebApiMethod.GetSonarrConfig:
handlerTask = HandleGetSonarrConfig;
break;
case WebApiMethod.ApplySonarrConfig:
handlerTask = HandleApplySonarrConfig;
break;
case WebApiMethod.TestSonarr:
handlerTask = HandleTestSonarr;
break;
case WebApiMethod.ApplyJackettConfig:
handlerTask = HandleApplyJackettConfig;
break;
@@ -164,55 +151,6 @@ namespace Jackett
}
}
async Task<JToken> HandleTestSonarr(HttpListenerContext context)
{
JToken jsonReply = new JObject();
try
{
await sonarrApi.TestConnection();
jsonReply["result"] = "success";
}
catch (Exception ex)
{
jsonReply["result"] = "error";
jsonReply["error"] = ex.Message;
}
return jsonReply;
}
async Task<JToken> HandleApplySonarrConfig(HttpListenerContext context)
{
JToken jsonReply = new JObject();
try
{
var postData = await ReadPostDataJson(context.Request.InputStream);
await sonarrApi.ApplyConfiguration(postData);
jsonReply["result"] = "success";
}
catch (Exception ex)
{
jsonReply["result"] = "error";
jsonReply["error"] = ex.Message;
}
return jsonReply;
}
Task<JToken> HandleGetSonarrConfig(HttpListenerContext context)
{
JObject jsonReply = new JObject();
try
{
jsonReply["config"] = sonarrApi.GetConfiguration().ToJson();
jsonReply["result"] = "success";
}
catch (Exception ex)
{
jsonReply["result"] = "error";
jsonReply["error"] = ex.Message;
}
return Task.FromResult<JToken>(jsonReply);
}
Task<JToken> HandleInvalidApiMethod(HttpListenerContext context)
{
JToken jsonReply = new JObject();
@@ -276,7 +214,7 @@ namespace Jackett
jsonReply["api_key"] = ApiKey.CurrentKey;
jsonReply["app_version"] = Assembly.GetExecutingAssembly().GetName().Version.ToString();
JArray items = new JArray();
foreach (var i in indexerManager.Indexers.OrderBy(_=>_.Key))
foreach (var i in indexerManager.Indexers.OrderBy(_ => _.Key))
{
var indexer = i.Value;
var item = new JObject();

View File

@@ -2,7 +2,6 @@
reloadIndexers();
loadJackettSettings();
loadSonarrInfo();
function loadJackettSettings() {
getJackettConfig(function (data) {
@@ -44,86 +43,6 @@ function getJackettConfig(callback) {
});
}
function loadSonarrInfo() {
getSonarrConfig(function (data) {
$("#sonarr-host").val("");
var host, port, apiKey;
for (var i = 0; i < data.config.length; i++) {
if (data.config[i].id == "host")
host = data.config[i].value;
if (data.config[i].id == "port")
port = data.config[i].value;
if (data.config[i].id == "apikey")
apiKey = data.config[i].value;
}
if (!apiKey)
$("#sonarr-warning").show();
else {
$("#sonarr-warning").hide();
$("#sonarr-host").val(host + ":" + port);
}
});
}
function getSonarrConfig(callback) {
var jqxhr = $.get("get_sonarr_config", function (data) {
callback(data);
}).fail(function () {
doNotify("Error loading Sonarr API configuration, request to Jackett server failed", "danger", "glyphicon glyphicon-alert");
});
}
$("#sonarr-test").click(function () {
var jqxhr = $.get("get_indexers", function (data) {
if (data.result == "error")
doNotify("Test failed for Sonarr API\n" + data.error, "danger", "glyphicon glyphicon-alert");
else
doNotify("Test successful for Sonarr API", "success", "glyphicon glyphicon-ok");
}).fail(function () {
doNotify("Error testing Sonarr, request to Jackett server failed", "danger", "glyphicon glyphicon-alert");
});
});
$("#sonarr-settings").click(function () {
getSonarrConfig(function (data) {
var config = data.config;
var configForm = newConfigModal("Sonarr API", config);
var $goButton = configForm.find(".setup-indexer-go");
$goButton.click(function () {
var data = getConfigModalJson(configForm);
var originalBtnText = $goButton.html();
$goButton.prop('disabled', true);
$goButton.html($('#templates > .spinner')[0].outerHTML);
var jqxhr = $.post("apply_sonarr_config", JSON.stringify(data), function (data) {
if (data.result == "error") {
if (data.config) {
populateSetupForm(data.indexer, data.name, data.config);
}
doNotify("Configuration failed: " + data.error, "danger", "glyphicon glyphicon-alert");
}
else {
configForm.modal("hide");
loadSonarrInfo();
doNotify("Successfully configured Sonarr API", "success", "glyphicon glyphicon-ok");
}
}).fail(function () {
doNotify("Request to Jackett server failed", "danger", "glyphicon glyphicon-alert");
}).always(function () {
$goButton.html(originalBtnText);
$goButton.prop('disabled', false);
});
});
configForm.modal("show");
});
});
function reloadIndexers() {
$('#indexers').hide();
$('#indexers > .indexer').remove();

View File

@@ -25,29 +25,18 @@
<hr />
<div class="input-area">
<span class="input-header">Sonarr API Host: </span>
<input id="sonarr-host" class="form-control input-right" type="text" readonly />
<button id="sonarr-settings" class="btn btn-primary btn-sm">
Settings <span class="glyphicon glyphicon-wrench" aria-hidden="true"></span>
</button>
<button id="sonarr-test" class="btn btn-warning btn-sm">
Test <span class="glyphicon glyphicon-screenshot" aria-hidden="true"></span>
</button>
<p id="sonarr-warning" class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign"></span>
Sonarr API must be configured
</p>
</div>
<hr />
<div class="input-area">
<p>
To add a Jackett indexer in Sonarr go to <b>Settings > Indexers > Add > Torznab > Custom</b>.
</p>
<h4>Adding a Jackett indexer in Sonarr</h4>
<ol>
<li>In Sonarr go to <b>Settings > Indexers > Add > Torznab > Custom</b></li>
<li>For <b>URL</b> enter the <b>Torznab Host</b> of one of the indexers below</li>
<li>For <b>API key</b> using the key below</li>
<li>Turn off <b>Enable RageID Lookup</b></li>
</ol>
<span class="input-header">Jackett API Key: </span>
<input id="api-key-input" class="form-control input-right" type="text" value="" placeholder="API Key" readonly="">
<p>Use this key when adding indexers to Sonarr. This key works for all indexers.</p>
</div>
<hr />
<div class="input-area">
<span class="input-header">Jackett port: </span>
<input id="jackett-port" class="form-control input-right" type="text" value="" placeholder="9117">
<button id="change-jackett-port" class="btn btn-primary btn-sm">