1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-01-04 06:22:45 +00:00

torrentleech: code cleanup (#8038)

* Code cleanup

Tested
This commit is contained in:
Diego Heras 2020-04-04 22:34:55 +02:00 committed by GitHub
parent 16a59b8abd
commit f16ee42f7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,37 +19,34 @@ namespace Jackett.Common.Indexers
{ {
public class TorrentLeech : BaseWebIndexer public class TorrentLeech : BaseWebIndexer
{ {
private string LoginUrl => SiteLink + "user/account/login/";
private string SearchUrl => SiteLink + "torrents/browse/list/";
private new ConfigurationDataRecaptchaLogin configData => (ConfigurationDataRecaptchaLogin)base.configData;
public override string[] LegacySiteLinks { get; protected set; } = public override string[] LegacySiteLinks { get; protected set; } =
{ {
"https://v4.torrentleech.org/", "https://v4.torrentleech.org/",
}; };
private string LoginUrl => SiteLink + "user/account/login/";
private string SearchUrl => SiteLink + "torrents/browse/list/";
private new ConfigurationDataRecaptchaLogin configData
{
get => (ConfigurationDataRecaptchaLogin)base.configData;
set => base.configData = value;
}
public TorrentLeech(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps) public TorrentLeech(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps)
: base(name: "TorrentLeech", : base("TorrentLeech",
description: "This is what happens when you seed", description: "This is what happens when you seed",
link: "https://www.torrentleech.org/", link: "https://www.torrentleech.org/",
caps: TorznabUtil.CreateDefaultTorznabTVCaps(), caps: new TorznabCapabilities
configService: configService, {
client: wc, SupportsImdbMovieSearch = true,
logger: l, SupportsImdbTVSearch = true
p: ps, },
downloadBase: "https://www.torrentleech.org/download/", configService: configService,
configData: new ConfigurationDataRecaptchaLogin("For best results, change the 'Default Number of Torrents per Page' setting to the maximum in your profile on the TorrentLeech webpage.")) client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataRecaptchaLogin(
"For best results, change the 'Default Number of Torrents per Page' setting to 100 in your Profile."))
{ {
Encoding = Encoding.UTF8; Encoding = Encoding.UTF8;
Language = "en-us"; Language = "en-us";
Type = "private"; Type = "private";
TorznabCaps.SupportsImdbMovieSearch = true;
TorznabCaps.SupportsImdbTVSearch = true;
AddCategoryMapping(1, TorznabCatType.Movies, "Movies"); AddCategoryMapping(1, TorznabCatType.Movies, "Movies");
AddCategoryMapping(8, TorznabCatType.MoviesSD, "Movies Cam"); AddCategoryMapping(8, TorznabCatType.MoviesSD, "Movies Cam");
@ -121,12 +118,14 @@ namespace Jackett.Common.Indexers
} }
else else
{ {
var result = new ConfigurationDataBasicLogin(); var result = new ConfigurationDataBasicLogin
result.SiteLink.Value = configData.SiteLink.Value; {
result.Instructions.Value = configData.Instructions.Value; SiteLink = {Value = configData.SiteLink.Value},
result.Username.Value = configData.Username.Value; Instructions = {Value = configData.Instructions.Value},
result.Password.Value = configData.Password.Value; Username = {Value = configData.Username.Value},
result.CookieHeader.Value = loginPage.Cookies; Password = {Value = configData.Password.Value},
CookieHeader = {Value = loginPage.Cookies}
};
return result; return result;
} }
} }
@ -179,86 +178,68 @@ namespace Jackett.Common.Indexers
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{ {
var releases = new List<ReleaseInfo>(); var releases = new List<ReleaseInfo>();
var searchString = query.GetQueryString();
searchString = Regex.Replace(searchString, @"(^|\s)-", " "); // remove dashes at the beginning of keywords as they exclude search strings (see issue #3096)
var searchUrl = SearchUrl;
var imdbId = ParseUtil.GetFullImdbID(query.ImdbID);
if (imdbId != null) // remove dashes at the beginning of keywords as they exclude search strings (see issue #3096)
{ var searchString = query.GetQueryString();
searchUrl += "imdbID/" + imdbId + "/"; searchString = Regex.Replace(searchString, @"(^|\s)-", " ");
}
var searchUrl = SearchUrl;
if (query.IsImdbQuery)
searchUrl += "imdbID/" + query.ImdbID + "/";
else if (!string.IsNullOrWhiteSpace(searchString)) else if (!string.IsNullOrWhiteSpace(searchString))
{
searchUrl += "query/" + WebUtility.UrlEncode(searchString) + "/"; searchUrl += "query/" + WebUtility.UrlEncode(searchString) + "/";
}
string.Format(SearchUrl, WebUtility.UrlEncode(searchString));
var cats = MapTorznabCapsToTrackers(query); var cats = MapTorznabCapsToTrackers(query);
if (cats.Count > 0) if (cats.Count > 0)
{ searchUrl += "categories/" + string.Join(",", cats);
searchUrl += "categories/";
foreach (var cat in cats)
{
if (!searchUrl.EndsWith("/"))
searchUrl += ",";
searchUrl += cat;
}
}
else else
{
searchUrl += "newfilter/2"; // include 0day and music searchUrl += "newfilter/2"; // include 0day and music
}
var results = await RequestStringWithCookiesAndRetry(searchUrl); var results = await RequestStringWithCookiesAndRetry(searchUrl);
if (results.Content.Contains("/user/account/login")) if (results.Content.Contains("/user/account/login")) // re-login
{ {
//Cookie appears to expire after a period of time or logging in to the site via browser
await DoLogin(); await DoLogin();
results = await RequestStringWithCookiesAndRetry(searchUrl); results = await RequestStringWithCookiesAndRetry(searchUrl);
} }
try try
{ {
dynamic jsonObj = JsonConvert.DeserializeObject(results.Content); var rows = (JArray)((JObject)JsonConvert.DeserializeObject(results.Content))["torrentList"];
foreach (var row in rows)
foreach (var torrent in jsonObj.torrentList)
{ {
var release = new ReleaseInfo(); var title = row["name"].ToString();
if (!query.MatchQueryStringAND(title))
release.MinimumRatio = 1;
release.MinimumSeedTime = 172800; // 48 hours
release.Guid = new Uri(SiteLink + "torrent/" + torrent.fid);
release.Comments = release.Guid;
release.Title = torrent.name;
if (!query.MatchQueryStringAND(release.Title))
continue; continue;
release.Link = new Uri(SiteLink + "download/" + torrent.fid + "/" + torrent.filename); var torrentId = row["fid"].ToString();
var comments = new Uri(SiteLink + "torrent/" + torrentId);
release.PublishDate = DateTime.ParseExact(torrent.addedTimestamp.ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal); var link = new Uri(SiteLink + "download/" + torrentId + "/" + row["filename"]);
var publishDate = DateTime.ParseExact(row["addedTimestamp"].ToString(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
release.Size = (long)torrent.size; var seeders = (int)row["seeders"];
release.Seeders = ParseUtil.CoerceInt(torrent.seeders.ToString());
release.Peers = release.Seeders + ParseUtil.CoerceInt(torrent.leechers.ToString());
release.Category = MapTrackerCatToNewznab(torrent.categoryID.ToString());
release.Description = torrent.categoryID.ToString();
release.Grabs = ParseUtil.CoerceInt(torrent.completed.ToString());
release.Imdb = ParseUtil.GetImdbID(torrent.imdbID.ToString());
release.UploadVolumeFactor = 1;
// freeleech #6579 #6624 #7367 // freeleech #6579 #6624 #7367
release.DownloadVolumeFactor = string.IsNullOrEmpty(torrent.download_multiplier.ToString()) ? var dlMultiplier = row["download_multiplier"].ToString();
1 : var dlVolumeFactor = string.IsNullOrEmpty(dlMultiplier) ? 1 : ParseUtil.CoerceInt(dlMultiplier);
ParseUtil.CoerceInt(torrent.download_multiplier.ToString());
var release = new ReleaseInfo
{
Title = title,
Comments = comments,
Guid = comments,
Link = link,
PublishDate = publishDate,
Category = MapTrackerCatToNewznab(row["categoryID"].ToString()),
Size = (long)row["size"],
Grabs = (int)row["completed"],
Seeders = seeders,
Peers = seeders + (int)row["leechers"],
Imdb = ParseUtil.GetImdbID(row["imdbID"].ToString()),
UploadVolumeFactor = 1,
DownloadVolumeFactor = dlVolumeFactor,
MinimumRatio = 1,
MinimumSeedTime = 172800 // 48 hours
};
releases.Add(release); releases.Add(release);
} }