redacted: treat freeload torrents as neutral leech

This commit is contained in:
Bogdan
2023-11-24 22:47:22 +02:00
parent bbe72362c1
commit 010b25646b

View File

@@ -74,11 +74,15 @@ namespace Jackett.Common.Indexers.Abstract
var cookieItem = configData.CookieItem; var cookieItem = configData.CookieItem;
if (cookieItem != null) if (cookieItem != null)
{
cookie = cookieItem.Value; cookie = cookieItem.Value;
}
var useTokenItem = configData.UseTokenItem; var useTokenItem = configData.UseTokenItem;
if (useTokenItem != null) if (useTokenItem != null)
{
useTokens = useTokenItem.Value; useTokens = useTokenItem.Value;
}
} }
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson) public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
@@ -89,17 +93,27 @@ namespace Jackett.Common.Indexers.Abstract
{ {
var apiKey = configData.ApiKey; var apiKey = configData.ApiKey;
if (apiKey?.Value == null) if (apiKey?.Value == null)
{
throw new Exception("Invalid API Key configured"); throw new Exception("Invalid API Key configured");
}
if (ApiKeyLengthLegacy == 0 && apiKey.Value.Length != ApiKeyLength) if (ApiKeyLengthLegacy == 0 && apiKey.Value.Length != ApiKeyLength)
{
throw new Exception($"Invalid API Key configured: expected length: {ApiKeyLength}, got {apiKey.Value.Length}"); throw new Exception($"Invalid API Key configured: expected length: {ApiKeyLength}, got {apiKey.Value.Length}");
}
if (ApiKeyLengthLegacy != 0 && apiKey.Value.Length != ApiKeyLength && apiKey.Value.Length != ApiKeyLengthLegacy) if (ApiKeyLengthLegacy != 0 && apiKey.Value.Length != ApiKeyLength && apiKey.Value.Length != ApiKeyLengthLegacy)
{
throw new Exception($"Invalid API Key configured: expected length: {ApiKeyLength} or {ApiKeyLengthLegacy}, got {apiKey.Value.Length}"); throw new Exception($"Invalid API Key configured: expected length: {ApiKeyLength} or {ApiKeyLengthLegacy}, got {apiKey.Value.Length}");
}
try try
{ {
var results = await PerformQuery(new TorznabQuery()); var results = await PerformQuery(new TorznabQuery());
if (!results.Any()) if (!results.Any())
{
throw new Exception("Found 0 results in the tracker"); throw new Exception("Found 0 results in the tracker");
}
IsConfigured = true; IsConfigured = true;
SaveConfig(); SaveConfig();
@@ -126,7 +140,9 @@ namespace Jackett.Common.Indexers.Abstract
{ {
var results = await PerformQuery(new TorznabQuery()); var results = await PerformQuery(new TorznabQuery());
if (!results.Any()) if (!results.Any())
{
throw new Exception("Found 0 results in the tracker"); throw new Exception("Found 0 results in the tracker");
}
IsConfigured = true; IsConfigured = true;
SaveConfig(); SaveConfig();
@@ -146,7 +162,9 @@ namespace Jackett.Common.Indexers.Abstract
using var loginResultDocument = loginResultParser.ParseDocument(response.ContentString); using var loginResultDocument = loginResultParser.ParseDocument(response.ContentString);
var loginform = loginResultDocument.QuerySelector("#loginform"); var loginform = loginResultDocument.QuerySelector("#loginform");
if (loginform == null) if (loginform == null)
{
throw new ExceptionWithConfigData(response.ContentString, configData); throw new ExceptionWithConfigData(response.ContentString, configData);
}
loginform.QuerySelector("table").Remove(); loginform.QuerySelector("table").Remove();
var errorMessage = loginform.TextContent.Replace("\n\t", " ").Trim(); var errorMessage = loginform.TextContent.Replace("\n\t", " ").Trim();
@@ -173,35 +191,55 @@ namespace Jackett.Common.Indexers.Abstract
}; };
if (!string.IsNullOrWhiteSpace(query.Genre)) if (!string.IsNullOrWhiteSpace(query.Genre))
{
queryCollection.Add("taglist", query.Genre); queryCollection.Add("taglist", query.Genre);
}
if (!string.IsNullOrWhiteSpace(query.ImdbID)) if (!string.IsNullOrWhiteSpace(query.ImdbID))
{ {
if (imdbInTags) if (imdbInTags)
{
queryCollection.Add("taglist", query.ImdbID); queryCollection.Add("taglist", query.ImdbID);
}
else else
{
queryCollection.Add("cataloguenumber", query.ImdbID); queryCollection.Add("cataloguenumber", query.ImdbID);
}
} }
else if (!string.IsNullOrWhiteSpace(searchString)) else if (!string.IsNullOrWhiteSpace(searchString))
{
queryCollection.Add("searchstr", searchString); queryCollection.Add("searchstr", searchString);
}
if (query.Artist.IsNotNullOrWhiteSpace() && query.Artist != "VA") if (query.Artist.IsNotNullOrWhiteSpace() && query.Artist != "VA")
{
queryCollection.Add("artistname", query.Artist); queryCollection.Add("artistname", query.Artist);
}
if (query.Label.IsNotNullOrWhiteSpace()) if (query.Label.IsNotNullOrWhiteSpace())
{
queryCollection.Add("recordlabel", query.Label); queryCollection.Add("recordlabel", query.Label);
}
if (query.Year.HasValue) if (query.Year.HasValue)
{
queryCollection.Add("year", query.Year.ToString()); queryCollection.Add("year", query.Year.ToString());
}
if (query.Album.IsNotNullOrWhiteSpace()) if (query.Album.IsNotNullOrWhiteSpace())
{
queryCollection.Add("groupname", query.Album); queryCollection.Add("groupname", query.Album);
}
foreach (var cat in MapTorznabCapsToTrackers(query)) foreach (var cat in MapTorznabCapsToTrackers(query))
{
queryCollection.Add("filter_cat[" + cat + "]", "1"); queryCollection.Add("filter_cat[" + cat + "]", "1");
}
if (configData.FreeleechOnly != null && configData.FreeleechOnly.Value) if (configData.FreeleechOnly != null && configData.FreeleechOnly.Value)
{
queryCollection.Add("freetorrent", "1"); queryCollection.Add("freetorrent", "1");
}
// remove . as not used in titles // remove . as not used in titles
searchUrl += "?" + queryCollection.GetQueryString().Replace(".", " "); searchUrl += "?" + queryCollection.GetQueryString().Replace(".", " ");
@@ -250,12 +288,21 @@ namespace Jackett.Common.Indexers.Abstract
var releaseType = (string)r["releaseType"]; var releaseType = (string)r["releaseType"];
var title = new StringBuilder(); var title = new StringBuilder();
if (!string.IsNullOrEmpty(artist)) if (!string.IsNullOrEmpty(artist))
{
title.Append(artist + " - "); title.Append(artist + " - ");
}
title.Append(groupName); title.Append(groupName);
if (!string.IsNullOrEmpty(groupYear) && groupYear != "0") if (!string.IsNullOrEmpty(groupYear) && groupYear != "0")
{
title.Append(" [" + groupYear + "]"); title.Append(" [" + groupYear + "]");
}
if (!string.IsNullOrEmpty(releaseType) && releaseType != "Unknown") if (!string.IsNullOrEmpty(releaseType) && releaseType != "Unknown")
{
title.Append(" [" + releaseType + "]"); title.Append(" [" + releaseType + "]");
}
var description = tags?.Any() == true && !string.IsNullOrEmpty(tags[0].ToString()) var description = tags?.Any() == true && !string.IsNullOrEmpty(tags[0].ToString())
? "Tags: " + string.Join(", ", tags) + "\n" ? "Tags: " + string.Join(", ", tags) + "\n"
: null; : null;
@@ -264,7 +311,10 @@ namespace Jackett.Common.Indexers.Abstract
: null; : null;
Uri poster = null; Uri poster = null;
if (!string.IsNullOrEmpty(cover)) if (!string.IsNullOrEmpty(cover))
{
poster = (cover.StartsWith("http")) ? new Uri(cover) : new Uri(PosterUrl + cover); poster = (cover.StartsWith("http")) ? new Uri(cover) : new Uri(PosterUrl + cover);
}
var release = new ReleaseInfo var release = new ReleaseInfo
{ {
PublishDate = groupTime, PublishDate = groupTime,
@@ -274,28 +324,41 @@ namespace Jackett.Common.Indexers.Abstract
}; };
if (release.Genres == null) if (release.Genres == null)
{
release.Genres = new List<string>(); release.Genres = new List<string>();
}
if (!string.IsNullOrEmpty(genre)) if (!string.IsNullOrEmpty(genre))
{
release.Genres = release.Genres.Union(genre.Split(',')).ToList(); release.Genres = release.Genres.Union(genre.Split(',')).ToList();
}
if (imdbInTags) if (imdbInTags)
{
release.Imdb = tags release.Imdb = tags
.Select(tag => ParseUtil.GetImdbId((string)tag)) .Select(tag => ParseUtil.GetImdbId((string)tag))
.Where(tag => tag != null).FirstIfSingleOrDefault(); .Where(tag => tag != null).FirstIfSingleOrDefault();
}
if (r["torrents"] is JArray) if (r["torrents"] is JArray)
{
foreach (JObject torrent in r["torrents"]) foreach (JObject torrent in r["torrents"])
{ {
var release2 = (ReleaseInfo)release.Clone(); var release2 = (ReleaseInfo)release.Clone();
FillReleaseInfoFromJson(release2, torrent); FillReleaseInfoFromJson(release2, torrent);
if (ReleaseInfoPostParse(release2, torrent, r)) if (ReleaseInfoPostParse(release2, torrent, r))
{
releases.Add(release2); releases.Add(release2);
}
} }
}
else else
{ {
FillReleaseInfoFromJson(release, r); FillReleaseInfoFromJson(release, r);
if (ReleaseInfoPostParse(release, r, r)) if (ReleaseInfoPostParse(release, r, r))
{
releases.Add(release); releases.Add(release);
}
} }
} }
} }
@@ -316,17 +379,23 @@ namespace Jackett.Common.Indexers.Abstract
var time = (string)torrent["time"]; var time = (string)torrent["time"];
if (!string.IsNullOrEmpty(time)) if (!string.IsNullOrEmpty(time))
{
release.PublishDate = DateTime.ParseExact(time + " +0000", "yyyy-MM-dd HH:mm:ss zzz", CultureInfo.InvariantCulture); release.PublishDate = DateTime.ParseExact(time + " +0000", "yyyy-MM-dd HH:mm:ss zzz", CultureInfo.InvariantCulture);
}
var flags = new List<string>(); var flags = new List<string>();
var format = (string)torrent["format"]; var format = (string)torrent["format"];
if (!string.IsNullOrEmpty(format)) if (!string.IsNullOrEmpty(format))
{
flags.Add(WebUtility.HtmlDecode(format)); flags.Add(WebUtility.HtmlDecode(format));
}
var encoding = (string)torrent["encoding"]; var encoding = (string)torrent["encoding"];
if (!string.IsNullOrEmpty(encoding)) if (!string.IsNullOrEmpty(encoding))
{
flags.Add(encoding); flags.Add(encoding);
}
if (torrent["hasLog"] != null && (bool)torrent["hasLog"]) if (torrent["hasLog"] != null && (bool)torrent["hasLog"])
{ {
@@ -335,41 +404,57 @@ namespace Jackett.Common.Indexers.Abstract
} }
if (torrent["hasCue"] != null && (bool)torrent["hasCue"]) if (torrent["hasCue"] != null && (bool)torrent["hasCue"])
{
flags.Add("Cue"); flags.Add("Cue");
}
// tehconnection.me specific? // tehconnection.me specific?
var lang = (string)torrent["lang"]; var lang = (string)torrent["lang"];
if (!string.IsNullOrEmpty(lang) && lang != "---") if (!string.IsNullOrEmpty(lang) && lang != "---")
{
flags.Add(lang); flags.Add(lang);
}
var media = (string)torrent["media"]; var media = (string)torrent["media"];
if (!string.IsNullOrEmpty(media)) if (!string.IsNullOrEmpty(media))
{
flags.Add(media); flags.Add(media);
}
// tehconnection.me specific? // tehconnection.me specific?
var resolution = (string)torrent["resolution"]; var resolution = (string)torrent["resolution"];
if (!string.IsNullOrEmpty(resolution)) if (!string.IsNullOrEmpty(resolution))
{
flags.Add(resolution); flags.Add(resolution);
}
// tehconnection.me specific? // tehconnection.me specific?
var container = (string)torrent["container"]; var container = (string)torrent["container"];
if (!string.IsNullOrEmpty(container)) if (!string.IsNullOrEmpty(container))
{
flags.Add(container); flags.Add(container);
}
// tehconnection.me specific? // tehconnection.me specific?
var codec = (string)torrent["codec"]; var codec = (string)torrent["codec"];
if (!string.IsNullOrEmpty(codec)) if (!string.IsNullOrEmpty(codec))
{
flags.Add(codec); flags.Add(codec);
}
// tehconnection.me specific? // tehconnection.me specific?
var audio = (string)torrent["audio"]; var audio = (string)torrent["audio"];
if (!string.IsNullOrEmpty(audio)) if (!string.IsNullOrEmpty(audio))
{
flags.Add(audio); flags.Add(audio);
}
// tehconnection.me specific? // tehconnection.me specific?
var subbing = (string)torrent["subbing"]; var subbing = (string)torrent["subbing"];
if (!string.IsNullOrEmpty(subbing) && subbing != "---") if (!string.IsNullOrEmpty(subbing) && subbing != "---")
{
flags.Add(subbing); flags.Add(subbing);
}
if (torrent["remastered"] != null && (bool)torrent["remastered"]) if (torrent["remastered"] != null && (bool)torrent["remastered"])
{ {
@@ -379,7 +464,9 @@ namespace Jackett.Common.Indexers.Abstract
} }
if (flags.Count > 0) if (flags.Count > 0)
{
release.Title += " " + string.Join(" / ", flags); release.Title += " " + string.Join(" / ", flags);
}
release.Size = (long)torrent["size"]; release.Size = (long)torrent["size"];
release.Seeders = (int)torrent["seeders"]; release.Seeders = (int)torrent["seeders"];
@@ -389,19 +476,31 @@ namespace Jackett.Common.Indexers.Abstract
release.Link = new Uri(DownloadUrl + torrentId); release.Link = new Uri(DownloadUrl + torrentId);
var category = (string)torrent["category"]; var category = (string)torrent["category"];
if (category == null || category.Contains("Select Category")) if (category == null || category.Contains("Select Category"))
{
release.Category = MapTrackerCatToNewznab("1"); release.Category = MapTrackerCatToNewznab("1");
}
else else
{
release.Category = MapTrackerCatDescToNewznab(category); release.Category = MapTrackerCatDescToNewznab(category);
}
release.Files = (int)torrent["fileCount"]; release.Files = (int)torrent["fileCount"];
release.Grabs = (int)torrent["snatches"]; release.Grabs = (int)torrent["snatches"];
release.DownloadVolumeFactor = 1; release.DownloadVolumeFactor = 1;
release.UploadVolumeFactor = 1; release.UploadVolumeFactor = 1;
if ((bool)torrent["isFreeleech"]) if ((bool)torrent["isFreeleech"])
{
release.DownloadVolumeFactor = 0; release.DownloadVolumeFactor = 0;
}
var isPersonalFreeleech = (bool?)torrent["isPersonalFreeleech"]; var isPersonalFreeleech = (bool?)torrent["isPersonalFreeleech"];
if (isPersonalFreeleech != null && isPersonalFreeleech == true) if (isPersonalFreeleech != null && isPersonalFreeleech == true)
{
release.DownloadVolumeFactor = 0; release.DownloadVolumeFactor = 0;
if ((bool)torrent["isNeutralLeech"]) }
var isFreeload = (bool?)torrent["isFreeload"];
if ((bool)torrent["isNeutralLeech"] || (isFreeload != null && isFreeload == true))
{ {
release.DownloadVolumeFactor = 0; release.DownloadVolumeFactor = 0;
release.UploadVolumeFactor = 0; release.UploadVolumeFactor = 0;