BeyondHDApi: Added option to extend title with available HDR for hybrid releases (#13398)

This commit is contained in:
Webster 2022-07-24 23:33:43 +02:00 committed by GitHub
parent 20c363293b
commit 72e6068fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 5 deletions

View File

@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using Jackett.Common.Models;
using Jackett.Common.Models.IndexerConfig;
using Jackett.Common.Models.IndexerConfig.Bespoke;
using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils;
using Jackett.Common.Utils.Clients;
@ -20,9 +21,9 @@ namespace Jackett.Common.Indexers
{
private readonly string APIBASE = "https://beyond-hd.me/api/torrents/";
private new ConfigurationDataAPIKeyAndRSSKey configData
private new ConfigurationDataBeyondHDApi configData
{
get => (ConfigurationDataAPIKeyAndRSSKey)base.configData;
get => (ConfigurationDataBeyondHDApi)base.configData;
set => base.configData = value;
}
@ -50,7 +51,7 @@ namespace Jackett.Common.Indexers
logger: l,
p: ps,
cacheService: cs,
configData: new ConfigurationDataAPIKeyAndRSSKey("Find the API and RSS keys under your security settings (your profile picture -> my security)"))
configData: new ConfigurationDataBeyondHDApi("Find the API and RSS keys under your security settings (your profile picture -> my security)"))
{
Encoding = Encoding.UTF8;
Language = "en-US";
@ -112,12 +113,13 @@ namespace Jackett.Common.Indexers
private ReleaseInfo mapToReleaseInfo(BHDResult bhdResult)
{
var uri = new Uri(bhdResult.url);
var downloadUri = new Uri(bhdResult.download_url);
var title = getTitle(bhdResult);
var releaseInfo = new ReleaseInfo
{
Title = bhdResult.name,
Title = title,
Seeders = bhdResult.seeders,
Guid = new Uri(bhdResult.url),
Details = new Uri(bhdResult.url),
@ -148,6 +150,32 @@ namespace Jackett.Common.Indexers
return releaseInfo;
}
private string getTitle(BHDResult bhdResult)
{
var title = bhdResult.name;
if (!configData.AddHybridFeaturesToTitle.Value)
return title;
var featureCount = bhdResult.dv + bhdResult.hdr10 + bhdResult.hdr10plus + bhdResult.hlg;
if (featureCount > 1)
{
var features = new List<string>();
if (bhdResult.dv == 1)
features.Add("Dolby Vision");
if (bhdResult.hdr10 == 1)
features.Add("HDR10");
if (bhdResult.hdr10plus == 1)
features.Add("HDR10+");
if (bhdResult.hlg == 1)
features.Add("HLG");
title += $" ({string.Join(" / ", features)})";
}
return title;
}
private async Task<BHDResponse> GetBHDResponse(string apiUrl, Dictionary<string, string> postData)
{
var request = new WebRequest
@ -272,6 +300,12 @@ namespace Jackett.Common.Indexers
public DateTime created_at { get; set; }
public string url { get; set; }
public string download_url { get; set; }
public int dv { get; set; }
public int hdr10 { get; set; }
[JsonProperty("hdr10+")]
public int hdr10plus { get; set; }
public int hlg { get; set; }
public int commentary { get; set; }
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Jackett.Common.Models.IndexerConfig.Bespoke
{
[ExcludeFromCodeCoverage]
internal class ConfigurationDataBeyondHDApi : ConfigurationData
{
public StringConfigurationItem ApiKey { get; private set; }
public StringConfigurationItem RSSKey { get; private set; }
public DisplayInfoConfigurationItem Instructions { get; private set; }
public BoolConfigurationItem AddHybridFeaturesToTitle { get; private set; }
public ConfigurationDataBeyondHDApi(string instructionMessageOptional)
{
ApiKey = new StringConfigurationItem("API Key");
RSSKey = new StringConfigurationItem("RSS Key");
Instructions = new DisplayInfoConfigurationItem("", instructionMessageOptional);
AddHybridFeaturesToTitle = new BoolConfigurationItem("Include DV/HDR10 in title when release has multiple HDR formats.");
}
}
}