#93 Change IPT to be category aware and render availible categories to the front end.

This commit is contained in:
KZ
2015-07-29 20:30:28 +01:00
parent daf6d8ff50
commit 95402f3d4f
9 changed files with 165 additions and 36 deletions

View File

@@ -211,3 +211,12 @@ hr {
.modal-fillwidth { .modal-fillwidth {
width: 1200px; width: 1200px;
} }
.indexer-caps {
padding: 0px 15px 15px 15px;
border-top: 1px solid #e5e5e5;
}
.indexer-caps table {
border-bottom: 1px solid #ddd;
}

View File

@@ -211,7 +211,7 @@ function displayIndexerSetup(id) {
return; return;
} }
populateSetupForm(id, data.name, data.config); populateSetupForm(id, data.name, data.config, data.caps);
}).fail(function () { }).fail(function () {
doNotify("Request to Jackett server failed", "danger", "glyphicon glyphicon-alert"); doNotify("Request to Jackett server failed", "danger", "glyphicon glyphicon-alert");
@@ -236,17 +236,12 @@ function populateConfigItems(configForm, config) {
} }
} }
function newConfigModal(title, config) { function newConfigModal(title, config, caps) {
//config-setup-modal var configTemplate = Handlebars.compile($("#jackett-config-setup-modal").html());
var configTemplate = Handlebars.compile($("#templates > .config-setup-modal")[0].outerHTML); var configForm = $(configTemplate({ title: title, caps: caps }));
var configForm = $(configTemplate({ title: title }));
$("#modals").append(configForm); $("#modals").append(configForm);
populateConfigItems(configForm, config); populateConfigItems(configForm, config);
return configForm; return configForm;
//modal.remove();
} }
function getConfigModalJson(configForm) { function getConfigModalJson(configForm) {
@@ -267,8 +262,8 @@ function getConfigModalJson(configForm) {
return configJson; return configJson;
} }
function populateSetupForm(indexerId, name, config) { function populateSetupForm(indexerId, name, config, caps) {
var configForm = newConfigModal(name, config); var configForm = newConfigModal(name, config, caps);
var $goButton = configForm.find(".setup-indexer-go"); var $goButton = configForm.find(".setup-indexer-go");
$goButton.click(function () { $goButton.click(function () {
var data = { indexer: indexerId, name: name }; var data = { indexer: indexerId, name: name };

View File

@@ -70,6 +70,45 @@
</div> </div>
</script> </script>
<script id="jackett-config-setup-modal" type="text/x-handlebars-template">
<div class="config-setup-modal modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">{{title}}</h4>
</div>
<div class="modal-body">
<form class="config-setup-form"></form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary setup-indexer-go">Okay</button>
</div>
<div class="indexer-caps">
<h4>Capabilities</h4>
<table class="dataTable compact cell-border hover stripe">
<thead>
<tr>
<th>Category</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{{#each caps}}
<tr>
<td>{{ID}}</td>
<td>{{Name}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
</div>
</div>
</script>
<title>Jackett</title> <title>Jackett</title>
</head> </head>
<body> <body>
@@ -149,24 +188,6 @@
<div id="modals"></div> <div id="modals"></div>
<div id="templates"> <div id="templates">
<div class="config-setup-modal modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">{{title}}</h4>
</div>
<div class="modal-body">
<form class="config-setup-form"></form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary setup-indexer-go">Okay</button>
</div>
</div>
</div>
</div>
<button class="indexer card add-indexer" data-toggle="modal" data-target="#select-indexer-modal"> <button class="indexer card add-indexer" data-toggle="modal" data-target="#select-indexer-modal">
<div class="indexer-add-content"> <div class="indexer-add-content">
<span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span>

View File

@@ -3,6 +3,7 @@ using Jackett.Indexers;
using Jackett.Models; using Jackett.Models;
using Jackett.Services; using Jackett.Services;
using Jackett.Utils; using Jackett.Utils;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -146,6 +147,7 @@ namespace Jackett.Controllers
var indexer = indexerService.GetIndexer((string)postData["indexer"]); var indexer = indexerService.GetIndexer((string)postData["indexer"]);
var config = await indexer.GetConfigurationForSetup(); var config = await indexer.GetConfigurationForSetup();
jsonReply["config"] = config.ToJson(); jsonReply["config"] = config.ToJson();
jsonReply["caps"] = indexer.TorznabCaps.CapsToJson();
jsonReply["name"] = indexer.DisplayName; jsonReply["name"] = indexer.DisplayName;
jsonReply["result"] = "success"; jsonReply["result"] = "success";
} }

View File

@@ -343,5 +343,19 @@ namespace Jackett.Indexers
{ {
categoryMapping.Add(new CategoryMapping(trackerCategory.ToString(), newznabCategory)); categoryMapping.Add(new CategoryMapping(trackerCategory.ToString(), newznabCategory));
} }
protected List<string> MapTorznabCapsToTrackers(TorznabQuery query)
{
var result = new List<string>();
foreach (var cat in query.Categories)
{
foreach (var mapping in categoryMapping.Where(c => c.NewzNabCategory == cat))
{
result.Add(mapping.TrackerCategory);
}
}
return result;
}
} }
} }

View File

@@ -7,6 +7,7 @@ using Newtonsoft.Json.Linq;
using NLog; using NLog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@@ -19,7 +20,7 @@ namespace Jackett.Indexers
{ {
public class IPTorrents : BaseIndexer, IIndexer public class IPTorrents : BaseIndexer, IIndexer
{ {
private string SearchUrl { get { return SiteLink + "t?26=&55=&78=&23=&24=&25=&66=&82=&65=&83=&79=&22=&5=&4=&60=&q="; } } private string BrowseUrl { get { return SiteLink + "t"; } }
public IPTorrents(IIndexerManagerService i, IWebClient wc, Logger l) public IPTorrents(IIndexerManagerService i, IWebClient wc, Logger l)
: base(name: "IPTorrents", : base(name: "IPTorrents",
@@ -30,7 +31,47 @@ namespace Jackett.Indexers
client: wc, client: wc,
logger: l) logger: l)
{ {
TorznabCaps.Categories.Add(TorznabCatType.Anime); AddCategoryMapping(72, TorznabCatType.Movies);
AddCategoryMapping(77, TorznabCatType.MoviesSD);
AddCategoryMapping(89, TorznabCatType.MoviesSD);
AddCategoryMapping(90, TorznabCatType.MoviesSD);
AddCategoryMapping(96, TorznabCatType.MoviesSD);
AddCategoryMapping(6, TorznabCatType.MoviesSD);
AddCategoryMapping(48, TorznabCatType.MoviesHD);
AddCategoryMapping(54, TorznabCatType.Movies);
AddCategoryMapping(62, TorznabCatType.MoviesSD);
AddCategoryMapping(38, TorznabCatType.MoviesForeign);
AddCategoryMapping(68, TorznabCatType.Movies);
AddCategoryMapping(20, TorznabCatType.MoviesHD);
AddCategoryMapping(7, TorznabCatType.MoviesSD);
AddCategoryMapping(73, TorznabCatType.TV);
AddCategoryMapping(26, TorznabCatType.TVSD);
AddCategoryMapping(55, TorznabCatType.TVSD);
AddCategoryMapping(78, TorznabCatType.TVSD);
AddCategoryMapping(23, TorznabCatType.TVHD);
AddCategoryMapping(24, TorznabCatType.TVSD);
AddCategoryMapping(25, TorznabCatType.TVSD);
AddCategoryMapping(66, TorznabCatType.TVSD);
AddCategoryMapping(82, TorznabCatType.TVSD);
AddCategoryMapping(65, TorznabCatType.TV);
AddCategoryMapping(83, TorznabCatType.TV);
AddCategoryMapping(79, TorznabCatType.TVSD);
AddCategoryMapping(22, TorznabCatType.TVHD);
AddCategoryMapping(79, TorznabCatType.TVSD);
AddCategoryMapping(4, TorznabCatType.TVSD);
AddCategoryMapping(5, TorznabCatType.TVHD);
AddCategoryMapping(75, TorznabCatType.Audio);
AddCategoryMapping(73, TorznabCatType.Audio);
AddCategoryMapping(80, TorznabCatType.AudioLossless);
AddCategoryMapping(93, TorznabCatType.Audio);
AddCategoryMapping(60, TorznabCatType.Anime);
AddCategoryMapping(1, TorznabCatType.Apps);
AddCategoryMapping(64, TorznabCatType.AudioBooks);
AddCategoryMapping(35, TorznabCatType.Books);
AddCategoryMapping(94, TorznabCatType.Comic);
} }
public Task<ConfigurationData> GetConfigurationForSetup() public Task<ConfigurationData> GetConfigurationForSetup()
@@ -71,8 +112,26 @@ namespace Jackett.Indexers
{ {
var releases = new List<ReleaseInfo>(); var releases = new List<ReleaseInfo>();
var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString(); var searchString = query.SanitizedSearchTerm + " " + query.GetEpisodeSearchString();
var episodeSearchUrl = SearchUrl + HttpUtility.UrlEncode(searchString); var searchUrl = BrowseUrl;
var response = await RequestStringWithCookiesAndRetry(episodeSearchUrl, null, SearchUrl); var trackerCats = MapTorznabCapsToTrackers(query);
var queryCollection = new NameValueCollection();
if (!string.IsNullOrWhiteSpace(searchString))
{
queryCollection.Add("q", searchString);
}
foreach (var cat in MapTorznabCapsToTrackers(query))
{
queryCollection.Add(cat, string.Empty);
}
if (queryCollection.Count > 0)
{
searchUrl += "?" + string.Join("&", queryCollection.AllKeys.Select(a => a + "=" + HttpUtility.UrlEncode(queryCollection[a])));
}
var response = await RequestStringWithCookiesAndRetry(searchUrl, null, BrowseUrl);
var results = response.Content; var results = response.Content;
try try
@@ -111,6 +170,9 @@ namespace Jackett.Indexers
release.Seeders = ParseUtil.CoerceInt(qRow.Find(".t_seeders").Text().Trim()); release.Seeders = ParseUtil.CoerceInt(qRow.Find(".t_seeders").Text().Trim());
release.Peers = ParseUtil.CoerceInt(qRow.Find(".t_leechers").Text().Trim()) + release.Seeders; release.Peers = ParseUtil.CoerceInt(qRow.Find(".t_leechers").Text().Trim()) + release.Seeders;
var cat = row.Cq().Find("td:eq(0) a").First().Attr("href").Substring(1);
release.Category = MapTrackerCatToNewznab(cat);
releases.Add(release); releases.Add(release);
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -46,6 +47,16 @@ namespace Jackett.Models
} }
} }
public JArray CapsToJson()
{
var jArray = new JArray();
foreach (var cat in Categories.GroupBy(p => p.ID).Select(g => g.First()).OrderBy(c=>c.ID))
{
jArray.Add(cat.ToJson());
}
return jArray;
}
public string ToXml() public string ToXml()
{ {
var xdoc = new XDocument( var xdoc = new XDocument(

View File

@@ -20,6 +20,7 @@ namespace Jackett.Models
cats.Add(8020, "Books/Comics"); cats.Add(8020, "Books/Comics");
cats.Add(4000, "PC"); cats.Add(4000, "PC");
cats.Add(3030, "Audio/Audiobook"); cats.Add(3030, "Audio/Audiobook");
cats.Add(2000, "Movies");
cats.Add(2040, "Movies/HD"); cats.Add(2040, "Movies/HD");
cats.Add(2030, "Movies/SD"); cats.Add(2030, "Movies/SD");
cats.Add(2010, "Movies/Foreign"); cats.Add(2010, "Movies/Foreign");
@@ -107,6 +108,11 @@ namespace Jackett.Models
get { return GetCat(3030); } get { return GetCat(3030); }
} }
public static TorznabCategory Movies
{
get { return GetCat(2000); }
}
public static TorznabCategory MoviesHD public static TorznabCategory MoviesHD
{ {
get { return GetCat(2040); } get { return GetCat(2040); }
@@ -114,7 +120,7 @@ namespace Jackett.Models
public static TorznabCategory MoviesSD public static TorznabCategory MoviesSD
{ {
get { return GetCat(2040); } get { return GetCat(2030); }
} }
public static TorznabCategory MoviesForeign public static TorznabCategory MoviesForeign

View File

@@ -1,4 +1,5 @@
using System; using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -17,5 +18,13 @@ namespace Jackett.Models
{ {
SubCategories = new List<TorznabCategory>(); SubCategories = new List<TorznabCategory>();
} }
public JToken ToJson()
{
var t = new JObject();
t["ID"] = ID;
t["Name"] = Name;
return t;
}
} }
} }