myanonamouse: option to exclude vip torrents. resolves #4579 (#9362)

This commit is contained in:
Diego Heras
2020-08-17 19:49:30 +02:00
committed by GitHub
parent 07103a9eaf
commit e940ac4c51
2 changed files with 26 additions and 38 deletions

View File

@@ -8,7 +8,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Jackett.Common.Models; using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig; using Jackett.Common.Models.IndexerConfig.Bespoke;
using Jackett.Common.Services.Interfaces; using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils; using Jackett.Common.Utils;
using Jackett.Common.Utils.Clients; using Jackett.Common.Utils.Clients;
@@ -20,14 +20,9 @@ namespace Jackett.Common.Indexers
[ExcludeFromCodeCoverage] [ExcludeFromCodeCoverage]
public class MyAnonamouse : BaseWebIndexer public class MyAnonamouse : BaseWebIndexer
{ {
private string LoginUrl => SiteLink + "takelogin.php";
private string SearchUrl => SiteLink + "tor/js/loadSearchJSONbasic.php"; private string SearchUrl => SiteLink + "tor/js/loadSearchJSONbasic.php";
private new ConfigurationDataMyAnonamouse configData private new ConfigurationDataMyAnonamouse configData => (ConfigurationDataMyAnonamouse)base.configData;
{
get => (ConfigurationDataMyAnonamouse)base.configData;
set => base.configData = value;
}
public MyAnonamouse(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps) public MyAnonamouse(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps)
: base(id: "myanonamouse", : base(id: "myanonamouse",
@@ -146,15 +141,12 @@ namespace Jackett.Common.Indexers
{ {
LoadValuesFromJson(configJson); LoadValuesFromJson(configJson);
// TODO: implement captcha
CookieHeader = "mam_id=" + configData.MamId.Value; CookieHeader = "mam_id=" + configData.MamId.Value;
try try
{ {
var results = await PerformQuery(new TorznabQuery()); var results = await PerformQuery(new TorznabQuery());
if (results.Count() == 0) if (!results.Any())
{
throw new Exception("Your man_id did not work"); throw new Exception("Your man_id did not work");
}
IsConfigured = true; IsConfigured = true;
SaveConfig(); SaveConfig();
@@ -176,7 +168,7 @@ namespace Jackett.Common.Indexers
{"tor[text]", query.GetQueryString()}, {"tor[text]", query.GetQueryString()},
{"tor[srchIn][title]", "true"}, {"tor[srchIn][title]", "true"},
{"tor[srchIn][author]", "true"}, {"tor[srchIn][author]", "true"},
{"tor[searchType]", "all"}, {"tor[searchType]", configData.ExcludeVip?.Value == true ? "nVIP" : "all"}, // exclude VIP torrents
{"tor[searchIn]", "torrents"}, {"tor[searchIn]", "torrents"},
{"tor[hash]", ""}, {"tor[hash]", ""},
{"tor[sortType]", "default"}, {"tor[sortType]", "default"},
@@ -184,10 +176,12 @@ namespace Jackett.Common.Indexers
{"thumbnails", "1"}, // gives links for thumbnail sized versions of their posters {"thumbnails", "1"}, // gives links for thumbnail sized versions of their posters
//{ "posterLink", "1"}, // gives links for a full sized poster //{ "posterLink", "1"}, // gives links for a full sized poster
//{ "dlLink", "1"}, // include the url to download the torrent //{ "dlLink", "1"}, // include the url to download the torrent
{"description", "1"}, // include the description {"description", "1"} // include the description
//{"bookmarks", "0"} // include if the item is bookmarked or not //{"bookmarks", "0"} // include if the item is bookmarked or not
}; };
// Exclude VIP torrents
var catList = MapTorznabCapsToTrackers(query); var catList = MapTorznabCapsToTrackers(query);
if (catList.Any()) if (catList.Any())
{ {
@@ -199,21 +193,15 @@ namespace Jackett.Common.Indexers
} }
} }
else else
{
qParams.Add("tor[cat][]", "0"); qParams.Add("tor[cat][]", "0");
}
var urlSearch = SearchUrl; var urlSearch = SearchUrl;
if (qParams.Count > 0) if (qParams.Count > 0)
{
urlSearch += $"?{qParams.GetQueryString()}"; urlSearch += $"?{qParams.GetQueryString()}";
}
var response = await RequestStringWithCookiesAndRetry(urlSearch); var response = await RequestStringWithCookiesAndRetry(urlSearch);
if (response.Content.StartsWith("Error")) if (response.Content.StartsWith("Error"))
{
throw new Exception(response.Content); throw new Exception(response.Content);
}
try try
{ {
@@ -221,11 +209,8 @@ namespace Jackett.Common.Indexers
var sitelink = new Uri(SiteLink); var sitelink = new Uri(SiteLink);
var error = jsonContent.Value<string>("error"); var error = jsonContent.Value<string>("error");
if (error != null) if (error != null && error == "Nothing returned, out of 0")
{ return releases;
if (error == "Nothing returned, out of 0")
return releases;
}
foreach (var item in jsonContent.Value<JArray>("data")) foreach (var item in jsonContent.Value<JArray>("data"))
{ {
@@ -237,22 +222,22 @@ namespace Jackett.Common.Indexers
release.Description = item.Value<string>("description"); release.Description = item.Value<string>("description");
var author_info = item.Value<string>("author_info"); var authorInfo = item.Value<string>("author_info");
string author = null; string author = null;
if (!string.IsNullOrWhiteSpace(author_info)) if (!string.IsNullOrWhiteSpace(authorInfo))
{ {
author_info = Regex.Unescape(author_info); authorInfo = Regex.Unescape(authorInfo);
var author_info_json = JObject.Parse(author_info); var authorInfoJson = JObject.Parse(authorInfo);
author = author_info_json.First.Last.Value<string>(); author = authorInfoJson.First.Last.Value<string>();
} }
if (author != null) if (author != null)
release.Title += " by " + author; release.Title += " by " + author;
var flags = new List<string>(); var flags = new List<string>();
var lang_code = item.Value<string>("lang_code"); var langCode = item.Value<string>("lang_code");
if (!string.IsNullOrEmpty(lang_code)) if (!string.IsNullOrEmpty(langCode))
flags.Add(lang_code); flags.Add(langCode);
var filetype = item.Value<string>("filetype"); var filetype = item.Value<string>("filetype");
if (!string.IsNullOrEmpty(filetype)) if (!string.IsNullOrEmpty(filetype))
@@ -261,6 +246,9 @@ namespace Jackett.Common.Indexers
if (flags.Count > 0) if (flags.Count > 0)
release.Title += " [" + string.Join(" / ", flags) + "]"; release.Title += " [" + string.Join(" / ", flags) + "]";
if (item.Value<int>("vip") == 1)
release.Title += " [VIP]";
var category = item.Value<string>("category"); var category = item.Value<string>("category");
release.Category = MapTrackerCatToNewznab(category); release.Category = MapTrackerCatToNewznab(category);
@@ -278,12 +266,8 @@ namespace Jackett.Common.Indexers
release.Peers = item.Value<int>("leechers") + release.Seeders; release.Peers = item.Value<int>("leechers") + release.Seeders;
var size = item.Value<string>("size"); var size = item.Value<string>("size");
release.Size = ReleaseInfo.GetBytes(size); release.Size = ReleaseInfo.GetBytes(size);
var free = item.Value<int>("free");
if (free == 1) release.DownloadVolumeFactor = item.Value<int>("free") == 1 ? 0 : 1;
release.DownloadVolumeFactor = 0;
else
release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1; release.UploadVolumeFactor = 1;
releases.Add(release); releases.Add(release);

View File

@@ -1,10 +1,12 @@
namespace Jackett.Common.Models.IndexerConfig namespace Jackett.Common.Models.IndexerConfig.Bespoke
{ {
public class ConfigurationDataMyAnonamouse : ConfigurationData public class ConfigurationDataMyAnonamouse : ConfigurationData
{ {
public StringItem MamId { get; private set; } public StringItem MamId { get; private set; }
public DisplayItem MamIdHint { get; private set; } public DisplayItem MamIdHint { get; private set; }
public BoolItem ExcludeVip { get; private set; }
public DisplayItem Instructions { get; private set; }
public ConfigurationDataMyAnonamouse() public ConfigurationDataMyAnonamouse()
{ {
@@ -14,6 +16,8 @@ namespace Jackett.Common.Models.IndexerConfig
{ {
Name = "mam_id instructions" Name = "mam_id instructions"
}; };
ExcludeVip = new BoolItem { Name = "Exclude VIP torrents" };
Instructions = new DisplayItem("For best results, change the 'Torrents per page' setting to 100 in your Profile => Torrent tab.") { Name = "" };
} }
} }