2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2019-02-16 01:19:05 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2019-02-16 01:19:05 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
namespace Jackett.Common.Indexers
|
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2020-02-09 02:35:16 +00:00
|
|
|
public class Torrentscsv : BaseWebIndexer
|
|
|
|
{
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
private string ApiEndpoint => SiteLink + "service/search";
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
private new ConfigurationData configData
|
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => base.configData;
|
|
|
|
set => base.configData = value;
|
2019-02-16 01:19:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
public Torrentscsv(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps) : base(
|
2019-02-16 01:19:05 +00:00
|
|
|
name: "Torrents.csv",
|
|
|
|
description: "Torrents.csv is a self-hostable, open source torrent search engine and database",
|
|
|
|
link: "https://torrents-csv.ml/",
|
2020-04-03 22:37:42 +00:00
|
|
|
caps: new TorznabCapabilities
|
|
|
|
{
|
|
|
|
SupportsImdbMovieSearch = true
|
|
|
|
},
|
2020-02-09 02:35:16 +00:00
|
|
|
configService: configService,
|
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationData())
|
|
|
|
{
|
2019-02-16 01:19:05 +00:00
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
Language = "en-us";
|
|
|
|
Type = "public";
|
|
|
|
|
2019-02-22 00:42:39 +00:00
|
|
|
// dummy mappings for sonarr, radarr, etc since torrents.csv doesnt return categories
|
2020-02-09 02:35:16 +00:00
|
|
|
AddCategoryMapping(1000, TorznabCatType.Console);
|
|
|
|
AddCategoryMapping(2000, TorznabCatType.Movies);
|
|
|
|
AddCategoryMapping(3000, TorznabCatType.Audio);
|
|
|
|
AddCategoryMapping(4000, TorznabCatType.PC);
|
|
|
|
AddCategoryMapping(5000, TorznabCatType.TV);
|
|
|
|
AddCategoryMapping(6000, TorznabCatType.XXX);
|
|
|
|
AddCategoryMapping(7000, TorznabCatType.Other);
|
|
|
|
AddCategoryMapping(8000, TorznabCatType.Books);
|
2019-02-16 01:19:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
|
|
|
{
|
|
|
|
configData.LoadValuesFromJson(configJson);
|
|
|
|
var releases = await PerformQuery(new TorznabQuery());
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
await ConfigureIfOK(string.Empty, releases.Count() > 0, () =>
|
|
|
|
{
|
|
|
|
throw new Exception("Error: No data returned!");
|
2019-02-16 01:19:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) => await PerformQuery(query, 0);
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query, int attempts)
|
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
var searchString = query.GetQueryString();
|
|
|
|
if (string.IsNullOrEmpty(searchString))
|
2020-02-20 04:28:27 +00:00
|
|
|
searchString = "2020";
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
var queryCollection = new NameValueCollection
|
|
|
|
{
|
|
|
|
{ "q", searchString },
|
|
|
|
{ "size", "500" },
|
|
|
|
{ "type_", "torrent" }
|
|
|
|
};
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
var searchUrl = ApiEndpoint + "?" + queryCollection.GetQueryString();
|
|
|
|
var response = await RequestStringWithCookiesAndRetry(searchUrl, string.Empty);
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
try
|
|
|
|
{
|
2019-02-16 01:19:05 +00:00
|
|
|
var jsonStart = response.Content;
|
2020-02-09 02:35:16 +00:00
|
|
|
var jsonContent = JArray.Parse(jsonStart);
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
foreach (var torrent in jsonContent)
|
|
|
|
{
|
2019-02-16 01:19:05 +00:00
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
if (torrent == null)
|
|
|
|
throw new Exception("Error: No data returned!");
|
|
|
|
|
2019-02-16 01:19:05 +00:00
|
|
|
// construct magnet link from infohash with all public trackers known to man
|
2020-03-26 22:15:28 +00:00
|
|
|
// TODO move trackers to List for reuse elsewhere
|
|
|
|
// TODO dynamically generate list periodically from online tracker repositories like
|
|
|
|
// https://torrents.io/tracker-list/
|
|
|
|
// https://github.com/ngosang/trackerslist
|
2020-04-07 16:17:17 +00:00
|
|
|
var magnet = new Uri("magnet:?xt=urn:btih:" + torrent.Value<JToken>("infohash") +
|
2019-02-16 01:19:05 +00:00
|
|
|
"&tr=udp://tracker.coppersurfer.tk:6969/announce" +
|
2019-02-22 00:42:39 +00:00
|
|
|
"&tr=udp://tracker.leechers-paradise.org:6969/announce" +
|
|
|
|
"&tr=udp://tracker.internetwarriors.net:1337/announce" +
|
|
|
|
"&tr=udp://tracker.opentrackr.org:1337/announce" +
|
2019-02-16 01:19:05 +00:00
|
|
|
"&tr=udp://9.rarbg.to:2710/announce" +
|
|
|
|
"&tr=udp://exodus.desync.com:6969/announce" +
|
2019-02-22 00:42:39 +00:00
|
|
|
"&tr=udp://explodie.org:6969/announce" +
|
|
|
|
"&tr=udp://tracker2.itzmx.com:6961/announce" +
|
|
|
|
"&tr=udp://tracker1.itzmx.com:8080/announce" +
|
|
|
|
"&tr=udp://tracker.torrent.eu.org:451/announce" +
|
|
|
|
"&tr=udp://tracker.tiny-vps.com:6969/announce" +
|
|
|
|
"&tr=udp://tracker.port443.xyz:6969/announce" +
|
|
|
|
"&tr=udp://thetracker.org:80/announce" +
|
|
|
|
"&tr=udp://open.stealth.si:80/announce" +
|
|
|
|
"&tr=udp://open.demonii.si:1337/announce" +
|
|
|
|
"&tr=udp://ipv4.tracker.harry.lu:80/announce" +
|
|
|
|
"&tr=udp://denis.stalker.upeer.me:6969/announce" +
|
|
|
|
"&tr=udp://tracker1.wasabii.com.tw:6969/announce" +
|
|
|
|
"&tr=udp://tracker.dler.org:6969/announce" +
|
|
|
|
"&tr=udp://tracker.cyberia.is:6969/announce" +
|
|
|
|
"&tr=udp://tracker4.itzmx.com:2710/announce" +
|
|
|
|
"&tr=udp://tracker.uw0.xyz:6969/announce" +
|
|
|
|
"&tr=udp://tracker.moeking.me:6969/announce" +
|
|
|
|
"&tr=udp://retracker.lanta-net.ru:2710/announce" +
|
|
|
|
"&tr=udp://tracker.nyaa.uk:6969/announce" +
|
|
|
|
"&tr=udp://tracker.novg.net:6969/announce" +
|
|
|
|
"&tr=udp://tracker.iamhansen.xyz:2000/announce" +
|
|
|
|
"&tr=udp://tracker.filepit.to:6969/announce" +
|
|
|
|
"&tr=udp://tracker.dyn.im:6969/announce" +
|
|
|
|
"&tr=udp://torrentclub.tech:6969/announce" +
|
|
|
|
"&tr=udp://tracker.tvunderground.org.ru:3218/announce" +
|
|
|
|
"&tr=udp://tracker.open-tracker.org:1337/announce" +
|
2020-03-26 22:15:28 +00:00
|
|
|
"&tr=udp://tracker.justseed.it:1337/announce");
|
2019-02-16 01:19:05 +00:00
|
|
|
|
|
|
|
// convert unix timestamp to human readable date
|
2020-02-09 02:35:16 +00:00
|
|
|
double createdunix = torrent.Value<long>("created_unix");
|
2020-02-10 22:16:19 +00:00
|
|
|
var dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
2020-02-09 02:35:16 +00:00
|
|
|
dateTime = dateTime.AddSeconds(createdunix);
|
2020-03-26 22:15:28 +00:00
|
|
|
var seeders = torrent.Value<int>("seeders");
|
|
|
|
var grabs = ParseUtil.CoerceInt(torrent.Value<string>("completed") ?? "0");
|
|
|
|
var release = new ReleaseInfo
|
|
|
|
{
|
|
|
|
Title = torrent.Value<string>("name"),
|
|
|
|
MagnetUri = magnet,
|
|
|
|
// there is no comments or details link so we point to the web site instead
|
|
|
|
Comments = new Uri(SiteLink),
|
|
|
|
Guid = magnet,
|
|
|
|
Link = magnet,
|
|
|
|
InfoHash = torrent.Value<JToken>("infohash").ToString(),
|
|
|
|
PublishDate = dateTime,
|
|
|
|
Seeders = seeders,
|
|
|
|
Peers = torrent.Value<int>("leechers") + seeders,
|
|
|
|
Size = torrent.Value<long>("size_bytes"),
|
|
|
|
Grabs = grabs,
|
|
|
|
MinimumRatio = 1,
|
|
|
|
MinimumSeedTime = 172800, // 48 hours
|
|
|
|
DownloadVolumeFactor = 0,
|
|
|
|
UploadVolumeFactor = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO isn't there already a function for this?
|
2020-02-09 02:35:16 +00:00
|
|
|
// dummy mappings for sonarr, radarr, etc
|
2020-02-10 22:16:19 +00:00
|
|
|
var categories = string.Join(";", MapTorznabCapsToTrackers(query));
|
2020-02-09 02:35:16 +00:00
|
|
|
if (!string.IsNullOrEmpty(categories))
|
|
|
|
{
|
|
|
|
if (categories.Contains("1000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.Console.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
if (categories.Contains("2000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.Movies.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
if (categories.Contains("3000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.Audio.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
if (categories.Contains("4000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.PC.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
if (categories.Contains("5000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.TV.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
if (categories.Contains("6000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.XXX.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
if (categories.Contains("7000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.Other.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
if (categories.Contains("8000"))
|
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.Books.ID };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// for null category
|
2020-03-26 22:15:28 +00:00
|
|
|
else
|
2020-02-09 02:35:16 +00:00
|
|
|
{
|
2019-02-22 00:42:39 +00:00
|
|
|
release.Category = new List<int> { TorznabCatType.Other.ID };
|
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
releases.Add(release);
|
2019-02-16 01:19:05 +00:00
|
|
|
}
|
2020-02-09 02:35:16 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(response.Content, ex);
|
2019-02-16 01:19:05 +00:00
|
|
|
}
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|