Skip to content

Commit

Permalink
myanonamouse: option to exclude vip torrents. resolves #4579 (#9362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosang committed Aug 17, 2020
1 parent 07103a9 commit e940ac4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
58 changes: 21 additions & 37 deletions src/Jackett.Common/Indexers/MyAnonamouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig;
using Jackett.Common.Models.IndexerConfig.Bespoke;
using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils;
using Jackett.Common.Utils.Clients;
Expand All @@ -20,14 +20,9 @@ namespace Jackett.Common.Indexers
[ExcludeFromCodeCoverage]
public class MyAnonamouse : BaseWebIndexer
{
private string LoginUrl => SiteLink + "takelogin.php";
private string SearchUrl => SiteLink + "tor/js/loadSearchJSONbasic.php";

private new ConfigurationDataMyAnonamouse configData
{
get => (ConfigurationDataMyAnonamouse)base.configData;
set => base.configData = value;
}
private new ConfigurationDataMyAnonamouse configData => (ConfigurationDataMyAnonamouse)base.configData;

public MyAnonamouse(IIndexerConfigurationService configService, WebClient c, Logger l, IProtectionService ps)
: base(id: "myanonamouse",
Expand Down Expand Up @@ -146,15 +141,12 @@ public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken
{
LoadValuesFromJson(configJson);

// TODO: implement captcha
CookieHeader = "mam_id=" + configData.MamId.Value;
try
{
var results = await PerformQuery(new TorznabQuery());
if (results.Count() == 0)
{
if (!results.Any())
throw new Exception("Your man_id did not work");
}

IsConfigured = true;
SaveConfig();
Expand All @@ -176,18 +168,20 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
{"tor[text]", query.GetQueryString()},
{"tor[srchIn][title]", "true"},
{"tor[srchIn][author]", "true"},
{"tor[searchType]", "all"},
{"tor[searchType]", configData.ExcludeVip?.Value == true ? "nVIP" : "all"}, // exclude VIP torrents
{"tor[searchIn]", "torrents"},
{"tor[hash]", ""},
{"tor[sortType]", "default"},
{"tor[startNumber]", "0"},
{"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
{"description", "1"} // include the description
//{"bookmarks", "0"} // include if the item is bookmarked or not
};

// Exclude VIP torrents

var catList = MapTorznabCapsToTrackers(query);
if (catList.Any())
{
Expand All @@ -199,33 +193,24 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
}
}
else
{
qParams.Add("tor[cat][]", "0");
}

var urlSearch = SearchUrl;
if (qParams.Count > 0)
{
urlSearch += $"?{qParams.GetQueryString()}";
}

var response = await RequestStringWithCookiesAndRetry(urlSearch);
if (response.Content.StartsWith("Error"))
{
throw new Exception(response.Content);
}

try
{
var jsonContent = JObject.Parse(response.Content);
var sitelink = new Uri(SiteLink);

var error = jsonContent.Value<string>("error");
if (error != null)
{
if (error == "Nothing returned, out of 0")
return releases;
}
if (error != null && error == "Nothing returned, out of 0")
return releases;

foreach (var item in jsonContent.Value<JArray>("data"))
{
Expand All @@ -237,22 +222,22 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer

release.Description = item.Value<string>("description");

var author_info = item.Value<string>("author_info");
var authorInfo = item.Value<string>("author_info");
string author = null;
if (!string.IsNullOrWhiteSpace(author_info))
if (!string.IsNullOrWhiteSpace(authorInfo))
{
author_info = Regex.Unescape(author_info);
var author_info_json = JObject.Parse(author_info);
author = author_info_json.First.Last.Value<string>();
authorInfo = Regex.Unescape(authorInfo);
var authorInfoJson = JObject.Parse(authorInfo);
author = authorInfoJson.First.Last.Value<string>();
}
if (author != null)
release.Title += " by " + author;

var flags = new List<string>();

var lang_code = item.Value<string>("lang_code");
if (!string.IsNullOrEmpty(lang_code))
flags.Add(lang_code);
var langCode = item.Value<string>("lang_code");
if (!string.IsNullOrEmpty(langCode))
flags.Add(langCode);

var filetype = item.Value<string>("filetype");
if (!string.IsNullOrEmpty(filetype))
Expand All @@ -261,6 +246,9 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
if (flags.Count > 0)
release.Title += " [" + string.Join(" / ", flags) + "]";

if (item.Value<int>("vip") == 1)
release.Title += " [VIP]";

var category = item.Value<string>("category");
release.Category = MapTrackerCatToNewznab(category);

Expand All @@ -278,12 +266,8 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
release.Peers = item.Value<int>("leechers") + release.Seeders;
var size = item.Value<string>("size");
release.Size = ReleaseInfo.GetBytes(size);
var free = item.Value<int>("free");

if (free == 1)
release.DownloadVolumeFactor = 0;
else
release.DownloadVolumeFactor = 1;
release.DownloadVolumeFactor = item.Value<int>("free") == 1 ? 0 : 1;
release.UploadVolumeFactor = 1;

releases.Add(release);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace Jackett.Common.Models.IndexerConfig
namespace Jackett.Common.Models.IndexerConfig.Bespoke
{

public class ConfigurationDataMyAnonamouse : ConfigurationData
{
public StringItem MamId { get; private set; }
public DisplayItem MamIdHint { get; private set; }
public BoolItem ExcludeVip { get; private set; }
public DisplayItem Instructions { get; private set; }

public ConfigurationDataMyAnonamouse()
{
Expand All @@ -14,6 +16,8 @@ public ConfigurationDataMyAnonamouse()
{
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 = "" };
}
}

Expand Down

0 comments on commit e940ac4

Please sign in to comment.