2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2016-09-22 10:27:35 +00:00
|
|
|
using System.Collections.Generic;
|
2017-04-15 08:45:10 +00:00
|
|
|
using System.Collections.Specialized;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-04-15 08:45:10 +00:00
|
|
|
using System.Text;
|
2017-10-29 06:50:47 +00:00
|
|
|
using System.Threading.Tasks;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
2017-08-22 15:43:39 +00:00
|
|
|
using Newtonsoft.Json;
|
2017-10-29 06:50:47 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
2018-03-10 08:05:56 +00:00
|
|
|
using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
2016-09-22 10:27:35 +00:00
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2017-07-10 20:58:44 +00:00
|
|
|
public class TorrentNetwork : BaseWebIndexer
|
2016-09-22 10:27:35 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
private string APIUrl => SiteLink + "api/";
|
2017-08-22 15:43:39 +00:00
|
|
|
private string passkey;
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
private readonly Dictionary<string, string> APIHeaders = new Dictionary<string, string>()
|
2017-08-22 15:43:39 +00:00
|
|
|
{
|
|
|
|
{"Content-Type", "application/json"},
|
|
|
|
};
|
2016-09-22 10:27:35 +00:00
|
|
|
|
2017-10-29 06:50:47 +00:00
|
|
|
private new ConfigurationDataBasicLoginWithRSSAndDisplay configData
|
2016-09-22 10:27:35 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataBasicLoginWithRSSAndDisplay)base.configData;
|
|
|
|
set => base.configData = value;
|
2016-09-22 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public TorrentNetwork(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
2020-05-11 19:59:28 +00:00
|
|
|
: base(id: "torrentnetwork",
|
|
|
|
name: "Torrent Network",
|
2017-10-04 05:05:10 +00:00
|
|
|
description: "Torrent Network (TN) is a GERMAN Private site for TV / MOVIES / GENERAL",
|
2016-09-22 10:27:35 +00:00
|
|
|
link: "https://tntracker.org/",
|
2017-08-22 15:43:39 +00:00
|
|
|
caps: new TorznabCapabilities(),
|
2017-07-10 20:58:44 +00:00
|
|
|
configService: configService,
|
2016-09-22 10:27:35 +00:00
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataBasicLoginWithRSSAndDisplay())
|
|
|
|
{
|
2017-11-05 09:42:03 +00:00
|
|
|
Encoding = Encoding.UTF8;
|
2016-12-09 17:20:58 +00:00
|
|
|
Language = "de-de";
|
2017-01-27 15:57:32 +00:00
|
|
|
Type = "private";
|
2016-12-06 13:56:47 +00:00
|
|
|
|
2017-08-22 15:43:39 +00:00
|
|
|
configData.AddDynamic("token", new HiddenItem() { Name = "token" });
|
|
|
|
configData.AddDynamic("passkey", new HiddenItem() { Name = "passkey" });
|
|
|
|
|
|
|
|
AddCategoryMapping(24, TorznabCatType.MoviesSD, "Movies GER/SD");
|
|
|
|
AddCategoryMapping(18, TorznabCatType.MoviesHD, "Movies GER/720p");
|
|
|
|
AddCategoryMapping(17, TorznabCatType.MoviesHD, "Movies GER/1080p");
|
|
|
|
AddCategoryMapping(20, TorznabCatType.MoviesHD, "Movies GER/2160p");
|
|
|
|
AddCategoryMapping(45, TorznabCatType.MoviesOther, "Movies GER/Remux");
|
|
|
|
AddCategoryMapping(19, TorznabCatType.MoviesBluRay, "Movies GER/BluRay");
|
|
|
|
AddCategoryMapping(34, TorznabCatType.TVAnime, "Movies GER/Anime");
|
|
|
|
AddCategoryMapping(36, TorznabCatType.Movies3D, "Movies GER/3D");
|
|
|
|
|
|
|
|
AddCategoryMapping(22, TorznabCatType.MoviesSD, "Movies ENG/SD");
|
|
|
|
AddCategoryMapping(35, TorznabCatType.MoviesHD, "Movies ENG/720p");
|
|
|
|
AddCategoryMapping(43, TorznabCatType.MoviesHD, "Movies ENG/1080p");
|
|
|
|
AddCategoryMapping(37, TorznabCatType.MoviesHD, "Movies ENG/2160p");
|
|
|
|
AddCategoryMapping(46, TorznabCatType.MoviesOther, "Movies ENG/Remux");
|
|
|
|
AddCategoryMapping(38, TorznabCatType.MoviesBluRay, "Movies ENG/BluRay");
|
|
|
|
AddCategoryMapping(39, TorznabCatType.TVAnime, "Movies ENG/Anime");
|
|
|
|
|
|
|
|
AddCategoryMapping(27, TorznabCatType.TVSD, "Series GER/SD");
|
|
|
|
AddCategoryMapping(28, TorznabCatType.TVHD, "Series GER/HD");
|
|
|
|
AddCategoryMapping(2, TorznabCatType.TVAnime, "Series GER/Anime");
|
|
|
|
AddCategoryMapping(16, TorznabCatType.TV, "Series GER/Pack");
|
|
|
|
AddCategoryMapping(6, TorznabCatType.TVDocumentary, "Docu/SD");
|
|
|
|
AddCategoryMapping(7, TorznabCatType.TVDocumentary, "Docu/HD");
|
|
|
|
|
|
|
|
AddCategoryMapping(29, TorznabCatType.TVSD, "Series ENG/SD");
|
|
|
|
AddCategoryMapping(40, TorznabCatType.TVHD, "Series ENG/HD");
|
|
|
|
AddCategoryMapping(41, TorznabCatType.TVAnime, "Series ENG/Anime");
|
|
|
|
AddCategoryMapping(42, TorznabCatType.TV, "Series ENG/Pack");
|
|
|
|
AddCategoryMapping(31, TorznabCatType.TVSport, "Sport");
|
|
|
|
|
|
|
|
AddCategoryMapping(10, TorznabCatType.PCGames, "Games/Win");
|
|
|
|
AddCategoryMapping(12, TorznabCatType.ConsoleWii, "Games/Wii");
|
|
|
|
AddCategoryMapping(13, TorznabCatType.ConsolePS4, "Games/PSX");
|
|
|
|
AddCategoryMapping(14, TorznabCatType.ConsoleXbox, "Games/XBOX");
|
|
|
|
|
|
|
|
AddCategoryMapping(4, TorznabCatType.PCMac, "Apps/Mac");
|
|
|
|
AddCategoryMapping(5, TorznabCatType.PC0day, "Apps/Win");
|
|
|
|
|
|
|
|
AddCategoryMapping(1, TorznabCatType.AudioAudiobook, "Misc/aBook");
|
|
|
|
AddCategoryMapping(8, TorznabCatType.Books, "Misc/eBook");
|
|
|
|
AddCategoryMapping(30, TorznabCatType.Other, "Misc/Sonstiges");
|
|
|
|
|
|
|
|
AddCategoryMapping(44, TorznabCatType.AudioLossless, "Musik/Flac");
|
|
|
|
AddCategoryMapping(25, TorznabCatType.AudioMP3, "Musik/MP3");
|
|
|
|
AddCategoryMapping(26, TorznabCatType.AudioVideo, "Musik/Video");
|
|
|
|
|
|
|
|
AddCategoryMapping(32, TorznabCatType.XXX, "XXX/XXX");
|
|
|
|
AddCategoryMapping(33, TorznabCatType.XXX, "XXX/XXX|HD");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void LoadValuesFromJson(JToken jsonConfig, bool useProtectionService = false)
|
|
|
|
{
|
|
|
|
base.LoadValuesFromJson(jsonConfig, useProtectionService);
|
|
|
|
|
|
|
|
var tokenItem = (HiddenItem)configData.GetDynamic("token");
|
|
|
|
if (tokenItem != null)
|
|
|
|
{
|
|
|
|
var token = tokenItem.Value;
|
|
|
|
if (!string.IsNullOrWhiteSpace(token))
|
2017-08-22 15:46:58 +00:00
|
|
|
APIHeaders["Authorization"] = token;
|
2017-08-22 15:43:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var passkeyItem = (HiddenItem)configData.GetDynamic("passkey");
|
|
|
|
if (passkeyItem != null)
|
|
|
|
{
|
|
|
|
passkey = passkeyItem.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task<dynamic> SendAPIRequest(string endpoint, object data)
|
|
|
|
{
|
|
|
|
var jsonData = JsonConvert.SerializeObject(data);
|
2020-09-21 16:39:47 +00:00
|
|
|
var result = await RequestWithCookiesAsync(
|
2020-06-11 15:09:27 +00:00
|
|
|
APIUrl + endpoint, method: RequestType.POST, referer: SiteLink, headers: APIHeaders, rawbody: jsonData);
|
2020-06-09 17:36:57 +00:00
|
|
|
if (!result.ContentString.StartsWith("{")) // not JSON => error
|
|
|
|
throw new ExceptionWithConfigData(result.ContentString, configData);
|
|
|
|
dynamic json = JsonConvert.DeserializeObject<dynamic>(result.ContentString);
|
2017-08-22 15:43:39 +00:00
|
|
|
return json;
|
2016-09-22 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2016-09-22 10:27:35 +00:00
|
|
|
{
|
2017-01-02 20:39:28 +00:00
|
|
|
LoadValuesFromJson(configJson);
|
2017-08-22 15:43:39 +00:00
|
|
|
APIHeaders.Remove("Authorization"); // remove any token from the headers
|
2016-09-22 10:27:35 +00:00
|
|
|
|
|
|
|
var pairs = new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{ "username", configData.Username.Value },
|
|
|
|
{ "password", configData.Password.Value }
|
|
|
|
};
|
|
|
|
|
2017-08-22 15:43:39 +00:00
|
|
|
var json = await SendAPIRequest("auth", pairs);
|
|
|
|
string token = json.token;
|
|
|
|
|
|
|
|
APIHeaders["Authorization"] = token;
|
|
|
|
|
|
|
|
var curuser = await SendAPIRequest("curuser", null);
|
2017-12-20 16:18:36 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(curuser.passkey.ToString()))
|
2017-12-03 05:47:50 +00:00
|
|
|
throw new ExceptionWithConfigData("got empty passkey: " + curuser.ToString(), configData);
|
|
|
|
passkey = curuser.passkey;
|
2017-08-22 15:43:39 +00:00
|
|
|
var passkeyItem = (HiddenItem)configData.GetDynamic("passkey");
|
2017-12-03 05:47:50 +00:00
|
|
|
passkeyItem.Value = passkey;
|
2017-08-22 15:43:39 +00:00
|
|
|
|
|
|
|
var tokenItem = (HiddenItem)configData.GetDynamic("token");
|
|
|
|
tokenItem.Value = token;
|
|
|
|
|
|
|
|
await ConfigureIfOK("", token.Length > 0, () =>
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2017-08-22 15:43:39 +00:00
|
|
|
throw new ExceptionWithConfigData(json.ToString(), configData);
|
2016-09-22 10:27:35 +00:00
|
|
|
});
|
2017-08-22 15:43:39 +00:00
|
|
|
|
2016-09-22 10:27:35 +00:00
|
|
|
return IndexerConfigurationStatus.RequiresTesting;
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2016-09-22 10:27:35 +00:00
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
2017-08-22 15:43:39 +00:00
|
|
|
|
|
|
|
var searchUrl = "browse";
|
2017-04-15 08:45:10 +00:00
|
|
|
var searchString = query.GetQueryString();
|
2020-03-26 22:15:28 +00:00
|
|
|
var queryCollection = new NameValueCollection
|
|
|
|
{
|
|
|
|
{ "orderC", "4" },
|
|
|
|
{ "orderD", "desc" },
|
|
|
|
{ "start", "0" },
|
|
|
|
{ "length", "100" }
|
|
|
|
};
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchString))
|
|
|
|
queryCollection.Add("search", searchString);
|
|
|
|
|
2017-08-22 15:43:39 +00:00
|
|
|
var cats = MapTorznabCapsToTrackers(query);
|
|
|
|
if (cats.Count > 0)
|
|
|
|
queryCollection.Add("cats", string.Join(",", cats));
|
|
|
|
|
2016-09-22 10:27:35 +00:00
|
|
|
searchUrl += "?" + queryCollection.GetQueryString();
|
|
|
|
|
2020-03-25 02:39:38 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(passkey))
|
2017-12-03 05:47:50 +00:00
|
|
|
await ApplyConfiguration(null);
|
|
|
|
|
2017-08-22 15:43:39 +00:00
|
|
|
var result = await SendAPIRequest(searchUrl, null);
|
2016-09-22 10:27:35 +00:00
|
|
|
try
|
|
|
|
{
|
2017-08-22 15:43:39 +00:00
|
|
|
if (result["error"] != null)
|
|
|
|
throw new Exception(result["error"].ToString());
|
2016-09-22 10:27:35 +00:00
|
|
|
|
2017-08-22 15:43:39 +00:00
|
|
|
var data = (JArray)result.data;
|
2017-10-29 06:50:47 +00:00
|
|
|
|
2017-08-22 15:43:39 +00:00
|
|
|
foreach (JArray torrent in data)
|
2016-09-22 10:27:35 +00:00
|
|
|
{
|
2017-08-22 15:43:39 +00:00
|
|
|
var torrentID = (long)torrent[2];
|
2020-03-26 22:15:28 +00:00
|
|
|
var comments = new Uri(SiteLink + "torrent/" + torrentID);
|
2017-08-22 15:43:39 +00:00
|
|
|
//var preDelaySeconds = (long)torrent[4];
|
2020-03-26 22:15:28 +00:00
|
|
|
var seeders = (int)torrent[6];
|
2017-08-22 15:43:39 +00:00
|
|
|
//var imdbRating = (double)torrent[8] / 10;
|
|
|
|
var genres = (string)torrent[9];
|
|
|
|
if (!string.IsNullOrWhiteSpace(genres))
|
2020-03-26 22:15:28 +00:00
|
|
|
genres = "Genres: " + genres;
|
2017-08-22 15:43:39 +00:00
|
|
|
// 12/13/14 unknown, probably IDs/name of the uploader
|
|
|
|
//var row12 = (long)torrent[12];
|
|
|
|
//var row13 = (string)torrent[13];
|
|
|
|
//var row14 = (long)torrent[14];
|
2020-03-26 22:15:28 +00:00
|
|
|
var link = new Uri(SiteLink + "sdownload/" + torrentID + "/" + passkey);
|
|
|
|
var publishDate = DateTimeUtil.UnixTimestampToDateTime((double)torrent[3]).ToLocalTime();
|
|
|
|
var downloadVolumeFactor = (long)torrent[10] switch
|
|
|
|
{
|
|
|
|
// Only Up
|
|
|
|
2 => 0,
|
|
|
|
// 50 % Down
|
|
|
|
1 => 0.5,
|
|
|
|
// All others 100% down
|
|
|
|
_ => 1,
|
|
|
|
};
|
|
|
|
var release = new ReleaseInfo
|
|
|
|
{
|
|
|
|
MinimumRatio = 0.8,
|
|
|
|
MinimumSeedTime = 172800, // 48 hours
|
|
|
|
Category = MapTrackerCatToNewznab(torrent[0].ToString()),
|
|
|
|
Title = torrent[1].ToString(),
|
|
|
|
Comments = comments,
|
|
|
|
Guid = comments,
|
|
|
|
Link = link,
|
|
|
|
PublishDate = publishDate,
|
|
|
|
Size = (long)torrent[5],
|
|
|
|
Seeders = seeders,
|
|
|
|
Peers = seeders + (int)torrent[7],
|
|
|
|
Description = genres,
|
|
|
|
UploadVolumeFactor = 1,
|
|
|
|
DownloadVolumeFactor = downloadVolumeFactor,
|
|
|
|
Grabs = (long)torrent[11]
|
|
|
|
};
|
2016-09-22 10:27:35 +00:00
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2017-08-22 15:43:39 +00:00
|
|
|
OnParseError(result.ToString(), ex);
|
2016-09-22 10:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|