From 3cb436898a85fde5def077adc3adaf5310c39908 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 1 Mar 2021 21:36:29 -0500 Subject: [PATCH] Fixed: HDBits and Filelist --- .../Indexers/Definitions/FileList/FileList.cs | 55 ++++++++++++++++ .../Definitions/FileList/FileListApi.cs | 2 + .../Definitions/FileList/FileListParser.cs | 11 +++- .../FileList/FileListRequestGenerator.cs | 59 +++++++++++++++-- .../Indexers/Definitions/HDBits/HDBits.cs | 29 ++++++++ .../Indexers/Definitions/HDBits/HDBitsApi.cs | 4 +- .../Definitions/HDBits/HDBitsParser.cs | 3 + .../HDBits/HDBitsRequestGenerator.cs | 66 ++++++++++++++----- src/NzbDrone.Core/Localization/Core/en.json | 2 + src/Prowlarr.Api.V1/Indexers/IndexerModule.cs | 1 - 10 files changed, 207 insertions(+), 25 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileList.cs b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileList.cs index 26f79a38f..3f3a90cfe 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileList.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileList.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using NLog; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; @@ -12,6 +13,8 @@ namespace NzbDrone.Core.Indexers.FileList public override IndexerPrivacy Privacy => IndexerPrivacy.Private; public override bool SupportsRss => true; public override bool SupportsSearch => true; + public override bool SupportsRedirect => true; + public override IndexerCapabilities Capabilities => SetCapabilities(); public FileList(IHttpClient httpClient, IIndexerStatusService indexerStatusService, IConfigService configService, Logger logger) : base(httpClient, indexerStatusService, configService, logger) @@ -27,5 +30,57 @@ namespace NzbDrone.Core.Indexers.FileList { return new FileListParser(Settings, BaseUrl); } + + private IndexerCapabilities SetCapabilities() + { + var caps = new IndexerCapabilities + { + TvSearchParams = new List + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep + }, + MovieSearchParams = new List + { + MovieSearchParam.Q, MovieSearchParam.ImdbId + }, + MusicSearchParams = new List + { + MusicSearchParam.Q + }, + BookSearchParams = new List + { + BookSearchParam.Q + } + }; + + caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.MoviesSD, "Filme SD"); + caps.Categories.AddCategoryMapping(2, NewznabStandardCategory.MoviesDVD, "Filme DVD"); + caps.Categories.AddCategoryMapping(3, NewznabStandardCategory.MoviesForeign, "Filme DVD-RO"); + caps.Categories.AddCategoryMapping(4, NewznabStandardCategory.MoviesHD, "Filme HD"); + caps.Categories.AddCategoryMapping(5, NewznabStandardCategory.AudioLossless, "FLAC"); + caps.Categories.AddCategoryMapping(6, NewznabStandardCategory.MoviesUHD, "Filme 4K"); + caps.Categories.AddCategoryMapping(7, NewznabStandardCategory.XXX, "XXX"); + caps.Categories.AddCategoryMapping(8, NewznabStandardCategory.PC, "Programe"); + caps.Categories.AddCategoryMapping(9, NewznabStandardCategory.PCGames, "Jocuri PC"); + caps.Categories.AddCategoryMapping(10, NewznabStandardCategory.Console, "Jocuri Console"); + caps.Categories.AddCategoryMapping(11, NewznabStandardCategory.Audio, "Audio"); + caps.Categories.AddCategoryMapping(12, NewznabStandardCategory.AudioVideo, "Videoclip"); + caps.Categories.AddCategoryMapping(13, NewznabStandardCategory.TVSport, "Sport"); + caps.Categories.AddCategoryMapping(15, NewznabStandardCategory.TV, "Desene"); + caps.Categories.AddCategoryMapping(16, NewznabStandardCategory.Books, "Docs"); + caps.Categories.AddCategoryMapping(17, NewznabStandardCategory.PC, "Linux"); + caps.Categories.AddCategoryMapping(18, NewznabStandardCategory.Other, "Diverse"); + caps.Categories.AddCategoryMapping(19, NewznabStandardCategory.MoviesForeign, "Filme HD-RO"); + caps.Categories.AddCategoryMapping(20, NewznabStandardCategory.MoviesBluRay, "Filme Blu-Ray"); + caps.Categories.AddCategoryMapping(21, NewznabStandardCategory.TVHD, "Seriale HD"); + caps.Categories.AddCategoryMapping(22, NewznabStandardCategory.PCMobileOther, "Mobile"); + caps.Categories.AddCategoryMapping(23, NewznabStandardCategory.TVSD, "Seriale SD"); + caps.Categories.AddCategoryMapping(24, NewznabStandardCategory.TVAnime, "Anime"); + caps.Categories.AddCategoryMapping(25, NewznabStandardCategory.Movies3D, "Filme 3D"); + caps.Categories.AddCategoryMapping(26, NewznabStandardCategory.MoviesBluRay, "Filme 4K Blu-Ray"); + caps.Categories.AddCategoryMapping(27, NewznabStandardCategory.TVUHD, "Seriale 4K"); + + return caps; + } } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListApi.cs b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListApi.cs index eea73fae6..6a8031915 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListApi.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListApi.cs @@ -18,6 +18,8 @@ namespace NzbDrone.Core.Indexers.FileList public string ImdbId { get; set; } [JsonProperty(PropertyName = "freeleech")] public bool FreeLeech { get; set; } + [JsonProperty(PropertyName = "doubleup")] + public bool DoubleUp { get; set; } [JsonProperty(PropertyName = "upload_date")] public DateTime UploadDate { get; set; } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListParser.cs b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListParser.cs index 518597bab..ab58fe849 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListParser.cs @@ -49,6 +49,9 @@ namespace NzbDrone.Core.Indexers.FileList imdbId = int.Parse(result.ImdbId.Substring(2)); } + var downloadVolumeFactor = result.FreeLeech == true ? 0 : 1; + var uploadVolumeFactor = result.DoubleUp == true ? 2 : 1; + torrentInfos.Add(new TorrentInfo() { Guid = string.Format("FileList-{0}", id), @@ -60,7 +63,13 @@ namespace NzbDrone.Core.Indexers.FileList Peers = result.Leechers + result.Seeders, PublishDate = result.UploadDate, ImdbId = imdbId, - IndexerFlags = flags + IndexerFlags = flags, + Files = (int)result.Files, + Grabs = (int)result.TimesCompleted, + DownloadVolumeFactor = downloadVolumeFactor, + UploadVolumeFactor = uploadVolumeFactor, + MinimumRatio = 1, + MinimumSeedTime = 172800, //48 hours }); } diff --git a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListRequestGenerator.cs index c2e0ece8a..f0b166bad 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListRequestGenerator.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.Indexers.FileList } else if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) { - var titleYearSearchQuery = string.Format("{0}", searchCriteria.SearchTerm); + var titleYearSearchQuery = string.Format("{0}", searchCriteria.SanitizedSearchTerm); pageableRequests.Add(GetRequest("search-torrents", searchCriteria.Categories, string.Format("&type=name&query={0}", titleYearSearchQuery.Trim()))); } else @@ -37,22 +37,71 @@ namespace NzbDrone.Core.Indexers.FileList public IndexerPageableRequestChain GetSearchRequests(MusicSearchCriteria searchCriteria) { - return new IndexerPageableRequestChain(); + var pageableRequests = new IndexerPageableRequestChain(); + if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) + { + var titleYearSearchQuery = string.Format("{0}", searchCriteria.SanitizedSearchTerm); + pageableRequests.Add(GetRequest("search-torrents", searchCriteria.Categories, string.Format("&type=name&query={0}", titleYearSearchQuery.Trim()))); + } + else + { + pageableRequests.Add(GetRequest("latest-torrents", searchCriteria.Categories, "")); + } + + return pageableRequests; } public IndexerPageableRequestChain GetSearchRequests(TvSearchCriteria searchCriteria) { - return new IndexerPageableRequestChain(); + var pageableRequests = new IndexerPageableRequestChain(); + + if (searchCriteria.ImdbId.IsNotNullOrWhiteSpace()) + { + pageableRequests.Add(GetRequest("search-torrents", searchCriteria.Categories, string.Format("&type=imdb&query={0}&season={1}&episode={2}", searchCriteria.ImdbId, searchCriteria.Season, searchCriteria.Episode))); + } + else if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) + { + var titleYearSearchQuery = string.Format("{0}", searchCriteria.SanitizedSearchTerm); + pageableRequests.Add(GetRequest("search-torrents", searchCriteria.Categories, string.Format("&type=name&query={0}&season={1}&episode={2}", titleYearSearchQuery.Trim(), searchCriteria.Season, searchCriteria.Episode))); + } + else + { + pageableRequests.Add(GetRequest("latest-torrents", searchCriteria.Categories, "")); + } + + return pageableRequests; } public IndexerPageableRequestChain GetSearchRequests(BookSearchCriteria searchCriteria) { - return new IndexerPageableRequestChain(); + var pageableRequests = new IndexerPageableRequestChain(); + if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) + { + var titleYearSearchQuery = string.Format("{0}", searchCriteria.SanitizedSearchTerm); + pageableRequests.Add(GetRequest("search-torrents", searchCriteria.Categories, string.Format("&type=name&query={0}", titleYearSearchQuery.Trim()))); + } + else + { + pageableRequests.Add(GetRequest("latest-torrents", searchCriteria.Categories, "")); + } + + return pageableRequests; } public IndexerPageableRequestChain GetSearchRequests(BasicSearchCriteria searchCriteria) { - return new IndexerPageableRequestChain(); + var pageableRequests = new IndexerPageableRequestChain(); + if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) + { + var titleYearSearchQuery = string.Format("{0}", searchCriteria.SanitizedSearchTerm); + pageableRequests.Add(GetRequest("search-torrents", searchCriteria.Categories, string.Format("&type=name&query={0}", titleYearSearchQuery.Trim()))); + } + else + { + pageableRequests.Add(GetRequest("latest-torrents", searchCriteria.Categories, "")); + } + + return pageableRequests; } private IEnumerable GetRequest(string searchType, int[] categories, string parameters) diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBits.cs b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBits.cs index f498f0018..5f75c0f68 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBits.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBits.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using NLog; using NzbDrone.Common.Http; using NzbDrone.Core.Configuration; @@ -10,6 +11,8 @@ namespace NzbDrone.Core.Indexers.HDBits public override string BaseUrl => "https://hdbits.org"; public override DownloadProtocol Protocol => DownloadProtocol.Torrent; public override IndexerPrivacy Privacy => IndexerPrivacy.Private; + public override IndexerCapabilities Capabilities => SetCapabilities(); + public override bool SupportsRedirect => true; public override int PageSize => 30; @@ -27,5 +30,31 @@ namespace NzbDrone.Core.Indexers.HDBits { return new HDBitsParser(Settings, BaseUrl); } + + private IndexerCapabilities SetCapabilities() + { + var caps = new IndexerCapabilities + { + TvSearchParams = new List + { + TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep, TvSearchParam.TvdbId + }, + MovieSearchParams = new List + { + MovieSearchParam.Q, MovieSearchParam.ImdbId + } + }; + + caps.Categories.AddCategoryMapping(6, NewznabStandardCategory.Audio, "Audio Track"); + caps.Categories.AddCategoryMapping(3, NewznabStandardCategory.TVDocumentary, "Documentary"); + caps.Categories.AddCategoryMapping(8, NewznabStandardCategory.Other, "Misc/Demo"); + caps.Categories.AddCategoryMapping(1, NewznabStandardCategory.Movies, "Movie"); + caps.Categories.AddCategoryMapping(4, NewznabStandardCategory.Audio, "Music"); + caps.Categories.AddCategoryMapping(5, NewznabStandardCategory.TVSport, "Sport"); + caps.Categories.AddCategoryMapping(2, NewznabStandardCategory.TV, "TV"); + caps.Categories.AddCategoryMapping(7, NewznabStandardCategory.XXX, "XXX"); + + return caps; + } } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsApi.cs b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsApi.cs index 38b64fc91..4a8c9e588 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsApi.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsApi.cs @@ -1,4 +1,4 @@ -using System; +using System; using Newtonsoft.Json; namespace NzbDrone.Core.Indexers.HDBits @@ -113,7 +113,7 @@ namespace NzbDrone.Core.Indexers.HDBits { public int? Id { get; set; } public int? Season { get; set; } - public int? Episode { get; set; } + public string Episode { get; set; } } public enum StatusCode diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsParser.cs b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsParser.cs index 5bba237a9..009b0a2d0 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsParser.cs @@ -76,10 +76,13 @@ namespace NzbDrone.Core.Indexers.HDBits DownloadUrl = GetDownloadUrl(id), InfoUrl = GetInfoUrl(id), Seeders = result.Seeders, + Grabs = (int)result.TimesCompleted, + Files = (int)result.NumFiles, Peers = result.Leechers + result.Seeders, PublishDate = result.Added.ToUniversalTime(), Internal = internalRelease, ImdbId = result.ImdbInfo?.Id ?? 0, + TvdbId = result.TvdbInfo?.Id ?? 0, IndexerFlags = flags }); } diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsRequestGenerator.cs b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsRequestGenerator.cs index 1c194ef8c..82775c6b4 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsRequestGenerator.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsRequestGenerator.cs @@ -10,6 +10,7 @@ namespace NzbDrone.Core.Indexers.HDBits { public class HDBitsRequestGenerator : IIndexerRequestGenerator { + public IndexerCapabilities Capabilities { get; set; } public HDBitsSettings Settings { get; set; } public string BaseUrl { get; set; } @@ -18,19 +19,14 @@ namespace NzbDrone.Core.Indexers.HDBits var pageableRequests = new IndexerPageableRequestChain(); var query = new TorrentQuery(); - if (TryAddSearchParameters(query, searchCriteria)) + if (searchCriteria.Categories.Length > 0) { - pageableRequests.Add(GetRequest(query)); + query.Category = Capabilities.Categories.MapTorznabCapsToTrackers(searchCriteria.Categories).Select(int.Parse).ToArray(); } - return pageableRequests; - } - - private bool TryAddSearchParameters(TorrentQuery query, MovieSearchCriteria searchCriteria) - { - if (searchCriteria.ImdbId.IsNullOrWhiteSpace()) + if (searchCriteria.ImdbId.IsNullOrWhiteSpace() && searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) { - return false; + query.Search = searchCriteria.SanitizedSearchTerm; } var imdbId = int.Parse(searchCriteria.ImdbId.Substring(2)); @@ -39,13 +35,11 @@ namespace NzbDrone.Core.Indexers.HDBits { query.ImdbInfo = query.ImdbInfo ?? new ImdbInfo(); query.ImdbInfo.Id = imdbId; - - //TODO Map Categories - query.Category = searchCriteria.Categories; - return true; } - return false; + pageableRequests.Add(GetRequest(query)); + + return pageableRequests; } public Func> GetCookies { get; set; } @@ -82,7 +76,32 @@ namespace NzbDrone.Core.Indexers.HDBits public IndexerPageableRequestChain GetSearchRequests(TvSearchCriteria searchCriteria) { - return new IndexerPageableRequestChain(); + var pageableRequests = new IndexerPageableRequestChain(); + var query = new TorrentQuery(); + + if (searchCriteria.Categories.Length > 0) + { + query.Category = Capabilities.Categories.MapTorznabCapsToTrackers(searchCriteria.Categories).Select(int.Parse).ToArray(); + } + + if (searchCriteria.TvdbId == 0 && searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) + { + query.Search = (searchCriteria.SanitizedSearchTerm + " " + searchCriteria.EpisodeSearchString).Trim(); + } + + var tvdbId = searchCriteria.TvdbId; + + if (tvdbId != 0) + { + query.TvdbInfo = query.TvdbInfo ?? new TvdbInfo(); + query.TvdbInfo.Id = tvdbId; + query.TvdbInfo.Season = searchCriteria.Season; + query.TvdbInfo.Episode = searchCriteria.Episode; + } + + pageableRequests.Add(GetRequest(query)); + + return pageableRequests; } public IndexerPageableRequestChain GetSearchRequests(BookSearchCriteria searchCriteria) @@ -92,7 +111,22 @@ namespace NzbDrone.Core.Indexers.HDBits public IndexerPageableRequestChain GetSearchRequests(BasicSearchCriteria searchCriteria) { - return new IndexerPageableRequestChain(); + var pageableRequests = new IndexerPageableRequestChain(); + var query = new TorrentQuery(); + + if (searchCriteria.Categories.Length > 0) + { + query.Category = Capabilities.Categories.MapTorznabCapsToTrackers(searchCriteria.Categories).Select(int.Parse).ToArray(); + } + + if (searchCriteria.SearchTerm.IsNotNullOrWhiteSpace()) + { + query.Search = searchCriteria.SanitizedSearchTerm; + } + + pageableRequests.Add(GetRequest(query)); + + return pageableRequests; } } } diff --git a/src/NzbDrone.Core/Localization/Core/en.json b/src/NzbDrone.Core/Localization/Core/en.json index 9bbfaaf05..2e03c842e 100644 --- a/src/NzbDrone.Core/Localization/Core/en.json +++ b/src/NzbDrone.Core/Localization/Core/en.json @@ -220,6 +220,7 @@ "EnableCompletedDownloadHandlingHelpText": "Automatically import completed downloads from download client", "EnabledHelpText": "Enable this list for use in Prowlarr", "EnableHelpText": "Enable metadata file creation for this metadata type", + "EnableIndexer": "Enable Indexer", "EnableInteractiveSearch": "Enable Interactive Search", "EnableInteractiveSearchHelpText": "Will be used when interactive search is used", "EnableInteractiveSearchHelpTextWarning": "Search is not supported with this indexer", @@ -336,6 +337,7 @@ "IndexerLongTermStatusCheckSingleClientMessage": "Indexers unavailable due to failures for more than 6 hours: {0}", "IndexerPriority": "Indexer Priority", "IndexerPriorityHelpText": "Indexer Priority from 1 (Highest) to 50 (Lowest). Default: 25.", + "IndexerQuery": "Indexer Query", "IndexerRssHealthCheckNoAvailableIndexers": "All rss-capable indexers are temporarily unavailable due to recent indexer errors", "IndexerRssHealthCheckNoIndexers": "No indexers available with RSS sync enabled, Prowlarr will not grab new releases automatically", "Indexers": "Indexers", diff --git a/src/Prowlarr.Api.V1/Indexers/IndexerModule.cs b/src/Prowlarr.Api.V1/Indexers/IndexerModule.cs index 4d3c0e29d..9f3adb505 100644 --- a/src/Prowlarr.Api.V1/Indexers/IndexerModule.cs +++ b/src/Prowlarr.Api.V1/Indexers/IndexerModule.cs @@ -4,7 +4,6 @@ using System.Net; using System.Text; using Nancy; using Nancy.ModelBinding; -using Nancy.Responses; using NzbDrone.Common.Extensions; using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch;