Improve season query logic for bB (#1632)

* Tweak BB indexer

Remove explicit tracker URL
Add tracker-specific season query

* Query for "S##" and "Season #" simultaneously on bB

* Fix tabs/spaces

* Rewrite title from "Season #" to "S##"

* Fix bug

Fix bug where searching for whole shows would rewrite Season # to S00, since no season was specified.

* Add new categories mappings

So that e.g. headphones can correctly query bB for music
This commit is contained in:
mueslo 2017-08-10 08:19:27 +02:00 committed by kaso17
parent 720b5971d3
commit 2e79500f50
1 changed files with 98 additions and 76 deletions

View File

@ -11,6 +11,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web; using System.Web;
using Jackett.Models.IndexerConfig; using Jackett.Models.IndexerConfig;
@ -36,7 +37,7 @@ namespace Jackett.Indexers
public BB(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps) public BB(IIndexerConfigurationService configService, IWebClient w, Logger l, IProtectionService ps)
: base(name: "bB", : base(name: "bB",
description: "bB", description: "bB",
link: "https://baconbits.org/", link: StringUtil.FromBase64("aHR0cHM6Ly9iYWNvbmJpdHMub3JnLw=="),
caps: new TorznabCapabilities(), caps: new TorznabCapabilities(),
configService: configService, configService: configService,
client: w, client: w,
@ -49,6 +50,8 @@ namespace Jackett.Indexers
Type = "private"; Type = "private";
AddCategoryMapping(1, TorznabCatType.Audio); AddCategoryMapping(1, TorznabCatType.Audio);
AddCategoryMapping(1, TorznabCatType.AudioMP3);
AddCategoryMapping(1, TorznabCatType.AudioLossless);
AddCategoryMapping(2, TorznabCatType.PC); AddCategoryMapping(2, TorznabCatType.PC);
AddCategoryMapping(3, TorznabCatType.BooksEbook); AddCategoryMapping(3, TorznabCatType.BooksEbook);
AddCategoryMapping(4, TorznabCatType.AudioAudiobook); AddCategoryMapping(4, TorznabCatType.AudioAudiobook);
@ -92,11 +95,18 @@ namespace Jackett.Indexers
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{ {
List<ReleaseInfo> releases = new List<ReleaseInfo>(); List<ReleaseInfo> releases = new List<ReleaseInfo>();
List<string> searchStrings = new List<string>(new string[] { query.GetQueryString() });
var searchString = query.GetQueryString(); if (string.IsNullOrEmpty(query.Episode) && (query.Season > 0))
var searchUrl = SearchUrl; // Tracker naming rules: If query is for a whole season, "Season #" instead of "S##".
searchStrings.Add((query.SanitizedSearchTerm + " " + string.Format("\"Season {0}\"", query.Season)).Trim());
List<string> categories = MapTorznabCapsToTrackers(query);
List<string> request_urls = new List<string>();
foreach (var searchString in searchStrings)
{
var queryCollection = new NameValueCollection(); var queryCollection = new NameValueCollection();
queryCollection.Add("action", "basic"); queryCollection.Add("action", "basic");
if (!string.IsNullOrWhiteSpace(searchString)) if (!string.IsNullOrWhiteSpace(searchString))
@ -104,22 +114,28 @@ namespace Jackett.Indexers
queryCollection.Add("searchstr", searchString); queryCollection.Add("searchstr", searchString);
} }
foreach (var cat in MapTorznabCapsToTrackers(query)) foreach (var cat in categories)
{ {
queryCollection.Add("filter_cat[" + cat + "]", "1"); queryCollection.Add("filter_cat[" + cat + "]", "1");
} }
searchUrl += queryCollection.GetQueryString(); request_urls.Add(SearchUrl + queryCollection.GetQueryString());
}
IEnumerable<Task<WebClientStringResult>> downloadTasksQuery =
from url in request_urls select RequestStringWithCookiesAndRetry(url);
var results = await RequestStringWithCookiesAndRetry(searchUrl); WebClientStringResult[] responses = await Task.WhenAll(downloadTasksQuery.ToArray());
for (int i = 0; i < searchStrings.Count(); i++)
{
var results = responses[i];
// Occasionally the cookies become invalid, login again if that happens // Occasionally the cookies become invalid, login again if that happens
if (results.IsRedirect) if (results.IsRedirect)
{ {
await ApplyConfiguration(null); await ApplyConfiguration(null);
results = await RequestStringWithCookiesAndRetry(searchUrl); results = await RequestStringWithCookiesAndRetry(request_urls[i]);
} }
try try
{ {
CQ dom = results.Content; CQ dom = results.Content;
@ -166,8 +182,13 @@ namespace Jackett.Indexers
var title = qRow.Find("td:nth-child(2)"); var title = qRow.Find("td:nth-child(2)");
title.Find("span, strong, div, br").Remove(); title.Find("span, strong, div, br").Remove();
release.Title = ParseUtil.NormalizeMultiSpaces(title.Text().Replace(" - ]", "]")); release.Title = ParseUtil.NormalizeMultiSpaces(title.Text().Replace(" - ]", "]"));
if (catStr == "10") //change "Season #" to "S##" for TV shows
release.Title = Regex.Replace(release.Title, @"Season (\d+)",
m => string.Format("S{0:00}", Int32.Parse(m.Groups[1].Value)));
releases.Add(release); releases.Add(release);
} }
} }
@ -175,6 +196,7 @@ namespace Jackett.Indexers
{ {
OnParseError(results.Content, ex); OnParseError(results.Content, ex);
} }
}
return releases; return releases;
} }
} }