2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2017-10-29 06:50:47 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-10-29 06:50:47 +00:00
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
2019-02-22 17:33:19 +00:00
|
|
|
using System.Net;
|
2017-10-29 06:50:47 +00:00
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Models;
|
2018-10-30 11:08:38 +00:00
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils;
|
2017-04-15 08:45:10 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
2020-01-21 02:25:19 +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
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2017-07-10 20:58:44 +00:00
|
|
|
public class Rarbg : BaseWebIndexer
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2019-03-20 23:26:07 +00:00
|
|
|
// API doc: https://torrentapi.org/apidocs_v2.txt?app_id=Jackett
|
2020-05-05 07:20:21 +00:00
|
|
|
private const string ApiEndpoint = "https://torrentapi.org/pubapi_v2.php";
|
|
|
|
private readonly TimeSpan TokenDuration = TimeSpan.FromMinutes(14); // 15 minutes expiration
|
|
|
|
private readonly string _appId;
|
|
|
|
private string _token;
|
|
|
|
private DateTime _lastTokenFetch;
|
2020-01-21 02:25:19 +00:00
|
|
|
private string _sort;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
private new ConfigurationData configData => base.configData;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2019-02-22 17:33:19 +00:00
|
|
|
public Rarbg(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps)
|
2020-05-11 19:59:28 +00:00
|
|
|
: base(id: "rarbg",
|
|
|
|
name: "RARBG",
|
2020-05-05 07:20:21 +00:00
|
|
|
description: "RARBG is a Public torrent site for MOVIES / TV / GENERAL",
|
|
|
|
link: "https://rarbg.to/",
|
|
|
|
caps: new TorznabCapabilities
|
|
|
|
{
|
|
|
|
SupportsImdbMovieSearch = true
|
|
|
|
},
|
|
|
|
configService: configService,
|
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationData())
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
Encoding = Encoding.GetEncoding("windows-1252");
|
2017-01-31 18:37:28 +00:00
|
|
|
Language = "en-us";
|
2017-04-15 08:45:10 +00:00
|
|
|
Type = "public";
|
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
webclient.requestDelay = 2.5; // The api has a 1req/2s limit
|
|
|
|
|
2020-01-21 02:25:19 +00:00
|
|
|
var sort = new SelectItem(new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"last", "created"},
|
|
|
|
{"seeders", "seeders"},
|
|
|
|
{"leechers", "leechers"}
|
2020-02-09 02:35:16 +00:00
|
|
|
})
|
|
|
|
{ Name = "Sort requested from site", Value = "last" };
|
2020-01-21 02:25:19 +00:00
|
|
|
configData.AddDynamic("sort", sort);
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
AddCategoryMapping(4, TorznabCatType.XXX, "XXX (18+)");
|
|
|
|
AddCategoryMapping(14, TorznabCatType.MoviesSD, "Movies/XVID");
|
|
|
|
AddCategoryMapping(17, TorznabCatType.MoviesSD, "Movies/x264");
|
|
|
|
AddCategoryMapping(18, TorznabCatType.TVSD, "TV Episodes");
|
|
|
|
AddCategoryMapping(23, TorznabCatType.AudioMP3, "Music/MP3");
|
|
|
|
AddCategoryMapping(25, TorznabCatType.AudioLossless, "Music/FLAC");
|
|
|
|
AddCategoryMapping(27, TorznabCatType.PCGames, "Games/PC ISO");
|
|
|
|
AddCategoryMapping(28, TorznabCatType.PCGames, "Games/PC RIP");
|
|
|
|
AddCategoryMapping(32, TorznabCatType.ConsoleXbox360, "Games/XBOX-360");
|
|
|
|
AddCategoryMapping(33, TorznabCatType.PCISO, "Software/PC ISO");
|
|
|
|
AddCategoryMapping(35, TorznabCatType.BooksEbook, "e-Books");
|
2020-03-21 07:59:56 +00:00
|
|
|
AddCategoryMapping(40, TorznabCatType.ConsolePS3, "Games/PS3");
|
|
|
|
AddCategoryMapping(41, TorznabCatType.TVHD, "TV HD Episodes");
|
|
|
|
AddCategoryMapping(42, TorznabCatType.MoviesBluRay, "Movies/Full BD");
|
|
|
|
AddCategoryMapping(44, TorznabCatType.MoviesHD, "Movies/x264/1080");
|
|
|
|
AddCategoryMapping(45, TorznabCatType.MoviesHD, "Movies/x264/720");
|
|
|
|
AddCategoryMapping(46, TorznabCatType.MoviesBluRay, "Movies/BD Remux");
|
|
|
|
AddCategoryMapping(47, TorznabCatType.Movies3D, "Movies/x264/3D");
|
|
|
|
AddCategoryMapping(48, TorznabCatType.MoviesHD, "Movies/XVID/720");
|
2020-05-05 07:20:21 +00:00
|
|
|
AddCategoryMapping(49, TorznabCatType.TVUHD, "TV UHD Episodes");
|
|
|
|
// torrentapi.org returns "Movies/TV-UHD-episodes" for some reason
|
|
|
|
// possibly because thats what the category is called on the /top100.php page
|
|
|
|
AddCategoryMapping(49, TorznabCatType.TVUHD, "Movies/TV-UHD-episodes");
|
2020-03-21 07:59:56 +00:00
|
|
|
AddCategoryMapping(50, TorznabCatType.MoviesUHD, "Movies/x264/4k");
|
|
|
|
AddCategoryMapping(51, TorznabCatType.MoviesUHD, "Movies/x265/4k");
|
|
|
|
AddCategoryMapping(52, TorznabCatType.MoviesUHD, "Movs/x265/4k/HDR");
|
|
|
|
AddCategoryMapping(53, TorznabCatType.ConsolePS4, "Games/PS4");
|
|
|
|
AddCategoryMapping(54, TorznabCatType.MoviesHD, "Movies/x265/1080");
|
2018-03-23 05:26:08 +00:00
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
_appId = "jackett_v" + EnvironmentUtil.JackettVersion;
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 17:28:42 +00:00
|
|
|
public override void LoadValuesFromJson(JToken jsonConfig, bool useProtectionService = false)
|
|
|
|
{
|
|
|
|
base.LoadValuesFromJson(jsonConfig, useProtectionService);
|
|
|
|
|
2020-02-09 02:35:16 +00:00
|
|
|
var sort = (SelectItem)configData.GetDynamic("sort");
|
2020-01-21 02:25:19 +00:00
|
|
|
_sort = sort != null ? sort.Value : "last";
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2019-02-22 17:28:42 +00:00
|
|
|
LoadValuesFromJson(configJson);
|
2017-04-15 08:45:10 +00:00
|
|
|
var releases = await PerformQuery(new TorznabQuery());
|
|
|
|
|
2020-01-21 02:25:19 +00:00
|
|
|
await ConfigureIfOK(string.Empty, releases.Any(), () =>
|
|
|
|
throw new Exception("Could not find releases from this URL"));
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
}
|
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query) {
|
2017-04-15 08:45:10 +00:00
|
|
|
var releases = new List<ReleaseInfo>();
|
2017-10-29 06:50:47 +00:00
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
// check the token and renewal if necessary
|
|
|
|
await RenewalTokenAsync();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
var response = await RequestStringWithCookiesAndRetry(BuildSearchUrl(query));
|
|
|
|
var jsonContent = JObject.Parse(response.Content);
|
|
|
|
var errorCode = jsonContent.Value<int>("error_code");
|
|
|
|
switch (errorCode)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-05-05 07:20:21 +00:00
|
|
|
case 0: // valid response with results
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 4: // invalid token
|
|
|
|
await RenewalTokenAsync(true); // force renewal token
|
|
|
|
response = await RequestStringWithCookiesAndRetry(BuildSearchUrl(query));
|
|
|
|
jsonContent = JObject.Parse(response.Content);
|
|
|
|
break;
|
|
|
|
case 10: // imdb not found, see issue #1486
|
|
|
|
case 20: // no results found
|
|
|
|
return releases;
|
|
|
|
default:
|
|
|
|
throw new Exception("Unknown error code: " + errorCode + " response: " + response.Content);
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-05-05 07:20:21 +00:00
|
|
|
foreach (var item in jsonContent.Value<JArray>("torrent_results"))
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-05-05 07:20:21 +00:00
|
|
|
var title = WebUtility.HtmlDecode(item.Value<string>("title"));
|
2017-10-25 14:14:06 +00:00
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
var magnetStr = item.Value<string>("download");
|
|
|
|
var magnetUri = new Uri(magnetStr);
|
|
|
|
var infoHash = magnetStr.Split(':')[3].Split('&')[0];
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2019-03-20 23:26:07 +00:00
|
|
|
// append app_id to prevent api server returning 403 forbidden
|
2020-05-05 07:20:21 +00:00
|
|
|
var comments = new Uri(item.Value<string>("info_page") + "&app_id=" + _appId);
|
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
// ex: 2015-08-16 21:25:08 +0000
|
|
|
|
var dateStr = item.Value<string>("pubdate").Replace(" +0000", "");
|
|
|
|
var dateTime = DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
|
|
|
|
var publishDate = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc).ToLocalTime();
|
2020-05-05 07:20:21 +00:00
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
var size = item.Value<long>("size");
|
2020-05-05 07:20:21 +00:00
|
|
|
var seeders = item.Value<int>("seeders");
|
|
|
|
var leechers = item.Value<int>("leechers");
|
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
var release = new ReleaseInfo
|
|
|
|
{
|
|
|
|
Title = title,
|
|
|
|
Category = MapTrackerCatDescToNewznab(item.Value<string>("category")),
|
|
|
|
MagnetUri = magnetUri,
|
|
|
|
InfoHash = infoHash,
|
|
|
|
Comments = comments,
|
|
|
|
PublishDate = publishDate,
|
|
|
|
Guid = magnetUri,
|
|
|
|
Seeders = seeders,
|
|
|
|
Peers = leechers + seeders,
|
|
|
|
Size = size,
|
|
|
|
MinimumRatio = 1,
|
|
|
|
MinimumSeedTime = 172800, // 48 hours
|
|
|
|
DownloadVolumeFactor = 0,
|
|
|
|
UploadVolumeFactor = 1
|
|
|
|
};
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-01-21 02:25:19 +00:00
|
|
|
var episodeInfo = item.Value<JToken>("episode_info");
|
|
|
|
if (episodeInfo.HasValues)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-03-26 22:15:28 +00:00
|
|
|
release.Imdb = ParseUtil.GetImdbID(episodeInfo.Value<string>("imdb"));
|
2020-01-21 02:25:19 +00:00
|
|
|
release.TVDBId = episodeInfo.Value<long?>("tvdb");
|
|
|
|
release.RageID = episodeInfo.Value<long?>("tvrage");
|
|
|
|
release.TMDb = episodeInfo.Value<long?>("themoviedb");
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(response.Content, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
2018-10-30 11:26:27 +00:00
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
private string BuildSearchUrl(TorznabQuery query)
|
2018-10-30 11:26:27 +00:00
|
|
|
{
|
2020-05-05 07:20:21 +00:00
|
|
|
var searchString = query.GetQueryString();
|
|
|
|
var qc = new NameValueCollection
|
|
|
|
{
|
|
|
|
{ "token", _token },
|
|
|
|
{ "format", "json_extended" },
|
|
|
|
{ "app_id", _appId },
|
|
|
|
{ "limit", "100" },
|
|
|
|
{ "ranked", "0" },
|
|
|
|
{ "sort", _sort }
|
|
|
|
};
|
|
|
|
|
|
|
|
if (query.ImdbID != null)
|
|
|
|
{
|
|
|
|
qc.Add("mode", "search");
|
|
|
|
qc.Add("search_imdb", query.ImdbID);
|
|
|
|
}
|
|
|
|
else if (query.RageID != null)
|
|
|
|
{
|
|
|
|
qc.Add("mode", "search");
|
|
|
|
qc.Add("search_tvrage", query.RageID.ToString());
|
|
|
|
}
|
|
|
|
/*else if (query.TvdbID != null)
|
|
|
|
{
|
|
|
|
queryCollection.Add("mode", "search");
|
|
|
|
queryCollection.Add("search_tvdb", query.TvdbID);
|
|
|
|
}*/
|
|
|
|
else if (!string.IsNullOrWhiteSpace(searchString))
|
|
|
|
{
|
|
|
|
// ignore ' (e.g. search for america's Next Top Model)
|
|
|
|
searchString = searchString.Replace("'", "");
|
|
|
|
qc.Add("mode", "search");
|
|
|
|
qc.Add("search_string", searchString);
|
|
|
|
}
|
|
|
|
else
|
2018-11-01 15:47:23 +00:00
|
|
|
{
|
2020-05-05 07:20:21 +00:00
|
|
|
qc.Add("mode", "list");
|
|
|
|
qc.Remove("sort");
|
2018-11-01 15:47:23 +00:00
|
|
|
}
|
2018-10-30 11:26:27 +00:00
|
|
|
|
2020-05-05 07:20:21 +00:00
|
|
|
var querycats = MapTorznabCapsToTrackers(query);
|
|
|
|
if (querycats.Count == 0)
|
|
|
|
// default to all, without specifying it some categories are missing (e.g. games), see #4146
|
|
|
|
querycats = GetAllTrackerCategories();
|
|
|
|
var cats = string.Join(";", querycats);
|
|
|
|
qc.Add("category", cats);
|
|
|
|
|
|
|
|
return ApiEndpoint + "?" + qc.GetQueryString();
|
2018-10-30 11:26:27 +00:00
|
|
|
}
|
2020-05-05 07:20:21 +00:00
|
|
|
|
|
|
|
private async Task RenewalTokenAsync(bool force = false)
|
|
|
|
{
|
|
|
|
if (!HasValidToken || force)
|
|
|
|
{
|
|
|
|
var qc = new NameValueCollection
|
|
|
|
{
|
|
|
|
{ "get_token", "get_token" },
|
|
|
|
{ "app_id", _appId }
|
|
|
|
};
|
|
|
|
var tokenUrl = ApiEndpoint + "?" + qc.GetQueryString();
|
|
|
|
var result = await RequestStringWithCookiesAndRetry(tokenUrl);
|
|
|
|
var json = JObject.Parse(result.Content);
|
|
|
|
_token = json.Value<string>("token");
|
|
|
|
_lastTokenFetch = DateTime.Now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool HasValidToken => !string.IsNullOrEmpty(_token) && _lastTokenFetch > DateTime.Now - TokenDuration;
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
2017-10-01 09:26:52 +00:00
|
|
|
}
|