Jackett/src/Jackett.Common/Indexers/PolishTracker.cs

198 lines
8.2 KiB
C#
Raw Normal View History

2017-10-29 06:50:47 +00:00
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
2017-10-29 06:50:47 +00:00
using System.Threading.Tasks;
using Jackett.Models;
using Jackett.Models.IndexerConfig;
Feature/netcore preparation (#2035) * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * Move to use package reference for restoring nuget packages. * Return a task result for this async method. * Update to a supported version of the .NET Framework. This also has the side effect of allowing us to automatically generate our binding redirects on build. * Set the solution to target VS2017 * Update test solution csproj file to support being built through MSBuild 15 * DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency. * Move the interfaces into their own files. This will be useful when we share them between the .NET Core and .NET Framework WebAPI * Stage services that need to point to the new interface namespace. * Update CurlSharp to fix memory leak issue and support better runtime compatibility with OSX and Linux * Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required
2017-10-29 10:19:09 +00:00
using Jackett.Services.Interfaces;
2017-10-29 06:50:47 +00:00
using Jackett.Utils;
using Jackett.Utils.Clients;
using Newtonsoft.Json;
2017-10-29 06:50:47 +00:00
using Newtonsoft.Json.Linq;
using NLog;
namespace Jackett.Indexers
{
public class PolishTracker : BaseWebIndexer
{
2017-10-29 06:50:47 +00:00
private string LoginUrl { get { return SiteLink + "login"; } }
private string TorrentApiUrl { get { return SiteLink + "apitorrents"; } }
private string CDNUrl { get { return "https://cdn.pte.nu/"; } }
public override string[] LegacySiteLinks { get; protected set; } = new string[] {
"https://polishtracker.net/",
};
2017-10-29 06:50:47 +00:00
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
{
get { return (ConfigurationDataBasicLoginWithRSSAndDisplay)base.configData; }
set { base.configData = value; }
}
public PolishTracker(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
: base(name: "PolishTracker",
description: "Polish Tracker is a POLISH Private site for 0DAY / MOVIES / GENERAL",
link: "https://pte.nu/",
caps: new TorznabCapabilities(),
configService: configService,
client: wc,
logger: l,
p: ps,
configData: new ConfigurationDataBasicLoginWithRSSAndDisplay())
{
Encoding = Encoding.UTF8;
Language = "pl-pl";
Type = "private";
AddCategoryMapping(1, TorznabCatType.PC0day, "0-Day");
AddCategoryMapping(3, TorznabCatType.PC0day, "Apps");
AddCategoryMapping(4, TorznabCatType.Console, "Consoles");
AddCategoryMapping(5, TorznabCatType.Books, "E-book");
AddCategoryMapping(6, TorznabCatType.MoviesHD, "Movies HD");
AddCategoryMapping(7, TorznabCatType.MoviesSD, "Movies SD");
AddCategoryMapping(8, TorznabCatType.Audio, "Music");
AddCategoryMapping(9, TorznabCatType.AudioVideo, "MusicVideo");
AddCategoryMapping(10, TorznabCatType.PCGames, "PcGames");
AddCategoryMapping(11, TorznabCatType.TVHD, "TV HD");
AddCategoryMapping(12, TorznabCatType.TVSD, "TV SD");
AddCategoryMapping(13, TorznabCatType.XXX, "XXX");
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{
LoadValuesFromJson(configJson);
var pairs = new Dictionary<string, string>
{
{ "email", configData.Username.Value },
{ "pass", configData.Password.Value }
};
var result = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, null, SiteLink);
await ConfigureIfOK(result.Cookies, result.Cookies != null && result.Cookies.Contains("id="), () =>
{
var errorMessage = result.Content;
throw new ExceptionWithConfigData(errorMessage, configData);
});
return IndexerConfigurationStatus.RequiresTesting;
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{
var releases = new List<ReleaseInfo>();
var searchUrl = TorrentApiUrl;
var searchString = query.GetQueryString();
var queryCollection = new NameValueCollection();
queryCollection.Add("tpage", "1");
foreach (var cat in MapTorznabCapsToTrackers(query))
{
queryCollection.Add("cat[]", cat);
}
if (!string.IsNullOrWhiteSpace(searchString))
queryCollection.Add("search", searchString);
var cats = MapTorznabCapsToTrackers(query);
if (cats.Count > 0)
queryCollection.Add("cats", string.Join(",", cats));
searchUrl += "?" + queryCollection.GetQueryString();
var result = await RequestStringWithCookiesAndRetry(searchUrl, null, TorrentApiUrl);
if (result.IsRedirect)
{
// re-login
await ApplyConfiguration(null);
result = await RequestStringWithCookiesAndRetry(searchUrl, null, TorrentApiUrl);
}
if (!result.Content.StartsWith("{")) // not JSON => error
throw new ExceptionWithConfigData(result.Content, configData);
dynamic json = JsonConvert.DeserializeObject<dynamic>(result.Content);
try
{
dynamic torrents = json["torrents"]; // latest torrents
if (json["hits"] != null) // is search result
torrents = json.SelectTokens("$.hits[?(@._type == 'torrent')]._source");
/*
2017-10-29 06:50:47 +00:00
{
"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)
{
var release = new ReleaseInfo();
var descriptions = new List<string>();
release.MinimumRatio = 1;
release.MinimumSeedTime = 0;
release.Category = MapTrackerCatToNewznab(torrent.category.ToString());
release.Title = torrent.name.ToString();
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)
2017-10-29 06:50:47 +00:00
{
if (release.Imdb != null)
release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/imd/l/" + imdbid + ".jpg");
else if (torrent["cdu_id"] != null)
release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/cdu/b/" + torrent["cdu_id"] + "_front.jpg");
else if (torrent["steam_id"] != null)
release.BannerUrl = new Uri(CDNUrl + "images/torrents/poster/ste/l/" + torrent["steam_id"] + ".jpg");
}
release.UploadVolumeFactor = 1;
release.DownloadVolumeFactor = 1;
release.Grabs = (long)torrent.completed;
var language = (string)torrent.language;
if (!string.IsNullOrEmpty(language))
descriptions.Add("Language: " + language);
else if ((bool?)torrent.polish == true)
descriptions.Add("Language: pl");
if (descriptions.Count > 0)
2017-10-29 06:50:47 +00:00
release.Description = string.Join("<br />\n", descriptions);
releases.Add(release);
}
}
catch (Exception ex)
{
OnParseError(result.ToString(), ex);
}
return releases;
}
}
}