From 63cf687f02828aa7197bd53f98e347ebde3dc2b5 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Tue, 17 Oct 2017 11:15:09 +0200 Subject: [PATCH] Animebytes: add AddSynonyms and FilterSeasonEpisode options --- src/Jackett/Indexers/AnimeBytes.cs | 34 ++++++++++++++++--- .../Bespoke/ConfigurationDataAnimeBytes.cs | 4 +++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Jackett/Indexers/AnimeBytes.cs b/src/Jackett/Indexers/AnimeBytes.cs index d969852f7..11f7159bc 100644 --- a/src/Jackett/Indexers/AnimeBytes.cs +++ b/src/Jackett/Indexers/AnimeBytes.cs @@ -35,6 +35,8 @@ namespace Jackett.Indexers private string MusicSearchUrl { get { return SiteLink + "torrents2.php?"; } } public bool AllowRaws { get { return configData.IncludeRaw.Value; } } public bool InsertSeason { get { return configData.InsertSeason != null && configData.InsertSeason.Value; } } + public bool AddSynonyms { get { return configData.AddSynonyms.Value; } } + public bool FilterSeasonEpisode { get { return configData.FilterSeasonEpisode.Value; } } new ConfigurationDataAnimeBytes configData { @@ -136,13 +138,13 @@ namespace Jackett.Indexers if (ContainsMusicCategories(query.Categories)) { - foreach (var result in await GetResults(SearchType.Audio, query.SanitizedSearchTerm)) + foreach (var result in await GetResults(query, SearchType.Audio, query.SanitizedSearchTerm)) { releases.Add(result); } } - foreach (var result in await GetResults(SearchType.Video, StripEpisodeNumber(query.SanitizedSearchTerm))) + foreach (var result in await GetResults(query, SearchType.Video, StripEpisodeNumber(query.SanitizedSearchTerm))) { releases.Add(result); } @@ -164,7 +166,7 @@ namespace Jackett.Indexers return categories.Length == 0 || music.Any(categories.Contains); } - private async Task> GetResults(SearchType searchType, string searchTerm) + private async Task> GetResults(TorznabQuery query, SearchType searchType, string searchTerm) { var cleanSearchTerm = HttpUtility.UrlEncode(searchTerm); @@ -232,7 +234,7 @@ namespace Jackett.Indexers synonyms.Add(mainTitle); // If the title contains a comma then we can't use the synonyms as they are comma seperated - if (!mainTitle.Contains(",")) + if (!mainTitle.Contains(",") && AddSynonyms) { var symnomnNames = string.Empty; foreach (var e in seriesCq.Find(".group_statbox li")) @@ -259,16 +261,20 @@ namespace Jackett.Indexers foreach (var title in synonyms) { var releaseRows = seriesCq.Find(".torrent_group tr"); + string episode = null; + int? season = null; // Skip the first two info rows for (int r = 1; r < releaseRows.Count(); r++) { + var row = releaseRows.Get(r); var rowCq = row.Cq(); if (rowCq.HasClass("edition_info")) { + episode = null; + season = null; releaseInfo = rowCq.Find("td").Text(); - if (string.IsNullOrWhiteSpace(releaseInfo)) { // Single episodes alpha - Reported that this info is missing. @@ -276,6 +282,16 @@ namespace Jackett.Indexers break; } + Regex SeasonRegEx = new Regex(@"Season (\d+)", RegexOptions.Compiled); + var SeasonRegExMatch = SeasonRegEx.Match(releaseInfo); + if (SeasonRegExMatch.Success) + season = ParseUtil.CoerceInt(SeasonRegExMatch.Groups[1].Value); + + Regex EpisodeRegEx = new Regex(@"Episode (\d+)", RegexOptions.Compiled); + var EpisodeRegExMatch = EpisodeRegEx.Match(releaseInfo); + if (EpisodeRegExMatch.Success) + episode = EpisodeRegExMatch.Groups[1].Value; + releaseInfo = releaseInfo.Replace("Episode ", ""); releaseInfo = releaseInfo.Replace("Season ", "S"); releaseInfo = releaseInfo.Trim(); @@ -295,6 +311,14 @@ namespace Jackett.Indexers continue; } + if (FilterSeasonEpisode) + { + if (query.Season != 0 && season != null && season != query.Season) // skip if season doesn't match + continue; + if (query.Episode != null && episode != null && episode != query.Episode) // skip if episode doesn't match + continue; + } + var release = new ReleaseInfo(); release.MinimumRatio = 1; release.MinimumSeedTime = 259200; diff --git a/src/Jackett/Models/IndexerConfig/Bespoke/ConfigurationDataAnimeBytes.cs b/src/Jackett/Models/IndexerConfig/Bespoke/ConfigurationDataAnimeBytes.cs index 8ff00e5df..b4e846d23 100644 --- a/src/Jackett/Models/IndexerConfig/Bespoke/ConfigurationDataAnimeBytes.cs +++ b/src/Jackett/Models/IndexerConfig/Bespoke/ConfigurationDataAnimeBytes.cs @@ -12,6 +12,8 @@ namespace Jackett.Models.IndexerConfig.Bespoke public BoolItem IncludeRaw { get; private set; } public DisplayItem DateWarning { get; private set; } public BoolItem InsertSeason { get; private set; } + public BoolItem AddSynonyms { get; private set; } + public BoolItem FilterSeasonEpisode { get; private set; } public ConfigurationDataAnimeBytes() : base() @@ -19,6 +21,8 @@ namespace Jackett.Models.IndexerConfig.Bespoke IncludeRaw = new BoolItem() { Name = "IncludeRaw", Value = false }; DateWarning = new DisplayItem("This tracker does not supply upload dates so they are based off year of release.") { Name = "DateWarning" }; InsertSeason = new BoolItem() { Name = "Prefix episode number with E0 for Sonarr Compatability", Value = false }; + AddSynonyms = new BoolItem() { Name = "Add releases for each synonym title", Value = true }; + FilterSeasonEpisode = new BoolItem() { Name = "Filter results by season/episode", Value = false }; } } }