mirror of https://github.com/Jackett/Jackett
Pull from master
This commit is contained in:
commit
ecdd1f655b
|
@ -31,6 +31,11 @@ Download in the [Releases page](https://github.com/zone117x/Jackett/releases)
|
|||
* [RARBG](https://rarbg.com)
|
||||
* [TorrentDay](https://torrentday.eu/)
|
||||
* [TorrentShack](http://torrentshack.me/)
|
||||
* AlphaRatio
|
||||
* AnimeBytes
|
||||
* SceneAccess
|
||||
* ShowRSS
|
||||
* Torrentz
|
||||
|
||||
|
||||
### Additional Trackers
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jackett
|
||||
{
|
||||
public class CachedResult
|
||||
{
|
||||
private List<ReleaseInfo> results;
|
||||
private DateTime created;
|
||||
private string query;
|
||||
|
||||
public CachedResult(string query, List<ReleaseInfo> results){
|
||||
this.results = results;
|
||||
created = DateTime.Now;
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public IReadOnlyList<ReleaseInfo> Results
|
||||
{
|
||||
get { return results.AsReadOnly(); }
|
||||
}
|
||||
|
||||
public DateTime Created
|
||||
{
|
||||
get { return created; }
|
||||
}
|
||||
|
||||
public string Query
|
||||
{
|
||||
get { return query; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jackett
|
||||
{
|
||||
public class ConfigurationDataBasicLoginAnimeBytes : ConfigurationDataBasicLogin
|
||||
{
|
||||
public BoolItem IncludeRaw { get; private set; }
|
||||
public DisplayItem RageIdWarning { get; private set; }
|
||||
public DisplayItem DateWarning { get; private set; }
|
||||
|
||||
public ConfigurationDataBasicLoginAnimeBytes(): base()
|
||||
{
|
||||
IncludeRaw = new BoolItem() { Name = "IncludeRaw", Value = false };
|
||||
RageIdWarning = new DisplayItem("Ensure rageid lookup is disabled in Sonarr for this tracker.") { Name = "RageWarning" };
|
||||
DateWarning = new DisplayItem("This tracker does not supply upload dates so they are based off year of release.") { Name = "DateWarning" };
|
||||
}
|
||||
|
||||
public override Item[] GetItems()
|
||||
{
|
||||
return new Item[] { Username, Password, IncludeRaw, RageIdWarning, DateWarning };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,387 @@
|
|||
using CsQuery;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Jackett.Indexers
|
||||
{
|
||||
public class AnimeBytes : IndexerInterface
|
||||
{
|
||||
private static List<CachedResult> cache = new List<CachedResult>();
|
||||
private static readonly TimeSpan cacheTime = new TimeSpan(0, 9, 0);
|
||||
|
||||
public event Action<IndexerInterface, string, Exception> OnResultParsingError;
|
||||
public event Action<IndexerInterface, JToken> OnSaveConfigurationRequested;
|
||||
|
||||
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";
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
get { return "AnimeBytes"; }
|
||||
}
|
||||
|
||||
public string DisplayDescription
|
||||
{
|
||||
get { return "The web's best Chinese cartoons"; }
|
||||
}
|
||||
|
||||
public Uri SiteLink
|
||||
{
|
||||
get { return new Uri(BaseUrl); }
|
||||
}
|
||||
|
||||
const string BaseUrl = "https://animebytes.tv";
|
||||
const string LoginUrl = BaseUrl + "/user/login";
|
||||
const string SearchUrl = BaseUrl + "/torrents.php?filter_cat[1]=1";
|
||||
|
||||
public bool IsConfigured { get; private set; }
|
||||
public bool AllowRaws { get; private set; }
|
||||
|
||||
|
||||
CookieContainer cookieContainer;
|
||||
HttpClientHandler handler;
|
||||
HttpClient client;
|
||||
|
||||
public AnimeBytes()
|
||||
{
|
||||
IsConfigured = false;
|
||||
cookieContainer = new CookieContainer();
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
CookieContainer = cookieContainer,
|
||||
AllowAutoRedirect = false,
|
||||
UseCookies = true,
|
||||
};
|
||||
client = new HttpClient(handler);
|
||||
client.DefaultRequestHeaders.Add("User-Agent", chromeUserAgent);
|
||||
}
|
||||
|
||||
public Task<ConfigurationData> GetConfigurationForSetup()
|
||||
{
|
||||
var config = new ConfigurationDataBasicLoginAnimeBytes();
|
||||
return Task.FromResult<ConfigurationData>(config);
|
||||
}
|
||||
|
||||
public async Task ApplyConfiguration(JToken configJson)
|
||||
{
|
||||
var config = new ConfigurationDataBasicLoginAnimeBytes();
|
||||
config.LoadValuesFromJson(configJson);
|
||||
|
||||
|
||||
// Get the login form as we need the CSRF Token
|
||||
var loginPage = await client.GetAsync(LoginUrl);
|
||||
CQ loginPageDom = await loginPage.Content.ReadAsStringAsync();
|
||||
var csrfToken = loginPageDom["input[name=\"csrf_token\"]"].Last();
|
||||
|
||||
// Build login form
|
||||
var pairs = new Dictionary<string, string> {
|
||||
{ "csrf_token", csrfToken.Attr("value") },
|
||||
{ "username", config.Username.Value },
|
||||
{ "password", config.Password.Value },
|
||||
{ "keeplogged_sent", "true" },
|
||||
{ "keeplogged", "on" },
|
||||
{ "login", "Log In!" }
|
||||
};
|
||||
|
||||
var content = new FormUrlEncodedContent(pairs);
|
||||
|
||||
// Do the login
|
||||
var response = await client.PostAsync(LoginUrl, content);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
// Compatiblity issue between the cookie format and httpclient
|
||||
// Pull it out manually ignoring the expiry date then set it manually
|
||||
// http://stackoverflow.com/questions/14681144/httpclient-not-storing-cookies-in-cookiecontainer
|
||||
IEnumerable<string> cookies;
|
||||
if (response.Headers.TryGetValues("set-cookie", out cookies))
|
||||
{
|
||||
foreach (var c in cookies)
|
||||
{
|
||||
cookieContainer.SetCookies(new Uri(BaseUrl), c.Substring(0, c.LastIndexOf(';')));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Cookie cookie in cookieContainer.GetCookies(new Uri(BaseUrl)))
|
||||
{
|
||||
if (cookie.Name == "session")
|
||||
{
|
||||
cookie.Expires = DateTime.Now.AddDays(360);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the home page now we are logged in as AllowAutoRedirect is false as we needed to get the cookie manually.
|
||||
response = await client.GetAsync(BaseUrl);
|
||||
responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!responseContent.Contains("/user/logout"))
|
||||
{
|
||||
throw new ExceptionWithConfigData("Failed to login, 6 failed attempts will get you banned for 6 hours.", (ConfigurationData)config);
|
||||
}
|
||||
else
|
||||
{
|
||||
AllowRaws = config.IncludeRaw.Value;
|
||||
var configSaveData = new JObject();
|
||||
configSaveData["cookies"] = cookieContainer.ToJson(SiteLink);
|
||||
configSaveData["raws"] = AllowRaws;
|
||||
|
||||
if (OnSaveConfigurationRequested != null)
|
||||
OnSaveConfigurationRequested(this, configSaveData);
|
||||
|
||||
IsConfigured = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFromSavedConfiguration(JToken jsonConfig)
|
||||
{
|
||||
cookieContainer.FillFromJson(new Uri(BaseUrl), (JArray)jsonConfig["cookies"]);
|
||||
IsConfigured = true;
|
||||
AllowRaws = jsonConfig["raws"].Value<bool>();
|
||||
}
|
||||
|
||||
|
||||
private string Hash(string input)
|
||||
{
|
||||
// Use input string to calculate MD5 hash
|
||||
MD5 md5 = System.Security.Cryptography.MD5.Create();
|
||||
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
|
||||
byte[] hashBytes = md5.ComputeHash(inputBytes);
|
||||
|
||||
// Convert the byte array to hexadecimal string
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hashBytes.Length; i++)
|
||||
{
|
||||
sb.Append(hashBytes[i].ToString("X2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private void CleanCache()
|
||||
{
|
||||
foreach (var expired in cache.Where(i => i.Created - DateTime.Now > cacheTime).ToList())
|
||||
{
|
||||
cache.Remove(expired);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<ReleaseInfo[]> PerformQuery(TorznabQuery query)
|
||||
{
|
||||
// This tracker only deals with full seasons so chop off the episode/season number if we have it D:
|
||||
if (!string.IsNullOrWhiteSpace(query.SearchTerm))
|
||||
{
|
||||
var splitindex = query.SearchTerm.LastIndexOf(' ');
|
||||
if (splitindex > -1)
|
||||
query.SearchTerm = query.SearchTerm.Substring(0, splitindex);
|
||||
}
|
||||
|
||||
// The result list
|
||||
var releases = new List<ReleaseInfo>();
|
||||
|
||||
// Check cache first so we don't query the server for each episode when searching for each episode in a series.
|
||||
lock (cache)
|
||||
{
|
||||
// Remove old cache items
|
||||
CleanCache();
|
||||
|
||||
var cachedResult = cache.Where(i => i.Query == query.SearchTerm).FirstOrDefault();
|
||||
if (cachedResult != null)
|
||||
return cachedResult.Results.Select(s => (ReleaseInfo)s.Clone()).ToArray();
|
||||
}
|
||||
|
||||
var queryUrl = SearchUrl;
|
||||
// Only include the query bit if its required as hopefully the site caches the non query page
|
||||
if(!string.IsNullOrWhiteSpace(query.SearchTerm)){
|
||||
|
||||
queryUrl += "&action=advanced&search_type=title&sort=time_added&way=desc&anime%5Btv_series%5D=1&searchstr=" + WebUtility.UrlEncode(query.SearchTerm);
|
||||
}
|
||||
|
||||
// Get the content from the tracker
|
||||
var response = await client.GetAsync(queryUrl);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
CQ dom = responseContent;
|
||||
|
||||
// Parse
|
||||
try
|
||||
{
|
||||
var releaseInfo = "S01";
|
||||
var root = dom.Find(".anime");
|
||||
// We may have got redirected to the series page if we have none of these
|
||||
if (root.Count() == 0)
|
||||
root = dom.Find(".torrent_table");
|
||||
|
||||
foreach (var series in root)
|
||||
{
|
||||
var seriesCq = series.Cq();
|
||||
|
||||
var synonyms = new List<string>();
|
||||
var mainTitle = seriesCq.Find(".group_title strong a").First().Text().Trim();
|
||||
|
||||
var yearStr = seriesCq.Find(".group_title strong").First().Text().Trim().Replace("]", "").Trim();
|
||||
int yearIndex = yearStr.LastIndexOf("[");
|
||||
if (yearIndex > -1)
|
||||
yearStr = yearStr.Substring(yearIndex+1);
|
||||
|
||||
int year = 0;
|
||||
if (!int.TryParse(yearStr, out year))
|
||||
year = DateTime.Now.Year;
|
||||
|
||||
synonyms.Add(mainTitle);
|
||||
|
||||
// If the title contains a comma then we can't use the synonyms as they are comma seperated
|
||||
if (!mainTitle.Contains(","))
|
||||
{
|
||||
var symnomnNames = string.Empty;
|
||||
foreach (var e in seriesCq.Find(".group_statbox li"))
|
||||
{
|
||||
if (e.FirstChild.InnerText == "Synonyms:")
|
||||
{
|
||||
symnomnNames = e.InnerText;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(symnomnNames))
|
||||
{
|
||||
foreach (var name in symnomnNames.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var theName = name.Trim();
|
||||
if (!theName.Contains("&#") && !string.IsNullOrWhiteSpace(theName))
|
||||
{
|
||||
synonyms.Add(theName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var title in synonyms)
|
||||
{
|
||||
var releaseRows = seriesCq.Find(".torrent_group tr");
|
||||
|
||||
// Skip the first two info rows
|
||||
for (int r = 2; r < releaseRows.Count(); r++)
|
||||
{
|
||||
var row = releaseRows.Get(r);
|
||||
var rowCq = row.Cq();
|
||||
if (rowCq.HasClass("edition_info"))
|
||||
{
|
||||
releaseInfo = rowCq.Find("td").Text();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(releaseInfo))
|
||||
{
|
||||
// Single episodes alpha - Reported that this info is missing.
|
||||
// It should self correct when availible
|
||||
break;
|
||||
}
|
||||
|
||||
releaseInfo = releaseInfo.Replace("Episode ", "");
|
||||
releaseInfo = releaseInfo.Replace("Season ", "S");
|
||||
releaseInfo = releaseInfo.Trim();
|
||||
}
|
||||
else if (rowCq.HasClass("torrent"))
|
||||
{
|
||||
var links = rowCq.Find("a");
|
||||
// Protect against format changes
|
||||
if (links.Count() != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var release = new ReleaseInfo();
|
||||
release.MinimumRatio = 1;
|
||||
release.MinimumSeedTime = 259200;
|
||||
var downloadLink = links.Get(0);
|
||||
release.Guid = new Uri(BaseUrl + "/" + downloadLink.Attributes.GetAttribute("href") + "&nh=" + Hash(title)); // Sonarr should dedupe on this url - allow a url per name.
|
||||
release.Link = release.Guid;// We dont know this so try to fake based on the release year
|
||||
release.PublishDate = new DateTime(year,1,1);
|
||||
release.PublishDate = release.PublishDate.AddDays(Math.Min(DateTime.Now.DayOfYear, 365) - 1);
|
||||
|
||||
var infoLink = links.Get(1);
|
||||
release.Comments = new Uri(BaseUrl + "/" + infoLink.Attributes.GetAttribute("href"));
|
||||
|
||||
// We dont actually have a release name >.> so try to create one
|
||||
var releaseTags = infoLink.InnerText.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
for (int i = releaseTags.Count - 1; i >= 0; i--)
|
||||
{
|
||||
releaseTags[i] = releaseTags[i].Trim();
|
||||
if (string.IsNullOrWhiteSpace(releaseTags[i]))
|
||||
releaseTags.RemoveAt(i);
|
||||
}
|
||||
|
||||
var group = releaseTags.Last();
|
||||
if (group.Contains("(") && group.Contains(")"))
|
||||
{
|
||||
// Skip raws if set
|
||||
if (group.ToLowerInvariant().StartsWith("raw") && !AllowRaws)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var start = group.IndexOf("(");
|
||||
group = "[" + group.Substring(start + 1, (group.IndexOf(")") - 1) - start) + "] ";
|
||||
}
|
||||
else
|
||||
{
|
||||
group = string.Empty;
|
||||
}
|
||||
|
||||
var infoString = "";
|
||||
|
||||
for (int i = 0; i + 1 < releaseTags.Count(); i++)
|
||||
{
|
||||
infoString += "[" + releaseTags[i] + "]";
|
||||
}
|
||||
|
||||
release.Title = string.Format("{0}{1} {2} {3}", group, title, releaseInfo, infoString);
|
||||
release.Description = title;
|
||||
|
||||
var size = rowCq.Find(".torrent_size");
|
||||
if (size.Count() > 0)
|
||||
{
|
||||
var sizeParts = size.First().Text().Split(' ');
|
||||
release.Size = ReleaseInfo.GetBytes(sizeParts[1], float.Parse(sizeParts[0]));
|
||||
}
|
||||
|
||||
// Additional 5 hours per GB
|
||||
release.MinimumSeedTime += (release.Size / 1000000000) * 18000;
|
||||
|
||||
// Peer info
|
||||
release.Seeders = int.Parse(rowCq.Find(".torrent_seeders").Text());
|
||||
release.Peers = release.Seeders + int.Parse(rowCq.Find(".torrent_leechers").Text());
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnResultParsingError(this, responseContent, ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
||||
// Add to the cache
|
||||
lock (cache)
|
||||
{
|
||||
cache.Add(new CachedResult(query.SearchTerm, releases));
|
||||
}
|
||||
|
||||
return releases.Select(s => (ReleaseInfo)s.Clone()).ToArray();
|
||||
}
|
||||
|
||||
public Task<byte[]> Download(Uri link)
|
||||
{
|
||||
return client.GetByteArrayAsync(link);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -149,7 +149,7 @@ namespace Jackett.Indexers
|
|||
release.Size = ReleaseInfo.GetBytes(sizeStringParts[1], float.Parse(sizeStringParts[0]));
|
||||
|
||||
release.Seeders = int.Parse(qRow.Find(".seeders").Text());
|
||||
release.Peers = int.Parse(qRow.Find(".leechers").Text());
|
||||
release.Peers = release.Seeders + int.Parse(qRow.Find(".leechers").Text());
|
||||
|
||||
releases.Add(release);
|
||||
}
|
||||
|
|
|
@ -81,9 +81,11 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ApiKey.cs" />
|
||||
<Compile Include="CachedResult.cs" />
|
||||
<Compile Include="ChannelInfo.cs" />
|
||||
<Compile Include="ChromeUnsafePorts.cs" />
|
||||
<Compile Include="ConfigurationData.cs" />
|
||||
<Compile Include="ConfigurationDataBasicLoginAnimeBytes.cs" />
|
||||
<Compile Include="ConfigurationDataBasicLogin.cs" />
|
||||
<Compile Include="ConfigurationDataUrl.cs" />
|
||||
<Compile Include="CookieContainerExtensions.cs" />
|
||||
|
@ -103,6 +105,7 @@
|
|||
<Compile Include="Indexers\Strike.cs" />
|
||||
<Compile Include="Indexers\ThePirateBay.cs" />
|
||||
<Compile Include="Indexers\TorrentDay.cs" />
|
||||
<Compile Include="Indexers\AnimeBytes.cs" />
|
||||
<Compile Include="Indexers\TorrentLeech.cs" />
|
||||
<Compile Include="Indexers\TorrentShack.cs" />
|
||||
<Compile Include="Indexers\Torrentz.cs" />
|
||||
|
@ -156,6 +159,19 @@
|
|||
<Content Include="WebContent\custom.js">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\custom.js">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\logos\animebytes.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\logos\sceneaccess.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\logos\showrss.png" />
|
||||
<Content Include="WebContent\logos\torrentday.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="WebContent\logos\sceneaccess.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||
namespace Jackett
|
||||
{
|
||||
|
||||
public class ReleaseInfo
|
||||
public class ReleaseInfo: ICloneable
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public Uri Guid { get; set; }
|
||||
|
@ -28,6 +28,30 @@ namespace Jackett
|
|||
public double? MinimumRatio { get; set; }
|
||||
public long? MinimumSeedTime { get; set; }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new ReleaseInfo()
|
||||
{
|
||||
Title = Title,
|
||||
Guid = Guid,
|
||||
Link = Link,
|
||||
Comments = Comments,
|
||||
PublishDate = PublishDate,
|
||||
Category = Category,
|
||||
Size = Size,
|
||||
Description = Description,
|
||||
RageID = RageID,
|
||||
Imdb = Imdb,
|
||||
Seeders = Seeders,
|
||||
Peers = Peers,
|
||||
ConverUrl = ConverUrl,
|
||||
BannerUrl = BannerUrl,
|
||||
InfoHash = InfoHash,
|
||||
MagnetUri = MagnetUri,
|
||||
MinimumRatio = MinimumRatio,
|
||||
MinimumSeedTime = MinimumSeedTime
|
||||
};
|
||||
}
|
||||
|
||||
public static long GetBytes(string unit, float value)
|
||||
{
|
||||
|
|
|
@ -46,11 +46,24 @@ namespace Jackett
|
|||
var q = new TorznabQuery();
|
||||
q.QueryType = query["t"];
|
||||
q.SearchTerm = query["q"];
|
||||
if (query["cat"] != null)
|
||||
{
|
||||
q.Categories = query["cat"].Split(',');
|
||||
}
|
||||
|
||||
if (query["extended"] != null)
|
||||
{
|
||||
q.Extended = int.Parse(query["extended"]);
|
||||
}
|
||||
q.ApiKey = query["apikey"];
|
||||
if (query["limit"] != null)
|
||||
{
|
||||
q.Limit = int.Parse(query["limit"]);
|
||||
}
|
||||
if (query["offset"] != null)
|
||||
{
|
||||
q.Offset = int.Parse(query["offset"]);
|
||||
}
|
||||
|
||||
int temp;
|
||||
if (int.TryParse(query["rid"], out temp))
|
||||
|
|
|
@ -95,6 +95,11 @@
|
|||
max-width: 260px;
|
||||
}
|
||||
|
||||
.setup-item-inputbool input {
|
||||
max-width: 100px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
-webkit-animation: spin 2s infinite linear;
|
||||
-moz-animation: spin 2s infinite linear;
|
||||
|
|
|
@ -428,6 +428,274 @@ $("#change-jackett-port").click(function () {
|
|||
|
||||
|
||||
|
||||
function doNotify(message, type, icon) {
|
||||
$.notify({
|
||||
message: message,
|
||||
icon: icon
|
||||
}, {
|
||||
element: 'body',
|
||||
type: type,
|
||||
allow_dismiss: true,
|
||||
z_index: 9000,
|
||||
mouse_over: 'pause',
|
||||
placement: {
|
||||
from: "bottom",
|
||||
align: "center"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function clearNotifications() {
|
||||
$('[data-notify="container"]').remove();
|
||||
}
|
||||
|
||||
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();
|
||||
$('#unconfigured-indexers').empty();
|
||||
var jqxhr = $.get("get_indexers", function (data) {
|
||||
$("#api-key-input").val(data.api_key);
|
||||
displayIndexers(data.items);
|
||||
}).fail(function () {
|
||||
doNotify("Error loading indexers, request to Jackett server failed", "danger", "glyphicon glyphicon-alert");
|
||||
});
|
||||
}
|
||||
|
||||
function displayIndexers(items) {
|
||||
var indexerTemplate = Handlebars.compile($("#templates > .configured-indexer")[0].outerHTML);
|
||||
var unconfiguredIndexerTemplate = Handlebars.compile($("#templates > .unconfigured-indexer")[0].outerHTML);
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i];
|
||||
item.torznab_host = resolveUrl("/api/" + item.id);
|
||||
if (item.configured)
|
||||
$('#indexers').append(indexerTemplate(item));
|
||||
else
|
||||
$('#unconfigured-indexers').append($(unconfiguredIndexerTemplate(item)));
|
||||
}
|
||||
|
||||
var addIndexerButton = $("#templates > .add-indexer")[0].outerHTML;
|
||||
$('#indexers').append(addIndexerButton);
|
||||
|
||||
$('#indexers').fadeIn();
|
||||
prepareSetupButtons();
|
||||
prepareTestButtons();
|
||||
prepareDeleteButtons();
|
||||
}
|
||||
|
||||
function prepareDeleteButtons() {
|
||||
$(".indexer-button-delete").each(function (i, btn) {
|
||||
var $btn = $(btn);
|
||||
var id = $btn.data("id");
|
||||
$btn.click(function () {
|
||||
var jqxhr = $.post("delete_indexer", JSON.stringify({ indexer: id }), function (data) {
|
||||
if (data.result == "error") {
|
||||
doNotify("Delete error for " + id + "\n" + data.error, "danger", "glyphicon glyphicon-alert");
|
||||
}
|
||||
else {
|
||||
doNotify("Deleted " + id, "success", "glyphicon glyphicon-ok");
|
||||
}
|
||||
}).fail(function () {
|
||||
doNotify("Error deleting indexer, request to Jackett server error", "danger", "glyphicon glyphicon-alert");
|
||||
}).always(function () {
|
||||
reloadIndexers();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function prepareSetupButtons() {
|
||||
$('.indexer-setup').each(function (i, btn) {
|
||||
var $btn = $(btn);
|
||||
var id = $btn.data("id");
|
||||
$btn.click(function () {
|
||||
displayIndexerSetup(id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function prepareTestButtons() {
|
||||
$(".indexer-button-test").each(function (i, btn) {
|
||||
var $btn = $(btn);
|
||||
var id = $btn.data("id");
|
||||
$btn.click(function () {
|
||||
doNotify("Test started for " + id, "info", "glyphicon glyphicon-transfer");
|
||||
var jqxhr = $.post("test_indexer", JSON.stringify({ indexer: id }), function (data) {
|
||||
if (data.result == "error") {
|
||||
doNotify("Test failed for " + data.name + "\n" + data.error, "danger", "glyphicon glyphicon-alert");
|
||||
}
|
||||
else {
|
||||
doNotify("Test successful for " + data.name, "success", "glyphicon glyphicon-ok");
|
||||
}
|
||||
}).fail(function () {
|
||||
doNotify("Error testing indexer, request to Jackett server error", "danger", "glyphicon glyphicon-alert");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function displayIndexerSetup(id) {
|
||||
|
||||
var jqxhr = $.post("get_config_form", JSON.stringify({ indexer: id }), function (data) {
|
||||
if (data.result == "error") {
|
||||
doNotify("Error: " + data.error, "danger", "glyphicon glyphicon-alert");
|
||||
return;
|
||||
}
|
||||
populateSetupForm(id, data.name, data.config);
|
||||
|
||||
}).fail(function () {
|
||||
doNotify("Request to Jackett server failed", "danger", "glyphicon glyphicon-alert");
|
||||
});
|
||||
|
||||
$("#select-indexer-modal").modal("hide");
|
||||
}
|
||||
|
||||
function populateConfigItems(configForm, config) {
|
||||
var $formItemContainer = configForm.find(".config-setup-form");
|
||||
$formItemContainer.empty();
|
||||
var setupItemTemplate = Handlebars.compile($("#templates > .setup-item")[0].outerHTML);
|
||||
for (var i = 0; i < config.length; i++) {
|
||||
var item = config[i];
|
||||
var setupValueTemplate = Handlebars.compile($("#templates > .setup-item-" + item.type)[0].outerHTML);
|
||||
item.value_element = setupValueTemplate(item);
|
||||
$formItemContainer.append(setupItemTemplate(item));
|
||||
}
|
||||
}
|
||||
|
||||
function newConfigModal(title, config) {
|
||||
//config-setup-modal
|
||||
var configTemplate = Handlebars.compile($("#templates > .config-setup-modal")[0].outerHTML);
|
||||
var configForm = $(configTemplate({ title: title }));
|
||||
|
||||
$("#modals").append(configForm);
|
||||
|
||||
populateConfigItems(configForm, config);
|
||||
|
||||
return configForm;
|
||||
//modal.remove();
|
||||
}
|
||||
|
||||
function getConfigModalJson(configForm) {
|
||||
var configJson = {};
|
||||
configForm.find(".config-setup-form").children().each(function (i, el) {
|
||||
$el = $(el);
|
||||
var type = $el.data("type");
|
||||
var id = $el.data("id");
|
||||
switch (type) {
|
||||
case "inputstring":
|
||||
configJson[id] = $el.find(".setup-item-inputstring").val();
|
||||
break;
|
||||
case "inputbool":
|
||||
configJson[id] = $el.find(".setup-item-inputbool input").is(":checked");
|
||||
break;
|
||||
}
|
||||
});
|
||||
return configJson;
|
||||
}
|
||||
|
||||
function populateSetupForm(indexerId, name, config) {
|
||||
|
||||
var configForm = newConfigModal(name, config);
|
||||
|
||||
var $goButton = configForm.find(".setup-indexer-go");
|
||||
$goButton.click(function () {
|
||||
var data = { indexer: indexerId, name: name };
|
||||
data.config = getConfigModalJson(configForm);
|
||||
|
||||
var originalBtnText = $goButton.html();
|
||||
$goButton.prop('disabled', true);
|
||||
$goButton.html($('#templates > .spinner')[0].outerHTML);
|
||||
|
||||
var jqxhr = $.post("configure_indexer", JSON.stringify(data), function (data) {
|
||||
if (data.result == "error") {
|
||||
if (data.config) {
|
||||
populateConfigItems(configForm, data.config);
|
||||
}
|
||||
doNotify("Configuration failed: " + data.error, "danger", "glyphicon glyphicon-alert");
|
||||
}
|
||||
else {
|
||||
configForm.modal("hide");
|
||||
reloadIndexers();
|
||||
doNotify("Successfully configured " + data.name, "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 resolveUrl(url) {
|
||||
var a = document.createElement('a');
|
||||
a.href = url;
|
||||
url = a.href;
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function doNotify(message, type, icon) {
|
||||
$.notify({
|
||||
message: message,
|
||||
|
|
|
@ -180,11 +180,11 @@
|
|||
</div>
|
||||
|
||||
<input class="setup-item-inputstring form-control" type="text" value="{{{value}}}" />
|
||||
<div class="setup-item-checkbox">
|
||||
<div class="setup-item-inputbool">
|
||||
{{#if value}}
|
||||
<input type="checkbox" class="form-control" checked />
|
||||
<input type="checkbox" data-id="{{id}}" class="form-control" checked />
|
||||
{{else}}
|
||||
<input type="checkbox" class="form-control" />
|
||||
<input type="checkbox" data-id="{{id}}" class="form-control" />
|
||||
{{/if}}
|
||||
</div>
|
||||
<img class="setup-item-displayimage" src="{{{value}}}" />
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
Loading…
Reference in New Issue