2019-05-03 19:54:30 +00:00
|
|
|
using System;
|
2017-04-15 08:45:10 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2019-05-03 19:54:30 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2017-04-15 08:45:10 +00:00
|
|
|
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
|
|
|
{
|
2017-07-10 20:58:44 +00:00
|
|
|
public class BroadcastTheNet : 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
|
2017-10-29 06:21:18 +00:00
|
|
|
private string APIBASE = "https://api.broadcasthe.net";
|
2017-04-15 08:45:10 +00:00
|
|
|
|
2017-10-29 06:21:18 +00:00
|
|
|
private new ConfigurationDataAPIKey configData
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
get { return (ConfigurationDataAPIKey)base.configData; }
|
|
|
|
set { base.configData = value; }
|
|
|
|
}
|
|
|
|
|
2017-11-05 09:42:03 +00:00
|
|
|
public BroadcastTheNet(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
2017-04-15 08:45:10 +00:00
|
|
|
: base(name: "BroadcastTheNet",
|
2017-10-03 10:47:02 +00:00
|
|
|
description: "Broadcasthe.net (BTN) is an invite-only torrent tracker focused on TV shows",
|
2017-04-15 08:45:10 +00:00
|
|
|
link: "https://broadcasthe.net/",
|
2017-08-21 11:06:44 +00:00
|
|
|
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,
|
|
|
|
configData: new ConfigurationDataAPIKey())
|
|
|
|
{
|
|
|
|
Encoding = Encoding.UTF8;
|
|
|
|
Language = "en-us";
|
|
|
|
Type = "private";
|
2017-08-21 11:06:44 +00:00
|
|
|
|
|
|
|
TorznabCaps.LimitsDefault = 100;
|
|
|
|
TorznabCaps.LimitsMax = 1000;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
var searchString = query.GetQueryString();
|
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>();
|
|
|
|
|
2019-05-03 19:54:30 +00:00
|
|
|
// If only the season is searched for then change format to match expected format
|
|
|
|
var seasonOnlyMatch = new Regex(@".*\s[Ss]{1}\d{2}(?<![Ee]{1}\d{2,3})?$").Match(searchString);
|
|
|
|
if (seasonOnlyMatch.Success)
|
|
|
|
{
|
|
|
|
searchString = Regex.Replace(searchString, @"[Ss]{1}\d{2}", $"Season {query.Season}");
|
|
|
|
}
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
var parameters = new JArray();
|
|
|
|
parameters.Add(new JValue(configData.Key.Value));
|
|
|
|
parameters.Add(new JValue(searchString.Trim()));
|
2017-08-21 11:06:44 +00:00
|
|
|
parameters.Add(new JValue(btnResults));
|
|
|
|
parameters.Add(new JValue(btnOffset));
|
2017-04-15 08:45:10 +00:00
|
|
|
var response = await PostDataWithCookiesAndRetry(APIBASE, null, null, null, new Dictionary<string, string>()
|
|
|
|
{
|
|
|
|
{ "Accept", "application/json-rpc, application/json"},
|
|
|
|
{"Content-Type", "application/json-rpc"}
|
2017-08-14 14:23:40 +00:00
|
|
|
}, JsonRPCRequest("getTorrents", parameters), false);
|
2017-04-15 08:45:10 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var btnResponse = JsonConvert.DeserializeObject<BTNRPCResponse>(response.Content);
|
|
|
|
|
2017-08-22 16:58:56 +00:00
|
|
|
if (btnResponse != null && btnResponse.Result != null && btnResponse.Result.Torrents != null)
|
2017-04-15 08:45:10 +00:00
|
|
|
{
|
|
|
|
foreach (var itemKey in btnResponse.Result.Torrents)
|
|
|
|
{
|
2017-08-21 11:06:44 +00:00
|
|
|
var descriptions = new List<string>();
|
2017-04-15 08:45:10 +00:00
|
|
|
var btnResult = itemKey.Value;
|
|
|
|
var item = new ReleaseInfo();
|
|
|
|
if (!string.IsNullOrEmpty(btnResult.SeriesBanner))
|
|
|
|
item.BannerUrl = new Uri(btnResult.SeriesBanner);
|
2017-08-21 11:06:44 +00:00
|
|
|
item.Category = MapTrackerCatToNewznab(btnResult.Resolution);
|
|
|
|
if (item.Category.Count == 0) // default to TV
|
|
|
|
item.Category.Add(TorznabCatType.TV.ID);
|
|
|
|
item.Comments = new Uri($"{SiteLink}torrents.php?id={btnResult.GroupID}&torrentid={btnResult.TorrentID}");
|
2017-04-15 08:45:10 +00:00
|
|
|
item.Guid = new Uri(btnResult.DownloadURL);
|
|
|
|
if (!string.IsNullOrWhiteSpace(btnResult.ImdbID))
|
|
|
|
item.Imdb = ParseUtil.CoerceLong(btnResult.ImdbID);
|
|
|
|
item.Link = new Uri(btnResult.DownloadURL);
|
|
|
|
item.MinimumRatio = 1;
|
|
|
|
item.PublishDate = DateTimeUtil.UnixTimestampToDateTime(btnResult.Time);
|
|
|
|
item.RageID = btnResult.TvrageID;
|
|
|
|
item.Seeders = btnResult.Seeders;
|
|
|
|
item.Peers = btnResult.Seeders + btnResult.Leechers;
|
|
|
|
item.Size = btnResult.Size;
|
|
|
|
item.TVDBId = btnResult.TvdbID;
|
|
|
|
item.Title = btnResult.ReleaseName;
|
2017-08-21 11:06:44 +00:00
|
|
|
item.UploadVolumeFactor = 1;
|
|
|
|
item.DownloadVolumeFactor = 0; // ratioless
|
|
|
|
item.Grabs = btnResult.Snatched;
|
|
|
|
|
|
|
|
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>");
|
|
|
|
|
|
|
|
item.Description = string.Join("<br />\n", descriptions);
|
|
|
|
|
2017-04-15 08:45:10 +00:00
|
|
|
releases.Add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(response.Content, ex);
|
|
|
|
}
|
|
|
|
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; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|