mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Update Corsarored.cs
This commit is contained in:
@@ -1,254 +1,254 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
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;
|
||||||
using Jackett.Common.Models.IndexerConfig;
|
using Jackett.Common.Models.IndexerConfig;
|
||||||
using Jackett.Common.Services.Interfaces;
|
using Jackett.Common.Services.Interfaces;
|
||||||
using Jackett.Common.Utils;
|
using Jackett.Common.Utils;
|
||||||
using Jackett.Common.Utils.Clients;
|
using Jackett.Common.Utils.Clients;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NLog;
|
using NLog;
|
||||||
using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
|
using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
|
||||||
|
|
||||||
namespace Jackett.Common.Indexers
|
namespace Jackett.Common.Indexers
|
||||||
{
|
{
|
||||||
public class Corsarored : BaseWebIndexer
|
public class Corsarored : BaseWebIndexer
|
||||||
{
|
{
|
||||||
private string APILatest { get { return SiteLink + "api/latests"; } }
|
private string APILatest { get { return SiteLink + "api/latests"; } }
|
||||||
private string APISearch { get { return SiteLink + "api/search"; } }
|
private string APISearch { get { return SiteLink + "api/search"; } }
|
||||||
|
|
||||||
private Dictionary<string, string> APIHeaders = new Dictionary<string, string>()
|
private Dictionary<string, string> APIHeaders = new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{"Content-Type", "application/json"},
|
{"Content-Type", "application/json"},
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly int MAX_SEARCH_PAGE_LIMIT = 8; // 1page 25 items, 200
|
private readonly int MAX_SEARCH_PAGE_LIMIT = 8; // 1page 25 items, 200
|
||||||
|
|
||||||
private new ConfigurationData configData
|
private new ConfigurationData configData
|
||||||
{
|
{
|
||||||
get { return (ConfigurationData)base.configData; }
|
get { return (ConfigurationData)base.configData; }
|
||||||
set { base.configData = value; }
|
set { base.configData = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Corsarored(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
public Corsarored(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
||||||
: base(name: "Corsaro.red",
|
: base(name: "Corsaro.red",
|
||||||
description: "Italian Torrents",
|
description: "Italian Torrents",
|
||||||
link: "https://corsaro.red/",
|
link: "https://corsaro.red/",
|
||||||
caps: new TorznabCapabilities(),
|
caps: new TorznabCapabilities(),
|
||||||
configService: configService,
|
configService: configService,
|
||||||
client: wc,
|
client: wc,
|
||||||
logger: l,
|
logger: l,
|
||||||
p: ps,
|
p: ps,
|
||||||
configData: new ConfigurationData())
|
configData: new ConfigurationData())
|
||||||
{
|
{
|
||||||
Encoding = Encoding.UTF8;
|
Encoding = Encoding.UTF8;
|
||||||
Language = "it-it";
|
Language = "it-it";
|
||||||
Type = "public";
|
Type = "public";
|
||||||
|
|
||||||
//wc.requestDelay = 2.5;
|
//wc.requestDelay = 2.5;
|
||||||
|
|
||||||
// TNTVillage cats
|
// TNTVillage cats
|
||||||
AddCategoryMapping(1, TorznabCatType.TV, "TV");
|
AddCategoryMapping(1, TorznabCatType.TV, "TV");
|
||||||
AddCategoryMapping(2, TorznabCatType.Audio, "Music");
|
AddCategoryMapping(2, TorznabCatType.Audio, "Music");
|
||||||
AddCategoryMapping(3, TorznabCatType.BooksEbook, "Books");
|
AddCategoryMapping(3, TorznabCatType.BooksEbook, "Books");
|
||||||
AddCategoryMapping(4, TorznabCatType.Movies, "Movies");
|
AddCategoryMapping(4, TorznabCatType.Movies, "Movies");
|
||||||
AddCategoryMapping(6, TorznabCatType.PC, "Software");
|
AddCategoryMapping(6, TorznabCatType.PC, "Software");
|
||||||
AddCategoryMapping(7, TorznabCatType.TVAnime, "Anime");
|
AddCategoryMapping(7, TorznabCatType.TVAnime, "Anime");
|
||||||
AddCategoryMapping(8, TorznabCatType.TVAnime, "Cartoons");
|
AddCategoryMapping(8, TorznabCatType.TVAnime, "Cartoons");
|
||||||
AddCategoryMapping(9, TorznabCatType.PC, "Software");
|
AddCategoryMapping(9, TorznabCatType.PC, "Software");
|
||||||
AddCategoryMapping(10, TorznabCatType.PC0day, "Software");
|
AddCategoryMapping(10, TorznabCatType.PC0day, "Software");
|
||||||
AddCategoryMapping(11, TorznabCatType.PCGames, "Games");
|
AddCategoryMapping(11, TorznabCatType.PCGames, "Games");
|
||||||
AddCategoryMapping(12, TorznabCatType.Console, "Games");
|
AddCategoryMapping(12, TorznabCatType.Console, "Games");
|
||||||
AddCategoryMapping(13, TorznabCatType.Books, "Books");
|
AddCategoryMapping(13, TorznabCatType.Books, "Books");
|
||||||
AddCategoryMapping(14, TorznabCatType.TVDocumentary, "Documentaries");
|
AddCategoryMapping(14, TorznabCatType.TVDocumentary, "Documentaries");
|
||||||
AddCategoryMapping(21, TorznabCatType.AudioVideo, "Music Video");
|
AddCategoryMapping(21, TorznabCatType.AudioVideo, "Music Video");
|
||||||
AddCategoryMapping(22, TorznabCatType.TVSport, "Sport");
|
AddCategoryMapping(22, TorznabCatType.TVSport, "Sport");
|
||||||
AddCategoryMapping(23, TorznabCatType.TV, "TV");
|
AddCategoryMapping(23, TorznabCatType.TV, "TV");
|
||||||
AddCategoryMapping(24, TorznabCatType.TV, "TV");
|
AddCategoryMapping(24, TorznabCatType.TV, "TV");
|
||||||
AddCategoryMapping(26, TorznabCatType.Console, "Games");
|
AddCategoryMapping(26, TorznabCatType.Console, "Games");
|
||||||
AddCategoryMapping(27, TorznabCatType.Other, "Wallpaper");
|
AddCategoryMapping(27, TorznabCatType.Other, "Wallpaper");
|
||||||
AddCategoryMapping(29, TorznabCatType.TV, "TV Series");
|
AddCategoryMapping(29, TorznabCatType.TV, "TV Series");
|
||||||
AddCategoryMapping(30, TorznabCatType.BooksComics, "Comics");
|
AddCategoryMapping(30, TorznabCatType.BooksComics, "Comics");
|
||||||
AddCategoryMapping(31, TorznabCatType.TV, "TV");
|
AddCategoryMapping(31, TorznabCatType.TV, "TV");
|
||||||
AddCategoryMapping(32, TorznabCatType.Console, "Games");
|
AddCategoryMapping(32, TorznabCatType.Console, "Games");
|
||||||
AddCategoryMapping(34, TorznabCatType.AudioAudiobook, "Audiobook");
|
AddCategoryMapping(34, TorznabCatType.AudioAudiobook, "Audiobook");
|
||||||
AddCategoryMapping(35, TorznabCatType.Audio, "Music");
|
AddCategoryMapping(35, TorznabCatType.Audio, "Music");
|
||||||
AddCategoryMapping(36, TorznabCatType.Books, "Books");
|
AddCategoryMapping(36, TorznabCatType.Books, "Books");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
||||||
{
|
{
|
||||||
base.LoadValuesFromJson(configJson);
|
base.LoadValuesFromJson(configJson);
|
||||||
var releases = await PerformQuery(new TorznabQuery());
|
var releases = await PerformQuery(new TorznabQuery());
|
||||||
|
|
||||||
await ConfigureIfOK(String.Empty, releases.Count() > 0, () =>
|
await ConfigureIfOK(String.Empty, releases.Count() > 0, () =>
|
||||||
{
|
{
|
||||||
throw new Exception("Could not find release from this URL.");
|
throw new Exception("Could not find release from this URL.");
|
||||||
});
|
});
|
||||||
|
|
||||||
return IndexerConfigurationStatus.Completed;
|
return IndexerConfigurationStatus.Completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private dynamic checkResponse(WebClientStringResult result)
|
private dynamic checkResponse(WebClientStringResult result)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dynamic json = JsonConvert.DeserializeObject<dynamic>(result.Content);
|
dynamic json = JsonConvert.DeserializeObject<dynamic>(result.Content);
|
||||||
|
|
||||||
if (json is JObject)
|
if (json is JObject)
|
||||||
if (json["ok"] != null && ((bool)json["ok"]) == false)
|
if (json["ok"] != null && ((bool)json["ok"]) == false)
|
||||||
throw new Exception("Server error");
|
throw new Exception("Server error");
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.Error("checkResponse() Error: ", e.Message);
|
logger.Error("checkResponse() Error: ", e.Message);
|
||||||
throw new ExceptionWithConfigData(result.Content, configData);
|
throw new ExceptionWithConfigData(result.Content, configData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<dynamic> SendAPIRequest(List<KeyValuePair<string, string>> data)
|
private async Task<dynamic> SendAPIRequest(List<KeyValuePair<string, string>> data)
|
||||||
{
|
{
|
||||||
var jsonData = JsonConvert.SerializeObject(data);
|
var jsonData = JsonConvert.SerializeObject(data);
|
||||||
var result = await PostDataWithCookiesAndRetry(APISearch, data, null, SiteLink, APIHeaders, null, true);
|
var result = await PostDataWithCookiesAndRetry(APISearch, data, null, SiteLink, APIHeaders, null, true);
|
||||||
return checkResponse(result);
|
return checkResponse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<dynamic> SendAPIRequestLatest()
|
private async Task<dynamic> SendAPIRequestLatest()
|
||||||
{
|
{
|
||||||
var result = await RequestStringWithCookiesAndRetry(APILatest, null, SiteLink, APIHeaders);
|
var result = await RequestStringWithCookiesAndRetry(APILatest, null, SiteLink, APIHeaders);
|
||||||
return checkResponse(result);
|
return checkResponse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 searchString = query.GetQueryString();
|
var searchString = query.GetQueryString();
|
||||||
var queryCollection = new List<KeyValuePair<string, string>>();
|
var queryCollection = new List<KeyValuePair<string, string>>();
|
||||||
int page = 0;
|
int page = 0;
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(searchString))
|
if (!string.IsNullOrWhiteSpace(searchString))
|
||||||
queryCollection.Add("term", searchString);
|
queryCollection.Add("term", searchString);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// no term execute latest search
|
// no term execute latest search
|
||||||
var result = await SendAPIRequestLatest();
|
var result = await SendAPIRequestLatest();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// this time is a jarray
|
// this time is a jarray
|
||||||
JArray json = (JArray)result;
|
JArray json = (JArray)result;
|
||||||
|
|
||||||
foreach (var torrent in json)
|
foreach (var torrent in json)
|
||||||
{
|
{
|
||||||
// add release
|
// add release
|
||||||
releases.Add(makeRelease(torrent));
|
releases.Add(makeRelease(torrent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OnParseError(result.ToString(), ex);
|
OnParseError(result.ToString(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return releases;
|
return releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cats = MapTorznabCapsToTrackers(query);
|
var cats = MapTorznabCapsToTrackers(query);
|
||||||
if (cats.Count > 0)
|
if (cats.Count > 0)
|
||||||
queryCollection.Add("category", string.Join(",", cats));
|
queryCollection.Add("category", string.Join(",", cats));
|
||||||
else
|
else
|
||||||
queryCollection.Add("category", "0"); // set ALL category
|
queryCollection.Add("category", "0"); // set ALL category
|
||||||
|
|
||||||
// lazy horrible page initialization
|
// lazy horrible page initialization
|
||||||
queryCollection.Add("page", page.ToString());
|
queryCollection.Add("page", page.ToString());
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// update page number
|
// update page number
|
||||||
queryCollection.RemoveAt(queryCollection.Count - 1); // remove last elem: page number
|
queryCollection.RemoveAt(queryCollection.Count - 1); // remove last elem: page number
|
||||||
queryCollection.Add("page", (++page).ToString());
|
queryCollection.Add("page", (++page).ToString());
|
||||||
|
|
||||||
var result = await SendAPIRequest(queryCollection);
|
var result = await SendAPIRequest(queryCollection);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// this time is a jobject
|
// this time is a jobject
|
||||||
JObject json = (JObject)result;
|
JObject json = (JObject)result;
|
||||||
|
|
||||||
if (json["results"] == null)
|
if (json["results"] == null)
|
||||||
throw new Exception("Error invalid JSON response");
|
throw new Exception("Error invalid JSON response");
|
||||||
|
|
||||||
// check number result
|
// check number result
|
||||||
if (((JArray)json["results"]).Count() == 0)
|
if (((JArray)json["results"]).Count() == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
foreach (var torrent in json["results"])
|
foreach (var torrent in json["results"])
|
||||||
{
|
{
|
||||||
// add release
|
// add release
|
||||||
releases.Add( makeRelease(torrent) );
|
releases.Add( makeRelease(torrent) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OnParseError(result.ToString(), ex);
|
OnParseError(result.ToString(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (page < MAX_SEARCH_PAGE_LIMIT);
|
} while (page < MAX_SEARCH_PAGE_LIMIT);
|
||||||
|
|
||||||
return releases;
|
return releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReleaseInfo makeRelease(JToken torrent)
|
private ReleaseInfo makeRelease(JToken torrent)
|
||||||
{
|
{
|
||||||
var release = new ReleaseInfo();
|
var release = new ReleaseInfo();
|
||||||
|
|
||||||
release.Title = (String)torrent["title"];
|
release.Title = (String)torrent["title"];
|
||||||
|
|
||||||
//https://corsaro.red/details/E5BB62E2E58C654F4450325046723A3F013CD7A4
|
//https://corsaro.red/details/E5BB62E2E58C654F4450325046723A3F013CD7A4
|
||||||
release.Comments = new Uri(SiteLink + "details/" + (string)torrent["hash"]);
|
release.Comments = new Uri(SiteLink + "details/" + (string)torrent["hash"]);
|
||||||
release.Guid = release.Comments;
|
release.Guid = release.Comments;
|
||||||
//release.Link = release.Comments;
|
//release.Link = release.Comments;
|
||||||
|
|
||||||
release.PublishDate = DateTime.Now;
|
release.PublishDate = DateTime.Now;
|
||||||
if (torrent["last_updated"] != null)
|
if (torrent["last_updated"] != null)
|
||||||
release.PublishDate = DateTime.Parse((string)torrent["last_updated"]);
|
release.PublishDate = DateTime.Parse((string)torrent["last_updated"]);
|
||||||
|
|
||||||
// TODO: don't know how to map this cats..
|
// TODO: don't know how to map this cats..
|
||||||
int cat = (int)torrent["category"];
|
int cat = (int)torrent["category"];
|
||||||
release.Category = MapTrackerCatToNewznab(cat.ToString());
|
release.Category = MapTrackerCatToNewznab(cat.ToString());
|
||||||
|
|
||||||
if (torrent["size"] != null)
|
if (torrent["size"] != null)
|
||||||
release.Size = (long)torrent["size"];
|
release.Size = (long)torrent["size"];
|
||||||
|
|
||||||
release.Grabs = (long)torrent["completed"];
|
release.Grabs = (long)torrent["completed"];
|
||||||
|
|
||||||
release.Description = (string)torrent["category"] + " " + (string)torrent["description"];
|
release.Description = (string)torrent["category"] + " " + (string)torrent["description"];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
RageID = copyFrom.RageID;
|
RageID = copyFrom.RageID;
|
||||||
Imdb = copyFrom.Imdb;
|
Imdb = copyFrom.Imdb;
|
||||||
TMDb = copyFrom.TMDb;
|
TMDb = copyFrom.TMDb;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
release.Seeders = (int)torrent["seeders"];
|
release.Seeders = (int)torrent["seeders"];
|
||||||
release.Peers = release.Seeders + (int)torrent["leechers"];
|
release.Peers = release.Seeders + (int)torrent["leechers"];
|
||||||
|
|
||||||
release.InfoHash = (string)torrent["hash"];
|
release.InfoHash = (string)torrent["hash"];
|
||||||
release.MagnetUri = new Uri((string)torrent["magnet"]);
|
release.MagnetUri = new Uri((string)torrent["magnet"]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MinimumRatio = copyFrom.MinimumRatio;
|
MinimumRatio = copyFrom.MinimumRatio;
|
||||||
MinimumSeedTime = copyFrom.MinimumSeedTime;
|
MinimumSeedTime = copyFrom.MinimumSeedTime;
|
||||||
DownloadVolumeFactor = copyFrom.DownloadVolumeFactor;
|
DownloadVolumeFactor = copyFrom.DownloadVolumeFactor;
|
||||||
UploadVolumeFactor = copyFrom.UploadVolumeFactor;
|
UploadVolumeFactor = copyFrom.UploadVolumeFactor;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return release;
|
return release;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user