mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
sharewoodapi: refactor (#14169)
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Jackett.Common.Extensions;
|
||||||
using Jackett.Common.Models;
|
using Jackett.Common.Models;
|
||||||
using Jackett.Common.Models.IndexerConfig;
|
using Jackett.Common.Models.IndexerConfig;
|
||||||
using Jackett.Common.Services.Interfaces;
|
using Jackett.Common.Services.Interfaces;
|
||||||
@@ -15,8 +17,6 @@ using NLog;
|
|||||||
using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
|
using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
|
||||||
using WebClient = Jackett.Common.Utils.Clients.WebClient;
|
using WebClient = Jackett.Common.Utils.Clients.WebClient;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Jackett.Common.Indexers
|
namespace Jackett.Common.Indexers
|
||||||
{
|
{
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
@@ -51,11 +51,11 @@ namespace Jackett.Common.Indexers
|
|||||||
// requestDelay for API Limit (1 request per 2 seconds)
|
// requestDelay for API Limit (1 request per 2 seconds)
|
||||||
webclient.requestDelay = 2.1;
|
webclient.requestDelay = 2.1;
|
||||||
|
|
||||||
var FreeLeechOnly = new BoolConfigurationItem("Search freeleech only");
|
var freeLeechOnly = new BoolConfigurationItem("Search freeleech only");
|
||||||
configData.AddDynamic("freeleechonly", FreeLeechOnly);
|
configData.AddDynamic("freeleechonly", freeLeechOnly);
|
||||||
|
|
||||||
var ReplaceMulti = new BoolConfigurationItem("Replace MULTi by another language in release name");
|
var replaceMulti = new BoolConfigurationItem("Replace MULTi by another language in release name");
|
||||||
configData.AddDynamic("replacemulti", ReplaceMulti);
|
configData.AddDynamic("replacemulti", replaceMulti);
|
||||||
|
|
||||||
// Configure the language select option for MULTI
|
// Configure the language select option for MULTI
|
||||||
var languageSelect = new SingleSelectConfigurationItem("Replace MULTi by this language", new Dictionary<string, string>
|
var languageSelect = new SingleSelectConfigurationItem("Replace MULTi by this language", new Dictionary<string, string>
|
||||||
@@ -68,11 +68,10 @@ namespace Jackett.Common.Indexers
|
|||||||
{"MULTi VOSTFR", "MULTi VOSTFR"}
|
{"MULTi VOSTFR", "MULTi VOSTFR"}
|
||||||
})
|
})
|
||||||
{ Value = "FRENCH" };
|
{ Value = "FRENCH" };
|
||||||
;
|
|
||||||
configData.AddDynamic("languageid", languageSelect);
|
configData.AddDynamic("languageid", languageSelect);
|
||||||
|
|
||||||
var ReplaceVostfr = new BoolConfigurationItem("Replace VOSTFR and SUBFRENCH with ENGLISH");
|
var replaceVostfr = new BoolConfigurationItem("Replace VOSTFR and SUBFRENCH with ENGLISH");
|
||||||
configData.AddDynamic("replacevostfr", ReplaceVostfr);
|
configData.AddDynamic("replacevostfr", replaceVostfr);
|
||||||
|
|
||||||
EnableConfigurableRetryAttempts();
|
EnableConfigurableRetryAttempts();
|
||||||
}
|
}
|
||||||
@@ -119,24 +118,24 @@ namespace Jackett.Common.Indexers
|
|||||||
caps.Categories.AddCategoryMapping(14, TorznabCatType.TVOther, "Emission TV");
|
caps.Categories.AddCategoryMapping(14, TorznabCatType.TVOther, "Emission TV");
|
||||||
caps.Categories.AddCategoryMapping(15, TorznabCatType.TVOther, "Spectacle/Concert");
|
caps.Categories.AddCategoryMapping(15, TorznabCatType.TVOther, "Spectacle/Concert");
|
||||||
caps.Categories.AddCategoryMapping(16, TorznabCatType.TVSport, "Sport");
|
caps.Categories.AddCategoryMapping(16, TorznabCatType.TVSport, "Sport");
|
||||||
caps.Categories.AddCategoryMapping(17, TorznabCatType.AudioOther, "Karaoké Vidéo");
|
caps.Categories.AddCategoryMapping(17, TorznabCatType.AudioVideo, "Karaoké Vidéo");
|
||||||
caps.Categories.AddCategoryMapping(18, TorznabCatType.AudioOther, "Karaoké");
|
caps.Categories.AddCategoryMapping(18, TorznabCatType.AudioOther, "Karaoké");
|
||||||
caps.Categories.AddCategoryMapping(20, TorznabCatType.Audio, "Musique");
|
caps.Categories.AddCategoryMapping(20, TorznabCatType.Audio, "Musique");
|
||||||
caps.Categories.AddCategoryMapping(21, TorznabCatType.AudioOther, "Podcast");
|
caps.Categories.AddCategoryMapping(21, TorznabCatType.AudioOther, "Podcast");
|
||||||
caps.Categories.AddCategoryMapping(22, TorznabCatType.Audio, "Sample");
|
caps.Categories.AddCategoryMapping(22, TorznabCatType.AudioOther, "Sample");
|
||||||
caps.Categories.AddCategoryMapping(23, TorznabCatType.AudioAudiobook, "Ebook Audio");
|
caps.Categories.AddCategoryMapping(23, TorznabCatType.AudioAudiobook, "Ebook Audio");
|
||||||
caps.Categories.AddCategoryMapping(24, TorznabCatType.Books, "BD");
|
caps.Categories.AddCategoryMapping(24, TorznabCatType.BooksEBook, "BD");
|
||||||
caps.Categories.AddCategoryMapping(25, TorznabCatType.BooksComics, "Comic");
|
caps.Categories.AddCategoryMapping(25, TorznabCatType.BooksComics, "Comic");
|
||||||
caps.Categories.AddCategoryMapping(26, TorznabCatType.BooksOther, "Manga");
|
caps.Categories.AddCategoryMapping(26, TorznabCatType.BooksOther, "Manga");
|
||||||
caps.Categories.AddCategoryMapping(27, TorznabCatType.Books, "Livre");
|
caps.Categories.AddCategoryMapping(27, TorznabCatType.Books, "Livre");
|
||||||
caps.Categories.AddCategoryMapping(28, TorznabCatType.BooksMags, "Presse");
|
caps.Categories.AddCategoryMapping(28, TorznabCatType.BooksMags, "Presse");
|
||||||
caps.Categories.AddCategoryMapping(29, TorznabCatType.Audio, "Application Linux");
|
caps.Categories.AddCategoryMapping(29, TorznabCatType.PC, "Application Linux");
|
||||||
caps.Categories.AddCategoryMapping(30, TorznabCatType.PC, "Application Window");
|
caps.Categories.AddCategoryMapping(30, TorznabCatType.PC0day, "Application Window");
|
||||||
caps.Categories.AddCategoryMapping(31, TorznabCatType.PCMac, "Application Mac");
|
caps.Categories.AddCategoryMapping(31, TorznabCatType.PCMac, "Application Mac");
|
||||||
caps.Categories.AddCategoryMapping(34, TorznabCatType.PCMobileiOS, "Application Smartphone/Tablette");
|
caps.Categories.AddCategoryMapping(34, TorznabCatType.PCMobileiOS, "Application Smartphone/Tablette");
|
||||||
caps.Categories.AddCategoryMapping(34, TorznabCatType.PCMobileAndroid, "Application Smartphone/Tablette");
|
caps.Categories.AddCategoryMapping(34, TorznabCatType.PCMobileAndroid, "Application Smartphone/Tablette");
|
||||||
caps.Categories.AddCategoryMapping(35, TorznabCatType.Other, "GPS");
|
caps.Categories.AddCategoryMapping(35, TorznabCatType.PCMobileOther, "GPS");
|
||||||
caps.Categories.AddCategoryMapping(36, TorznabCatType.Audio, "Jeux Linux");
|
caps.Categories.AddCategoryMapping(36, TorznabCatType.PCGames, "Jeux Linux");
|
||||||
caps.Categories.AddCategoryMapping(37, TorznabCatType.PCGames, "Jeux Windows");
|
caps.Categories.AddCategoryMapping(37, TorznabCatType.PCGames, "Jeux Windows");
|
||||||
caps.Categories.AddCategoryMapping(39, TorznabCatType.ConsoleNDS, "Jeux Nintendo");
|
caps.Categories.AddCategoryMapping(39, TorznabCatType.ConsoleNDS, "Jeux Nintendo");
|
||||||
caps.Categories.AddCategoryMapping(39, TorznabCatType.ConsoleWii, "Jeux Nintendo");
|
caps.Categories.AddCategoryMapping(39, TorznabCatType.ConsoleWii, "Jeux Nintendo");
|
||||||
@@ -149,12 +148,10 @@ namespace Jackett.Common.Indexers
|
|||||||
caps.Categories.AddCategoryMapping(45, TorznabCatType.XXXOther, "XXX Hentai");
|
caps.Categories.AddCategoryMapping(45, TorznabCatType.XXXOther, "XXX Hentai");
|
||||||
caps.Categories.AddCategoryMapping(47, TorznabCatType.XXXImageSet, "XXX Images");
|
caps.Categories.AddCategoryMapping(47, TorznabCatType.XXXImageSet, "XXX Images");
|
||||||
caps.Categories.AddCategoryMapping(48, TorznabCatType.XXXOther, "XXX Jeu-Vidéo");
|
caps.Categories.AddCategoryMapping(48, TorznabCatType.XXXOther, "XXX Jeu-Vidéo");
|
||||||
caps.Categories.AddCategoryMapping(50, TorznabCatType.OtherMisc, "Formation Logiciels");
|
|
||||||
caps.Categories.AddCategoryMapping(49, TorznabCatType.OtherMisc, "Formations Vidéos");
|
caps.Categories.AddCategoryMapping(49, TorznabCatType.OtherMisc, "Formations Vidéos");
|
||||||
|
caps.Categories.AddCategoryMapping(50, TorznabCatType.OtherMisc, "Formation Logiciels");
|
||||||
caps.Categories.AddCategoryMapping(51, TorznabCatType.XXXOther, "XXX Ebooks");
|
caps.Categories.AddCategoryMapping(51, TorznabCatType.XXXOther, "XXX Ebooks");
|
||||||
caps.Categories.AddCategoryMapping(52, TorznabCatType.AudioVideo, "Vidéos-Clips");
|
caps.Categories.AddCategoryMapping(52, TorznabCatType.AudioVideo, "Vidéos-Clips");
|
||||||
caps.Categories.AddCategoryMapping(51, TorznabCatType.XXXOther, "XXX Ebooks");
|
|
||||||
caps.Categories.AddCategoryMapping(51, TorznabCatType.XXXOther, "XXX Ebooks");
|
|
||||||
|
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
@@ -176,6 +173,7 @@ namespace Jackett.Common.Indexers
|
|||||||
private bool GetReplaceMulti => ((BoolConfigurationItem)configData.GetDynamic("replacemulti")).Value;
|
private bool GetReplaceMulti => ((BoolConfigurationItem)configData.GetDynamic("replacemulti")).Value;
|
||||||
private string GetLang => ((SingleSelectConfigurationItem)configData.GetDynamic("languageid")).Value;
|
private string GetLang => ((SingleSelectConfigurationItem)configData.GetDynamic("languageid")).Value;
|
||||||
private bool GetReplaceVostfr => ((BoolConfigurationItem)configData.GetDynamic("replacevostfr")).Value;
|
private bool GetReplaceVostfr => ((BoolConfigurationItem)configData.GetDynamic("replacevostfr")).Value;
|
||||||
|
|
||||||
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
||||||
{
|
{
|
||||||
LoadValuesFromJson(configJson);
|
LoadValuesFromJson(configJson);
|
||||||
@@ -185,48 +183,53 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
var releases = await PerformQuery(new TorznabQuery());
|
var releases = await PerformQuery(new TorznabQuery());
|
||||||
|
|
||||||
await ConfigureIfOK(string.Empty, releases.Any(),
|
await ConfigureIfOK(string.Empty, releases.Any(), () => throw new Exception("Could not find releases."));
|
||||||
() => throw new Exception("Could not find releases."));
|
|
||||||
|
|
||||||
return IndexerConfigurationStatus.Completed;
|
return IndexerConfigurationStatus.Completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 Mapcats = MapTorznabCapsToTrackers(query);
|
|
||||||
|
|
||||||
if (Mapcats.Count == 0)
|
var categoryMapping = MapTorznabCapsToTrackers(query).Distinct().ToList();
|
||||||
{ // NO CATEGORIES ==> RSS SEARCH
|
|
||||||
Mapcats.Add("1000");
|
if (!categoryMapping.Any())
|
||||||
}
|
|
||||||
foreach (var cats in Mapcats)
|
|
||||||
{
|
{
|
||||||
|
// NO CATEGORIES ==> RSS SEARCH
|
||||||
|
categoryMapping.Add("1000");
|
||||||
|
}
|
||||||
|
|
||||||
|
var term = query.GetQueryString().Trim();
|
||||||
|
|
||||||
|
foreach (var categoryId in categoryMapping)
|
||||||
|
{
|
||||||
var searchUrl = SearchUrl;
|
var searchUrl = SearchUrl;
|
||||||
|
|
||||||
var qc = new List<KeyValuePair<string, string>> // NameValueCollection don't support cat[]=19&cat[]=6
|
var parameters = new NameValueCollection
|
||||||
{
|
{
|
||||||
{"limit", "25"}
|
{ "limit", categoryId != "1000" ? "25" : "100" }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Convert.ToInt32(cats) != 1000)
|
if (categoryId != "1000")
|
||||||
{
|
{
|
||||||
qc.Add("subcategory", cats);
|
parameters.Set("subcategory", categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.GetQueryString() != "")
|
if (term.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
qc.Add("name", query.GetQueryString());
|
parameters.Set("name", term);
|
||||||
searchUrl = searchUrl + "/search";
|
searchUrl += "/search";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
searchUrl = searchUrl + "/last-torrents";
|
searchUrl += "/last-torrents";
|
||||||
}
|
}
|
||||||
|
|
||||||
searchUrl = searchUrl + "?" + qc.GetQueryString();
|
if (parameters.Count > 0)
|
||||||
|
{
|
||||||
|
searchUrl += $"?{parameters.GetQueryString()}";
|
||||||
|
}
|
||||||
|
|
||||||
var response = await RequestWithCookiesAsync(searchUrl);
|
var response = await RequestWithCookiesAsync(searchUrl);
|
||||||
if (response.Status == HttpStatusCode.Unauthorized)
|
if (response.Status == HttpStatusCode.Unauthorized)
|
||||||
@@ -234,7 +237,9 @@ namespace Jackett.Common.Indexers
|
|||||||
response = await RequestWithCookiesAsync(searchUrl);
|
response = await RequestWithCookiesAsync(searchUrl);
|
||||||
}
|
}
|
||||||
else if (response.Status != HttpStatusCode.OK)
|
else if (response.Status != HttpStatusCode.OK)
|
||||||
|
{
|
||||||
throw new Exception($"Unknown error in search: {response.ContentString}");
|
throw new Exception($"Unknown error in search: {response.ContentString}");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -243,61 +248,44 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
var id = row.Value<string>("id");
|
var id = row.Value<string>("id");
|
||||||
var link = new Uri($"{SearchUrl}/{id}/download");
|
var link = new Uri($"{SearchUrl}/{id}/download");
|
||||||
var urlStr = row.Value<string>("slug");
|
var slug = row.Value<string>("slug");
|
||||||
var details = new Uri($"{SiteLink}torrents/{urlStr}.{id}");
|
var details = new Uri($"{SiteLink}torrents/{slug}.{id}");
|
||||||
DateTime publishDate = DateTime.Parse(row.Value<string>("created_at"), CultureInfo.InvariantCulture);
|
|
||||||
var cat = row.Value<string>("subcategory_id");
|
var cat = row.Value<string>("subcategory_id");
|
||||||
|
if (Convert.ToInt32(categoryId) != 1000)
|
||||||
if (Convert.ToInt32(cats) != 1000)
|
|
||||||
{
|
{
|
||||||
if (Convert.ToInt32(cats) < 8) //USE CATEGORIES
|
// USE CATEGORIES OR SUBCATEGORIES
|
||||||
{
|
cat = row.Value<string>(Convert.ToInt32(categoryId) < 8 ? "category_id" : "subcategory_id");
|
||||||
cat = row.Value<string>("category_id");
|
|
||||||
}
|
|
||||||
else //USE SUBCATEGORIES
|
|
||||||
{
|
|
||||||
cat = row.Value<string>("subcategory_id");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long dlVolumeFactor = 1;
|
var dlVolumeFactor = row.Value<bool>("free") ? 0 : 1;
|
||||||
long ulVolumeFactor = 1;
|
var ulVolumeFactor = row.Value<bool>("doubleup") ? 2 : 1;
|
||||||
if (row.Value<bool>("free") == true)
|
|
||||||
{
|
|
||||||
dlVolumeFactor = 0;
|
|
||||||
}
|
|
||||||
if (row.Value<bool>("doubleup") == true)
|
|
||||||
{
|
|
||||||
ulVolumeFactor = 2;
|
|
||||||
}
|
|
||||||
var sizeString = row.Value<string>("size");
|
|
||||||
var title = row.Value<string>("name");
|
var title = row.Value<string>("name");
|
||||||
|
|
||||||
//SPECIAL CASES
|
//SPECIAL CASES
|
||||||
|
if (GetFreeLeech && dlVolumeFactor == 1)
|
||||||
if (GetFreeLeech == true && dlVolumeFactor == 1)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (GetReplaceMulti == true)
|
if (GetReplaceMulti)
|
||||||
{
|
{
|
||||||
title = MultiRename(title, GetLang);
|
title = MultiRename(title, GetLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetReplaceVostfr == true)
|
if (GetReplaceVostfr)
|
||||||
{
|
{
|
||||||
title = VostfrRename(title, "ENGLISH");
|
title = VostfrRename(title, "ENGLISH");
|
||||||
}
|
}
|
||||||
|
|
||||||
var release = new ReleaseInfo
|
var release = new ReleaseInfo
|
||||||
{
|
{
|
||||||
|
|
||||||
Title = title,
|
|
||||||
Link = link,
|
|
||||||
Details = details,
|
|
||||||
Guid = details,
|
Guid = details,
|
||||||
|
Details = details,
|
||||||
|
Link = link,
|
||||||
|
Title = title,
|
||||||
Category = MapTrackerCatToNewznab(cat),
|
Category = MapTrackerCatToNewznab(cat),
|
||||||
PublishDate = publishDate,
|
PublishDate = DateTime.Parse(row.Value<string>("created_at"), CultureInfo.InvariantCulture),
|
||||||
Size = ParseUtil.GetBytes(sizeString),
|
Size = ParseUtil.GetBytes(row.Value<string>("size")),
|
||||||
Grabs = row.Value<long>("times_completed"),
|
Grabs = row.Value<long>("times_completed"),
|
||||||
Seeders = row.Value<long>("seeders"),
|
Seeders = row.Value<long>("seeders"),
|
||||||
Peers = row.Value<long>("leechers") + row.Value<long>("seeders"),
|
Peers = row.Value<long>("leechers") + row.Value<long>("seeders"),
|
||||||
@@ -321,12 +309,14 @@ namespace Jackett.Common.Indexers
|
|||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<byte[]> Download(Uri link)
|
||||||
{
|
{
|
||||||
var response = await RequestWithCookiesAsync(link.ToString());
|
var response = await RequestWithCookiesAsync(link.ToString());
|
||||||
|
|
||||||
if (response.Status == HttpStatusCode.Unauthorized)
|
if (response.Status == HttpStatusCode.Unauthorized)
|
||||||
{
|
{
|
||||||
response = await RequestWithCookiesAsync(link.ToString());
|
response = await RequestWithCookiesAsync(link.ToString());
|
||||||
}
|
}
|
||||||
else if (response.Status != HttpStatusCode.OK)
|
else if (response.Status != HttpStatusCode.OK)
|
||||||
throw new Exception($"Unknown error in download: {response.ContentBytes}");
|
throw new Exception($"Unknown error in download: {response.ContentBytes}");
|
||||||
|
|
||||||
return response.ContentBytes;
|
return response.ContentBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user