mirror of
https://github.com/Jackett/Jackett.git
synced 2025-10-03 08:57:46 +02:00
polishtracker: add imdb search and code clean up (#7913)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jackett.Common.Models;
|
using Jackett.Common.Models;
|
||||||
@@ -16,21 +17,17 @@ namespace Jackett.Common.Indexers
|
|||||||
public class PolishTracker : BaseWebIndexer
|
public class PolishTracker : BaseWebIndexer
|
||||||
{
|
{
|
||||||
private string LoginUrl => SiteLink + "login";
|
private string LoginUrl => SiteLink + "login";
|
||||||
private string TorrentApiUrl => SiteLink + "apitorrents";
|
private string SearchUrl => SiteLink + "apitorrents";
|
||||||
private string CDNUrl => "https://cdn.pte.nu/";
|
private static string CdnUrl => "https://cdn.pte.nu/";
|
||||||
|
|
||||||
public override string[] LegacySiteLinks { get; protected set; } = new string[] {
|
public override string[] LegacySiteLinks { get; protected set; } = {
|
||||||
"https://polishtracker.net/",
|
"https://polishtracker.net/",
|
||||||
};
|
};
|
||||||
|
|
||||||
private new ConfigurationDataBasicLoginWithEmail configData
|
private new ConfigurationDataBasicLoginWithEmail configData => (ConfigurationDataBasicLoginWithEmail)base.configData;
|
||||||
{
|
|
||||||
get => (ConfigurationDataBasicLoginWithEmail)base.configData;
|
|
||||||
set => base.configData = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PolishTracker(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
public PolishTracker(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
||||||
: base(name: "PolishTracker",
|
: base("PolishTracker",
|
||||||
description: "Polish Tracker is a POLISH Private site for 0DAY / MOVIES / GENERAL",
|
description: "Polish Tracker is a POLISH Private site for 0DAY / MOVIES / GENERAL",
|
||||||
link: "https://pte.nu/",
|
link: "https://pte.nu/",
|
||||||
caps: new TorznabCapabilities(),
|
caps: new TorznabCapabilities(),
|
||||||
@@ -44,6 +41,9 @@ namespace Jackett.Common.Indexers
|
|||||||
Language = "pl-pl";
|
Language = "pl-pl";
|
||||||
Type = "private";
|
Type = "private";
|
||||||
|
|
||||||
|
TorznabCaps.SupportsImdbMovieSearch = true;
|
||||||
|
TorznabCaps.SupportsImdbTVSearch = true;
|
||||||
|
|
||||||
AddCategoryMapping(1, TorznabCatType.PC0day, "0-Day");
|
AddCategoryMapping(1, TorznabCatType.PC0day, "0-Day");
|
||||||
AddCategoryMapping(3, TorznabCatType.PC0day, "Apps");
|
AddCategoryMapping(3, TorznabCatType.PC0day, "Apps");
|
||||||
AddCategoryMapping(4, TorznabCatType.Console, "Consoles");
|
AddCategoryMapping(4, TorznabCatType.Console, "Consoles");
|
||||||
@@ -69,7 +69,7 @@ namespace Jackett.Common.Indexers
|
|||||||
};
|
};
|
||||||
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink);
|
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink);
|
||||||
|
|
||||||
await ConfigureIfOK(result.Cookies, result.Cookies != null && result.Cookies.Contains("id="), () =>
|
await ConfigureIfOK(result.Cookies, result.Cookies?.Contains("id=") == true, () =>
|
||||||
{
|
{
|
||||||
var errorMessage = result.Content;
|
var errorMessage = result.Content;
|
||||||
if (errorMessage.Contains("Error!"))
|
if (errorMessage.Contains("Error!"))
|
||||||
@@ -83,105 +83,87 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
var releases = new List<ReleaseInfo>();
|
var releases = new List<ReleaseInfo>();
|
||||||
|
|
||||||
var searchUrl = TorrentApiUrl;
|
var qc = new List<KeyValuePair<string, string>> // NameValueCollection don't support cat[]=19&cat[]=6
|
||||||
var searchString = query.GetQueryString();
|
|
||||||
var queryCollection = new List<KeyValuePair<string, string>>
|
|
||||||
{
|
{
|
||||||
{ "tpage", "1" }
|
{ "tpage", "1" }
|
||||||
};
|
};
|
||||||
foreach (var cat in MapTorznabCapsToTrackers(query))
|
|
||||||
|
if (query.IsImdbQuery)
|
||||||
{
|
{
|
||||||
queryCollection.Add("cat[]", cat);
|
qc.Add("search", query.ImdbID);
|
||||||
|
qc.Add("nfo", "true");
|
||||||
}
|
}
|
||||||
|
else if (!string.IsNullOrWhiteSpace(query.GetQueryString()))
|
||||||
|
qc.Add("search", query.GetQueryString());
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(searchString))
|
foreach (var cat in MapTorznabCapsToTrackers(query))
|
||||||
queryCollection.Add("search", searchString);
|
qc.Add("cat[]", cat);
|
||||||
|
|
||||||
searchUrl += "?" + queryCollection.GetQueryString();
|
var searchUrl = SearchUrl + "?" + qc.GetQueryString();
|
||||||
|
var result = await RequestStringWithCookiesAndRetry(searchUrl, null, SearchUrl);
|
||||||
var result = await RequestStringWithCookiesAndRetry(searchUrl, null, TorrentApiUrl);
|
|
||||||
if (result.IsRedirect)
|
if (result.IsRedirect)
|
||||||
{
|
{
|
||||||
// re-login
|
// re-login
|
||||||
await ApplyConfiguration(null);
|
await ApplyConfiguration(null);
|
||||||
result = await RequestStringWithCookiesAndRetry(searchUrl, null, TorrentApiUrl);
|
result = await RequestStringWithCookiesAndRetry(searchUrl, null, SearchUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.Content.StartsWith("{")) // not JSON => error
|
if (!result.Content.StartsWith("{")) // not JSON => error
|
||||||
throw new ExceptionWithConfigData(result.Content, configData);
|
throw new ExceptionWithConfigData(result.Content, configData);
|
||||||
dynamic json = JsonConvert.DeserializeObject<dynamic>(result.Content);
|
|
||||||
|
var json = JsonConvert.DeserializeObject<dynamic>(result.Content);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dynamic torrents = json["torrents"]; // latest torrents
|
var torrents = json["torrents"]; // latest torrents
|
||||||
|
|
||||||
if (json["hits"] != null) // is search result
|
if (json["hits"] != null) // is search result
|
||||||
torrents = json.SelectTokens("$.hits[?(@._type == 'torrent')]._source");
|
torrents = json.SelectTokens("$.hits[?(@._type == 'torrent')]._source");
|
||||||
/*
|
|
||||||
{
|
|
||||||
"id":426868,
|
|
||||||
"name":"Realease-nameE",
|
|
||||||
"size":"2885494332",
|
|
||||||
"category":11,
|
|
||||||
"added":"2017-09-11T11:36:26.936Z",
|
|
||||||
"comments":0,
|
|
||||||
"leechers":0,
|
|
||||||
"seeders":1,
|
|
||||||
"completed":0,
|
|
||||||
"poster":true,
|
|
||||||
"imdb_id":"3743822",
|
|
||||||
"cdu_id":null,
|
|
||||||
"steam_id":null,
|
|
||||||
"subs":null,
|
|
||||||
"language":"en"
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
|
|
||||||
foreach (var torrent in torrents)
|
foreach (var torrent in torrents)
|
||||||
{
|
{
|
||||||
// TODO convert to ReleaseInfo Initializer
|
var torrentId = (long)torrent.id;
|
||||||
var release = new ReleaseInfo();
|
var comments = new Uri(SiteLink + "torrents/" + torrentId);
|
||||||
var descriptions = new List<string>();
|
var link = new Uri(SiteLink + "download/" + torrentId);
|
||||||
release.MinimumRatio = 1;
|
var publishDate = DateTime.Parse(torrent.added.ToString());
|
||||||
release.MinimumSeedTime = 0;
|
var imdbId = ParseUtil.GetImdbID(torrent.imdb_id.ToString());
|
||||||
|
|
||||||
release.Category = MapTrackerCatToNewznab(torrent.category.ToString());
|
Uri banner = null;
|
||||||
release.Title = torrent.name.ToString();
|
if ((bool)torrent.poster)
|
||||||
var torrentID = (long)torrent.id;
|
|
||||||
release.Comments = new Uri(SiteLink + "torrents/" + torrentID);
|
|
||||||
release.Guid = release.Comments;
|
|
||||||
release.Link = new Uri(SiteLink + "download/" + torrentID);
|
|
||||||
var date = (DateTime)torrent.added;
|
|
||||||
release.PublishDate = date;
|
|
||||||
release.Size = ParseUtil.CoerceLong(torrent.size.ToString());
|
|
||||||
release.Seeders = (int)torrent.seeders;
|
|
||||||
release.Peers = release.Seeders + (int)torrent.leechers;
|
|
||||||
var imdbid = torrent.imdb_id.ToString();
|
|
||||||
if (!string.IsNullOrEmpty(imdbid))
|
|
||||||
release.Imdb = ParseUtil.CoerceLong(imdbid);
|
|
||||||
|
|
||||||
if ((bool)torrent.poster == true)
|
|
||||||
{
|
{
|
||||||
if (release.Imdb != null)
|
if (torrent["imdb_id"] != null)
|
||||||
release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/imd/l/" + imdbid + ".jpg");
|
banner = new Uri(CdnUrl + "images/torrents/poster/imd/l/" + torrent["imdb_id"] + ".jpg");
|
||||||
else if (torrent["cdu_id"] != null)
|
else if (torrent["cdu_id"] != null)
|
||||||
release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/cdu/b/" + torrent["cdu_id"] + "_front.jpg");
|
banner = new Uri(CdnUrl + "images/torrents/poster/cdu/b/" + torrent["cdu_id"] + "_front.jpg");
|
||||||
else if (torrent["steam_id"] != null)
|
else if (torrent["steam_id"] != null)
|
||||||
release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/ste/l/" + torrent["steam_id"] + ".jpg");
|
banner = new Uri(CdnUrl + "images/torrents/poster/ste/l/" + torrent["steam_id"] + ".jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
release.UploadVolumeFactor = 1;
|
var descriptions = new List<string>();
|
||||||
release.DownloadVolumeFactor = 1;
|
|
||||||
|
|
||||||
release.Grabs = (long)torrent.completed;
|
|
||||||
|
|
||||||
var language = (string)torrent.language;
|
var language = (string)torrent.language;
|
||||||
if (!string.IsNullOrEmpty(language))
|
if (!string.IsNullOrEmpty(language))
|
||||||
descriptions.Add("Language: " + language);
|
descriptions.Add("Language: " + language);
|
||||||
else if ((bool?)torrent.polish == true)
|
else if ((bool?)torrent.polish == true)
|
||||||
descriptions.Add("Language: pl");
|
descriptions.Add("Language: pl");
|
||||||
|
var description = descriptions.Any() ? string.Join("<br />\n", descriptions) : null;
|
||||||
|
|
||||||
if (descriptions.Count > 0)
|
var release = new ReleaseInfo
|
||||||
release.Description = string.Join("<br />\n", descriptions);
|
{
|
||||||
|
Title = torrent.name.ToString(),
|
||||||
|
Comments = comments,
|
||||||
|
Guid = comments,
|
||||||
|
Link = link,
|
||||||
|
PublishDate = publishDate,
|
||||||
|
Category = MapTrackerCatToNewznab(torrent.category.ToString()),
|
||||||
|
Size = (long)torrent.size,
|
||||||
|
Grabs = (long)torrent.completed,
|
||||||
|
Seeders = (int)torrent.seeders,
|
||||||
|
Peers = (int)torrent.seeders + (int)torrent.leechers,
|
||||||
|
Imdb = imdbId,
|
||||||
|
BannerUrl = banner,
|
||||||
|
Description = description,
|
||||||
|
MinimumRatio = 1,
|
||||||
|
MinimumSeedTime = 259200, // 72 hours (I can't verify this, but this is a safe value in most trackers)
|
||||||
|
UploadVolumeFactor = 1,
|
||||||
|
DownloadVolumeFactor = 1
|
||||||
|
};
|
||||||
|
|
||||||
releases.Add(release);
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user