2017-10-29 06:50:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
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;
|
|
|
|
|
using Jackett.Common.Utils.Clients;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
|
namespace Jackett.Common.Indexers
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
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
|
2018-10-30 11:08:38 +00:00
|
|
|
|
private static readonly string defaultSiteLink = "https://torrentapi.org/";
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
2018-10-30 11:08:38 +00:00
|
|
|
|
private Uri BaseUri
|
|
|
|
|
{
|
|
|
|
|
get { return new Uri(configData.Url.Value); }
|
|
|
|
|
set { configData.Url.Value = value.ToString(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string ApiEndpoint { get { return BaseUri + "pubapi_v2.php"; } }
|
|
|
|
|
|
|
|
|
|
private new ConfigurationDataUrl configData
|
|
|
|
|
{
|
|
|
|
|
get { return (ConfigurationDataUrl)base.configData; }
|
|
|
|
|
set { base.configData = value; }
|
|
|
|
|
}
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
|
|
private DateTime lastTokenFetch;
|
|
|
|
|
private string token;
|
2018-03-23 05:26:08 +00:00
|
|
|
|
private string app_id;
|
2019-02-22 17:28:42 +00:00
|
|
|
|
private bool provideTorrentLink = false;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
2017-10-29 06:50:47 +00:00
|
|
|
|
private readonly TimeSpan TOKEN_DURATION = TimeSpan.FromMinutes(10);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
|
|
private bool HasValidToken { get { return !string.IsNullOrEmpty(token) && lastTokenFetch > DateTime.Now - TOKEN_DURATION; } }
|
|
|
|
|
|
2019-02-22 17:33:19 +00:00
|
|
|
|
public Rarbg(IIndexerConfigurationService configService, Utils.Clients.WebClient wc, Logger l, IProtectionService ps)
|
2017-04-15 08:45:10 +00:00
|
|
|
|
: base(name: "RARBG",
|
2017-10-03 10:47:02 +00:00
|
|
|
|
description: "RARBG is a Public torrent site for MOVIES / TV / GENERAL",
|
2017-04-15 08:45:10 +00:00
|
|
|
|
link: "https://rarbg.to/",
|
|
|
|
|
caps: new TorznabCapabilities(),
|
2017-07-10 20:58:44 +00:00
|
|
|
|
configService: configService,
|
2017-04-15 08:45:10 +00:00
|
|
|
|
client: wc,
|
|
|
|
|
logger: l,
|
|
|
|
|
p: ps,
|
2018-10-30 11:08:38 +00:00
|
|
|
|
configData: new ConfigurationDataUrl(defaultSiteLink))
|
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";
|
|
|
|
|
|
2019-02-22 17:28:42 +00:00
|
|
|
|
var provideTorrentLinkItem = new ConfigurationData.BoolItem { Value = false };
|
|
|
|
|
provideTorrentLinkItem.Name = "Generate torrent download link additionally to magnet (not recommended due to DDoS protection).";
|
|
|
|
|
configData.AddDynamic("providetorrentlink", provideTorrentLinkItem);
|
|
|
|
|
|
2019-05-11 03:27:25 +00:00
|
|
|
|
TorznabCaps.SupportsImdbMovieSearch = true;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
2019-04-21 03:28:19 +00:00
|
|
|
|
webclient.requestDelay = 2.1; // The api has a 1req/2s limit.
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
|
|
AddCategoryMapping(4, TorznabCatType.XXX, "XXX (18+)");
|
|
|
|
|
AddCategoryMapping(14, TorznabCatType.MoviesSD, "Movies/XVID");
|
|
|
|
|
AddCategoryMapping(48, TorznabCatType.MoviesHD, "Movies/XVID/720");
|
|
|
|
|
AddCategoryMapping(17, TorznabCatType.MoviesSD, "Movies/x264");
|
|
|
|
|
AddCategoryMapping(44, TorznabCatType.MoviesHD, "Movies/x264/1080");
|
|
|
|
|
AddCategoryMapping(45, TorznabCatType.MoviesHD, "Movies/x264/720");
|
|
|
|
|
AddCategoryMapping(47, TorznabCatType.Movies3D, "Movies/x264/3D");
|
2017-10-01 09:26:52 +00:00
|
|
|
|
AddCategoryMapping(50, TorznabCatType.MoviesHD, "Movies/x264/4k");
|
|
|
|
|
AddCategoryMapping(51, TorznabCatType.MoviesHD, "Movies/x265/4k");
|
|
|
|
|
AddCategoryMapping(52, TorznabCatType.MoviesHD, "Movs/x265/4k/HDR");
|
2017-04-15 08:45:10 +00:00
|
|
|
|
AddCategoryMapping(42, TorznabCatType.MoviesBluRay, "Movies/Full BD");
|
|
|
|
|
AddCategoryMapping(46, TorznabCatType.MoviesBluRay, "Movies/BD Remux");
|
|
|
|
|
AddCategoryMapping(18, TorznabCatType.TVSD, "TV Episodes");
|
|
|
|
|
AddCategoryMapping(41, TorznabCatType.TVHD, "TV HD Episodes");
|
2017-10-01 09:26:52 +00:00
|
|
|
|
AddCategoryMapping(49, TorznabCatType.TVHD, "TV UHD Episodes"); // torrentapi.org returns "Movies/TV-UHD-episodes" for some reason
|
|
|
|
|
AddCategoryMapping(49, TorznabCatType.TVHD, "Movies/TV-UHD-episodes"); // possibly because thats what the category is called on the /top100.php page
|
2017-04-15 08:45:10 +00:00
|
|
|
|
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(40, TorznabCatType.ConsolePS3, "Games/PS3");
|
|
|
|
|
AddCategoryMapping(32, TorznabCatType.ConsoleXbox360, "Games/XBOX-360");
|
|
|
|
|
AddCategoryMapping(33, TorznabCatType.PCISO, "Software/PC ISO");
|
|
|
|
|
AddCategoryMapping(35, TorznabCatType.BooksEbook, "e-Books");
|
2018-03-23 05:26:08 +00:00
|
|
|
|
|
|
|
|
|
app_id = "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);
|
|
|
|
|
|
|
|
|
|
var provideTorrentLinkItem = (ConfigurationData.BoolItem)configData.GetDynamic("providetorrentlink");
|
|
|
|
|
if (provideTorrentLinkItem != null)
|
|
|
|
|
{
|
|
|
|
|
provideTorrentLink = provideTorrentLinkItem.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-29 06:50:47 +00:00
|
|
|
|
private async Task CheckToken()
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
if (!HasValidToken)
|
|
|
|
|
{
|
|
|
|
|
var queryCollection = new NameValueCollection();
|
|
|
|
|
queryCollection.Add("get_token", "get_token");
|
2018-03-23 05:26:08 +00:00
|
|
|
|
queryCollection.Add("app_id", app_id);
|
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
2018-03-23 05:26:08 +00:00
|
|
|
|
var tokenUrl = ApiEndpoint + "?" + queryCollection.GetQueryString();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
|
|
var result = await RequestStringWithCookiesAndRetry(tokenUrl);
|
|
|
|
|
var json = JObject.Parse(result.Content);
|
|
|
|
|
token = json.Value<string>("token");
|
|
|
|
|
lastTokenFetch = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
await ConfigureIfOK(string.Empty, releases.Count() > 0, () =>
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Could not find releases from this URL");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 05:15:47 +00:00
|
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
2017-06-28 05:31:38 +00:00
|
|
|
|
return await PerformQuery(query, 0);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-28 05:31:38 +00:00
|
|
|
|
public async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query, int attempts)
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
await CheckToken();
|
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
|
var searchString = query.GetQueryString();
|
2017-10-29 06:50:47 +00:00
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
|
var queryCollection = new NameValueCollection();
|
|
|
|
|
queryCollection.Add("token", token);
|
|
|
|
|
queryCollection.Add("format", "json_extended");
|
2018-03-23 05:26:08 +00:00
|
|
|
|
queryCollection.Add("app_id", app_id);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
queryCollection.Add("limit", "100");
|
|
|
|
|
queryCollection.Add("ranked", "0");
|
|
|
|
|
|
|
|
|
|
if (query.ImdbID != null)
|
|
|
|
|
{
|
|
|
|
|
queryCollection.Add("mode", "search");
|
|
|
|
|
queryCollection.Add("search_imdb", query.ImdbID);
|
|
|
|
|
}
|
|
|
|
|
else if (query.RageID != null)
|
|
|
|
|
{
|
|
|
|
|
queryCollection.Add("mode", "search");
|
|
|
|
|
queryCollection.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))
|
|
|
|
|
{
|
2017-06-03 14:13:05 +00:00
|
|
|
|
searchString = searchString.Replace("'", ""); // ignore ' (e.g. search for america's Next Top Model)
|
2017-04-15 08:45:10 +00:00
|
|
|
|
queryCollection.Add("mode", "search");
|
|
|
|
|
queryCollection.Add("search_string", searchString);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
queryCollection.Add("mode", "list");
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 14:05:22 +00:00
|
|
|
|
var querycats = MapTorznabCapsToTrackers(query);
|
|
|
|
|
if (querycats.Count == 0)
|
|
|
|
|
querycats = GetAllTrackerCategories(); // default to all, without specifing it some categories are missing (e.g. games), see #4146
|
|
|
|
|
var cats = string.Join(";", querycats);
|
|
|
|
|
queryCollection.Add("category", cats);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
2018-03-23 05:26:08 +00:00
|
|
|
|
var searchUrl = ApiEndpoint + "?" + queryCollection.GetQueryString();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
var response = await RequestStringWithCookiesAndRetry(searchUrl, string.Empty);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var jsonContent = JObject.Parse(response.Content);
|
|
|
|
|
|
|
|
|
|
int errorCode = jsonContent.Value<int>("error_code");
|
|
|
|
|
if (errorCode == 20) // no results found
|
|
|
|
|
{
|
|
|
|
|
return releases.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-25 15:37:33 +00:00
|
|
|
|
// return empty results in case of invalid imdb ID, see issue #1486
|
|
|
|
|
if (errorCode == 10) // Cant find imdb in database. Are you sure this imdb exists?
|
|
|
|
|
return releases;
|
|
|
|
|
|
2017-10-25 14:14:06 +00:00
|
|
|
|
if (errorCode == 2 // Invalid token set!
|
|
|
|
|
|| errorCode == 4) // Invalid token. Use get_token for a new one!
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
2017-10-25 14:14:06 +00:00
|
|
|
|
token = null;
|
|
|
|
|
if (attempts < 3)
|
2017-04-15 08:45:10 +00:00
|
|
|
|
{
|
|
|
|
|
return await PerformQuery(query, ++attempts);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-10-25 14:14:06 +00:00
|
|
|
|
throw new Exception("error " + errorCode.ToString() + " after " + attempts.ToString() + " attempts: " + jsonContent.Value<string>("error"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errorCode > 0) // too many requests per seconds ???
|
|
|
|
|
{
|
2017-10-29 06:50:47 +00:00
|
|
|
|
// we use the IwebClient rate limiter now, this shouldn't happen
|
2017-10-25 14:14:06 +00:00
|
|
|
|
throw new Exception("error " + errorCode.ToString() + ": " + jsonContent.Value<string>("error"));
|
2017-04-15 08:45:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var item in jsonContent.Value<JArray>("torrent_results"))
|
|
|
|
|
{
|
|
|
|
|
var release = new ReleaseInfo();
|
2019-02-22 17:33:19 +00:00
|
|
|
|
release.Title = WebUtility.HtmlDecode(item.Value<string>("title"));
|
2017-04-15 08:45:10 +00:00
|
|
|
|
release.Category = MapTrackerCatDescToNewznab(item.Value<string>("category"));
|
|
|
|
|
|
|
|
|
|
release.MagnetUri = new Uri(item.Value<string>("download"));
|
|
|
|
|
release.InfoHash = release.MagnetUri.ToString().Split(':')[3].Split('&')[0];
|
2019-03-20 23:26:07 +00:00
|
|
|
|
// append app_id to prevent api server returning 403 forbidden
|
|
|
|
|
release.Comments = new Uri(item.Value<string>("info_page") + "&app_id=" + app_id);
|
2019-02-22 17:28:42 +00:00
|
|
|
|
if (provideTorrentLink)
|
|
|
|
|
release.Link = release.Comments; // in case of a torrent download we grab the link from the details page in Download()
|
2018-02-28 17:39:08 +00:00
|
|
|
|
release.Guid = release.MagnetUri;
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
|
|
var episode_info = item.Value<JToken>("episode_info");
|
|
|
|
|
|
|
|
|
|
if (episode_info.HasValues)
|
|
|
|
|
{
|
|
|
|
|
var imdb = episode_info.Value<string>("imdb");
|
|
|
|
|
release.Imdb = ParseUtil.GetImdbID(imdb);
|
|
|
|
|
release.TVDBId = episode_info.Value<long?>("tvdb");
|
|
|
|
|
release.RageID = episode_info.Value<long?>("tvrage");
|
|
|
|
|
release.TMDb = episode_info.Value<long?>("themoviedb");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
release.PublishDate = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc).ToLocalTime();
|
|
|
|
|
|
|
|
|
|
release.Seeders = item.Value<int>("seeders");
|
|
|
|
|
release.Peers = item.Value<int>("leechers") + release.Seeders;
|
|
|
|
|
release.Size = item.Value<long>("size");
|
2020-01-11 18:07:19 +00:00
|
|
|
|
release.MinimumRatio = 1;
|
|
|
|
|
release.MinimumSeedTime = 172800; // 48 hours
|
2017-04-15 08:45:10 +00:00
|
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
|
|
|
|
|
|
releases.Add(release);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
OnParseError(response.Content, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
|
}
|
2018-10-30 11:26:27 +00:00
|
|
|
|
|
|
|
|
|
public override async Task<byte[]> Download(Uri link)
|
|
|
|
|
{
|
|
|
|
|
// build download link from info redirect link
|
2018-11-01 15:47:23 +00:00
|
|
|
|
var slink = link.ToString();
|
|
|
|
|
var response = await RequestStringWithCookies(slink);
|
|
|
|
|
if (!response.IsRedirect && response.Content.Contains("Invalid token."))
|
|
|
|
|
{
|
|
|
|
|
// get new token
|
|
|
|
|
token = null;
|
|
|
|
|
await CheckToken();
|
|
|
|
|
slink += "&token=" + token;
|
|
|
|
|
response = await RequestStringWithCookies(slink);
|
|
|
|
|
}
|
2018-10-30 11:26:27 +00:00
|
|
|
|
if (!response.IsRedirect)
|
|
|
|
|
throw new Exception("Downlaod Failed, expected redirect");
|
|
|
|
|
|
|
|
|
|
var targeturi = new Uri(response.RedirectingTo);
|
|
|
|
|
var id = targeturi.Segments.Last();
|
|
|
|
|
var dluri = new Uri(targeturi, "/download.php?id=" + id + "&f=jackett.torrent");
|
|
|
|
|
return await base.Download(dluri, RequestType.GET);
|
|
|
|
|
}
|
2017-04-15 08:45:10 +00:00
|
|
|
|
}
|
2017-10-01 09:26:52 +00:00
|
|
|
|
}
|