diff --git a/src/Jackett.Common/Indexers/MyAnonamouse.cs b/src/Jackett.Common/Indexers/MyAnonamouse.cs index 5a5adac0d..91cc3b9ca 100644 --- a/src/Jackett.Common/Indexers/MyAnonamouse.cs +++ b/src/Jackett.Common/Indexers/MyAnonamouse.cs @@ -5,13 +5,13 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Threading.Tasks; using Jackett.Common.Models; using Jackett.Common.Models.IndexerConfig.Bespoke; using Jackett.Common.Services.Interfaces; using Jackett.Common.Utils; using Jackett.Common.Utils.Clients; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NLog; @@ -169,26 +169,32 @@ namespace Jackett.Common.Indexers protected override async Task> PerformQuery(TorznabQuery query) { - var releases = new List(); + var limit = query.Limit > 0 ? query.Limit : 100; + var offset = query.Offset > 0 ? query.Offset : 0; var qParams = new NameValueCollection { {"tor[text]", query.GetQueryString()}, + {"tor[searchType]", configData.SearchType.Value}, {"tor[srchIn][title]", "true"}, {"tor[srchIn][author]", "true"}, - {"tor[searchType]", configData.ExcludeVip?.Value == true ? "nVIP" : "all"}, // exclude VIP torrents + {"tor[srchIn][narrator]", "true"}, {"tor[searchIn]", "torrents"}, - {"tor[hash]", ""}, {"tor[sortType]", "default"}, - {"tor[startNumber]", "0"}, + {"tor[perpage]", limit.ToString()}, + {"tor[startNumber]", offset.ToString()}, {"thumbnails", "1"}, // gives links for thumbnail sized versions of their posters - //{ "posterLink", "1"}, // gives links for a full sized poster - //{ "dlLink", "1"}, // include the url to download the torrent {"description", "1"} // include the description - //{"bookmarks", "0"} // include if the item is bookmarked or not }; - // Exclude VIP torrents + if (configData.SearchInDescription.Value) + qParams.Add("tor[srchIn][description]", "true"); + + if (configData.SearchInSeries.Value) + qParams.Add("tor[srchIn][series]", "true"); + + if (configData.SearchInFilenames.Value) + qParams.Add("tor[srchIn][filenames]", "true"); var catList = MapTorznabCapsToTrackers(query); if (catList.Any()) @@ -207,10 +213,17 @@ namespace Jackett.Common.Indexers if (qParams.Count > 0) urlSearch += $"?{qParams.GetQueryString()}"; - var response = await RequestWithCookiesAndRetryAsync(urlSearch); + var response = await RequestWithCookiesAndRetryAsync( + urlSearch, + headers: new Dictionary + { + {"Accept", "application/json"} + }); if (response.ContentString.StartsWith("Error")) throw new Exception(response.ContentString); + var releases = new List(); + try { var jsonContent = JObject.Parse(response.ContentString); @@ -222,30 +235,46 @@ namespace Jackett.Common.Indexers foreach (var item in jsonContent.Value("data")) { - //TODO shift to ReleaseInfo object initializer for consistency - var release = new ReleaseInfo(); - var id = item.Value("id"); - release.Title = item.Value("title"); + var link = new Uri(sitelink, "/tor/download.php?tid=" + id); + var details = new Uri(sitelink, "/t/" + id); - release.Description = item.Value("description"); + var release = new ReleaseInfo + { + Guid = details, + Title = item.Value("title").Trim(), + Description = item.Value("description").Trim(), + Link = link, + Details = details, + Category = MapTrackerCatToNewznab(item.Value("category")), + PublishDate = DateTime.ParseExact(item.Value("added"), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime(), + Grabs = item.Value("times_completed"), + Files = item.Value("numfiles"), + Seeders = item.Value("seeders"), + Peers = item.Value("seeders") + item.Value("leechers"), + Size = ReleaseInfo.GetBytes(item.Value("size")), + DownloadVolumeFactor = item.Value("free") ? 0 : 1, + UploadVolumeFactor = 1, + + // MinimumRatio = 1, // global MR is 1.0 but torrents must be seeded for 3 days regardless of ratio + MinimumSeedTime = 259200 // 72 hours + }; var authorInfo = item.Value("author_info"); - string author = null; - if (!string.IsNullOrWhiteSpace(authorInfo)) + if (authorInfo != null) try { - authorInfo = Regex.Unescape(authorInfo); - var authorInfoJson = JObject.Parse(authorInfo); - author = authorInfoJson.First.Last.Value(); + var authorInfoList = JsonConvert.DeserializeObject>(authorInfo); + var author = authorInfoList?.Take(5).Select(v => v.Value).ToList(); + + if (author != null && author.Any()) + release.Title += " by " + string.Join(", ", author); } catch (Exception) { // the JSON on author_info field can be malformed due to double quotes logger.Warn($"{DisplayName} error parsing author_info: {authorInfo}"); } - if (author != null) - release.Title += " by " + author; var flags = new List(); @@ -255,38 +284,14 @@ namespace Jackett.Common.Indexers var filetype = item.Value("filetype"); if (!string.IsNullOrEmpty(filetype)) - flags.Add(filetype); + flags.Add(filetype.ToUpper()); if (flags.Count > 0) release.Title += " [" + string.Join(" / ", flags) + "]"; - if (item.Value("vip") == 1) + if (item.Value("vip")) release.Title += " [VIP]"; - var category = item.Value("category"); - release.Category = MapTrackerCatToNewznab(category); - - release.Link = new Uri(sitelink, "/tor/download.php?tid=" + id); - release.Details = new Uri(sitelink, "/t/" + id); - release.Guid = release.Details; - - var dateStr = item.Value("added"); - var dateTime = DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); - release.PublishDate = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc).ToLocalTime(); - - release.Grabs = item.Value("times_completed"); - release.Files = item.Value("numfiles"); - release.Seeders = item.Value("seeders"); - release.Peers = item.Value("leechers") + release.Seeders; - var size = item.Value("size"); - release.Size = ReleaseInfo.GetBytes(size); - - release.DownloadVolumeFactor = item.Value("free") == 1 ? 0 : 1; - release.UploadVolumeFactor = 1; - - // release.MinimumRatio = 1; // global MR is 1.0 but torrents must be seeded for 3 days regardless of ratio - release.MinimumSeedTime = 259200; // 72 hours - releases.Add(release); } } diff --git a/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataMyAnonamouse.cs b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataMyAnonamouse.cs index e865d2b40..46c7ca2cd 100644 --- a/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataMyAnonamouse.cs +++ b/src/Jackett.Common/Models/IndexerConfig/Bespoke/ConfigurationDataMyAnonamouse.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; namespace Jackett.Common.Models.IndexerConfig.Bespoke @@ -7,16 +8,30 @@ namespace Jackett.Common.Models.IndexerConfig.Bespoke { public StringConfigurationItem MamId { get; private set; } public DisplayInfoConfigurationItem MamIdHint { get; private set; } - public BoolConfigurationItem ExcludeVip { get; private set; } - public DisplayInfoConfigurationItem Instructions { get; private set; } + public SingleSelectConfigurationItem SearchType { get; private set; } + public BoolConfigurationItem SearchInDescription { get; private set; } + public BoolConfigurationItem SearchInSeries { get; private set; } + public BoolConfigurationItem SearchInFilenames { get; private set; } public ConfigurationDataMyAnonamouse() { MamId = new StringConfigurationItem("mam_id"); MamIdHint = new DisplayInfoConfigurationItem("mam_id instructions", "Go to your security preferences and create a new session for the IP used by the Jackett server. Then paste the resulting mam_id value into the mam_id field here."); - ExcludeVip = new BoolConfigurationItem("Exclude VIP torrents"); - Instructions = new DisplayInfoConfigurationItem("", "For best results, change the 'Torrents per page' setting to 100 in your Profile => Torrent tab."); + SearchType = new SingleSelectConfigurationItem( + "Search Type", + new Dictionary + { + { "all", "All torrents" }, + { "active", "Only active" }, + { "fl", "Freeleech" }, + { "fl-VIP", "Freeleech or VIP" }, + { "VIP", "VIP torrents" }, + { "nVIP", "Torrents not VIP" }, + }) + { Value = "all" }; + SearchInDescription = new BoolConfigurationItem("Also search text in the description") { Value = false }; + SearchInSeries = new BoolConfigurationItem("Also search text in the series") { Value = false }; + SearchInFilenames = new BoolConfigurationItem("Also search text in the filenames") { Value = false }; } } - }