2019-05-03 19:54:30 +00:00
|
|
|
using System;
|
2017-04-15 08:45:10 +00:00
|
|
|
using System.Collections.Generic;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-04-15 08:45:10 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
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;
|
2017-08-14 14:23:40 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
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]
|
2020-06-06 20:15:50 +00:00
|
|
|
public class BroadcasTheNet : BaseWebIndexer
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2017-08-14 14:23:40 +00:00
|
|
|
// Docs at http://apidocs.broadcasthe.net/docs.php
|
2020-02-10 22:16:19 +00:00
|
|
|
private readonly string APIBASE = "https://api.broadcasthe.net";
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-04-03 23:03:26 +00:00
|
|
|
// TODO: remove ConfigurationDataAPIKey class and use ConfigurationDataPasskey instead
|
2017-10-29 06:21:18 +00:00
|
|
|
private new ConfigurationDataAPIKey configData
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataAPIKey)base.configData;
|
|
|
|
set => base.configData = value;
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 20:15:50 +00:00
|
|
|
public BroadcasTheNet(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
|
|
|
: base(id: "broadcasthenet",
|
|
|
|
name: "BroadcasTheNet",
|
|
|
|
description: "BroadcasTheNet (BTN) is an invite-only torrent tracker focused on TV shows",
|
2020-05-11 19:59:28 +00:00
|
|
|
link: "https://broadcasthe.net/",
|
2020-10-18 20:47:36 +00:00
|
|
|
caps: new TorznabCapabilities
|
|
|
|
{
|
|
|
|
LimitsDefault = 100,
|
|
|
|
LimitsMax = 1000,
|
|
|
|
TvSearchParams = new List<TvSearchParam>
|
|
|
|
{
|
|
|
|
TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep
|
|
|
|
}
|
|
|
|
},
|
2020-05-11 19:59:28 +00:00
|
|
|
configService: configService,
|
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationDataAPIKey())
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
Language = "en-us";
|
|
|
|
Type = "private";
|
2017-08-21 11:06:44 +00:00
|
|
|
|
|
|
|
AddCategoryMapping("SD", TorznabCatType.TVSD, "SD");
|
|
|
|
AddCategoryMapping("720p", TorznabCatType.TVHD, "720p");
|
|
|
|
AddCategoryMapping("1080p", TorznabCatType.TVHD, "1080p");
|
|
|
|
AddCategoryMapping("1080i", TorznabCatType.TVHD, "1080i");
|
|
|
|
AddCategoryMapping("2160p", TorznabCatType.TVHD, "2160p");
|
|
|
|
AddCategoryMapping("Portable Device", TorznabCatType.TVSD, "Portable Device");
|
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
|
|
|
{
|
|
|
|
LoadValuesFromJson(configJson);
|
|
|
|
|
|
|
|
IsConfigured = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var results = await PerformQuery(new TorznabQuery());
|
|
|
|
if (results.Count() == 0)
|
|
|
|
throw new Exception("Testing returned no results!");
|
|
|
|
IsConfigured = true;
|
|
|
|
SaveConfig();
|
|
|
|
}
|
2017-08-14 14:23:40 +00:00
|
|
|
catch (Exception e)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
throw new ExceptionWithConfigData(e.Message, configData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string JsonRPCRequest(string method, JArray parameters)
|
|
|
|
{
|
|
|
|
dynamic request = new JObject();
|
|
|
|
request["jsonrpc"] = "2.0";
|
|
|
|
request["method"] = method;
|
|
|
|
request["params"] = parameters;
|
|
|
|
request["id"] = Guid.NewGuid().ToString().Substring(0, 8);
|
|
|
|
return request.ToString();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-10-01 22:08:29 +00:00
|
|
|
var searchString = query.SearchTerm != null ? query.SearchTerm : "";
|
2017-08-21 11:06:44 +00:00
|
|
|
var btnResults = query.Limit;
|
|
|
|
if (btnResults == 0)
|
|
|
|
btnResults = (int)TorznabCaps.LimitsDefault;
|
|
|
|
var btnOffset = query.Offset;
|
2017-04-15 08:45:10 +00:00
|
|
|
var releases = new List<ReleaseInfo>();
|
2020-09-30 17:34:37 +00:00
|
|
|
var searchParam = new Dictionary<string, string>();
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-09-30 17:34:37 +00:00
|
|
|
// If only the season/episode is searched for then change format to match expected format
|
|
|
|
if (query.Season > 0 && query.Episode == null)
|
2019-05-03 19:54:30 +00:00
|
|
|
{
|
2020-09-30 17:34:37 +00:00
|
|
|
searchParam["name"] = $"Season {query.Season}";
|
|
|
|
searchParam["category"] = "Season";
|
|
|
|
} else if (query.Season > 0 && int.Parse(query.Episode) > 0)
|
|
|
|
{
|
|
|
|
searchParam["name"] = string.Format("S{0:00}E{1:00}", query.Season, int.Parse(query.Episode));
|
|
|
|
searchParam["category"] = "Episode";
|
2019-05-03 19:54:30 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 17:34:37 +00:00
|
|
|
searchParam["search"] = searchString.Replace(" ", "%");
|
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
var parameters = new JArray
|
|
|
|
{
|
|
|
|
new JValue(configData.Key.Value),
|
2020-09-30 17:34:37 +00:00
|
|
|
JObject.FromObject(searchParam),
|
2020-03-26 22:15:28 +00:00
|
|
|
new JValue(btnResults),
|
|
|
|
new JValue(btnOffset)
|
|
|
|
};
|
2020-09-30 17:34:37 +00:00
|
|
|
|
2020-06-11 15:09:27 +00:00
|
|
|
var response = await RequestWithCookiesAndRetryAsync(
|
|
|
|
APIBASE, method: RequestType.POST,
|
|
|
|
headers: new Dictionary<string, string>
|
|
|
|
{
|
|
|
|
{"Accept", "application/json-rpc, application/json"},
|
|
|
|
{"Content-Type", "application/json-rpc"}
|
|
|
|
}, rawbody: JsonRPCRequest("getTorrents", parameters), emulateBrowser: false);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-06-09 17:36:57 +00:00
|
|
|
var btnResponse = JsonConvert.DeserializeObject<BTNRPCResponse>(response.ContentString);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
if (btnResponse?.Result?.Torrents != null)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
foreach (var itemKey in btnResponse.Result.Torrents)
|
|
|
|
{
|
|
|
|
var btnResult = itemKey.Value;
|
2020-03-26 22:15:28 +00:00
|
|
|
var descriptions = new List<string>();
|
2017-08-21 11:06:44 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.Series))
|
|
|
|
descriptions.Add("Series: " + btnResult.Series);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.GroupName))
|
|
|
|
descriptions.Add("Group Name: " + btnResult.GroupName);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.Source))
|
|
|
|
descriptions.Add("Source: " + btnResult.Source);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.Container))
|
|
|
|
descriptions.Add("Container: " + btnResult.Container);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.Codec))
|
|
|
|
descriptions.Add("Codec: " + btnResult.Codec);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.Resolution))
|
|
|
|
descriptions.Add("Resolution: " + btnResult.Resolution);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.Origin))
|
|
|
|
descriptions.Add("Origin: " + btnResult.Origin);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.Series))
|
|
|
|
descriptions.Add("Youtube Trailer: <a href=\"" + btnResult.YoutubeTrailer + "\">" + btnResult.YoutubeTrailer + "</a>");
|
2020-03-26 22:15:28 +00:00
|
|
|
var imdb = ParseUtil.GetImdbID(btnResult.ImdbID);
|
|
|
|
var link = new Uri(btnResult.DownloadURL);
|
2020-11-08 02:11:27 +00:00
|
|
|
var details = new Uri($"{SiteLink}torrents.php?id={btnResult.GroupID}&torrentid={btnResult.TorrentID}");
|
2020-03-26 22:15:28 +00:00
|
|
|
var publishDate = DateTimeUtil.UnixTimestampToDateTime(btnResult.Time);
|
|
|
|
var release = new ReleaseInfo
|
|
|
|
{
|
|
|
|
Category = MapTrackerCatToNewznab(btnResult.Resolution),
|
2020-11-08 02:11:27 +00:00
|
|
|
Details = details,
|
2020-03-26 22:15:28 +00:00
|
|
|
Guid = link,
|
|
|
|
Link = link,
|
|
|
|
MinimumRatio = 1,
|
|
|
|
PublishDate = publishDate,
|
|
|
|
RageID = btnResult.TvrageID,
|
|
|
|
Seeders = btnResult.Seeders,
|
|
|
|
Peers = btnResult.Seeders + btnResult.Leechers,
|
|
|
|
Size = btnResult.Size,
|
|
|
|
TVDBId = btnResult.TvdbID,
|
|
|
|
Title = btnResult.ReleaseName,
|
|
|
|
UploadVolumeFactor = 1,
|
|
|
|
DownloadVolumeFactor = 0, // ratioless
|
|
|
|
Grabs = btnResult.Snatched,
|
|
|
|
Description = string.Join("<br />\n", descriptions),
|
|
|
|
Imdb = imdb
|
|
|
|
};
|
|
|
|
if (!string.IsNullOrEmpty(btnResult.SeriesBanner))
|
2020-11-07 23:43:33 +00:00
|
|
|
release.Poster = new Uri(btnResult.SeriesBanner);
|
2020-03-26 22:15:28 +00:00
|
|
|
if (!release.Category.Any()) // default to TV
|
|
|
|
release.Category.Add(TorznabCatType.TV.ID);
|
2017-08-21 11:06:44 +00:00
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
releases.Add(release);
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2020-06-09 17:36:57 +00:00
|
|
|
OnParseError(response.ContentString, ex);
|
2017-04-15 08:45:10 +00:00
|
|
|
}
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BTNRPCResponse
|
|
|
|
{
|
|
|
|
public string Id { get; set; }
|
|
|
|
public BTNResultPage Result { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BTNResultPage
|
|
|
|
{
|
|
|
|
public Dictionary<int, BTNResultItem> Torrents { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BTNResultItem
|
|
|
|
{
|
|
|
|
public int TorrentID { get; set; }
|
|
|
|
public string DownloadURL { get; set; }
|
|
|
|
public string GroupName { get; set; }
|
|
|
|
public int GroupID { get; set; }
|
|
|
|
public int SeriesID { get; set; }
|
|
|
|
public string Series { get; set; }
|
|
|
|
public string SeriesBanner { get; set; }
|
|
|
|
public string SeriesPoster { get; set; }
|
|
|
|
public string YoutubeTrailer { get; set; }
|
|
|
|
public string Category { get; set; }
|
|
|
|
public int? Snatched { get; set; }
|
|
|
|
public int? Seeders { get; set; }
|
|
|
|
public int? Leechers { get; set; }
|
|
|
|
public string Source { get; set; }
|
|
|
|
public string Container { get; set; }
|
|
|
|
public string Codec { get; set; }
|
|
|
|
public string Resolution { get; set; }
|
|
|
|
public string Origin { get; set; }
|
|
|
|
public string ReleaseName { get; set; }
|
|
|
|
public long Size { get; set; }
|
|
|
|
public long Time { get; set; }
|
|
|
|
public int? TvdbID { get; set; }
|
|
|
|
public int? TvrageID { get; set; }
|
|
|
|
public string ImdbID { get; set; }
|
|
|
|
public string InfoHash { get; set; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|