Add LiveTv configuration extension

This commit is contained in:
Patrick Barron 2024-01-12 18:37:14 -05:00
parent 93e5135391
commit ad51f4f95d
6 changed files with 46 additions and 46 deletions

View File

@ -0,0 +1,18 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.LiveTv;
namespace Jellyfin.LiveTv.Configuration;
/// <summary>
/// <see cref="IConfigurationManager"/> extensions for Live TV.
/// </summary>
public static class LiveTvConfigurationExtensions
{
/// <summary>
/// Gets the <see cref="LiveTvOptions"/>.
/// </summary>
/// <param name="configurationManager">The <see cref="IConfigurationManager"/>.</param>
/// <returns>The <see cref="LiveTvOptions"/>.</returns>
public static LiveTvOptions GetLiveTvConfiguration(this IConfigurationManager configurationManager)
=> configurationManager.GetConfiguration<LiveTvOptions>("livetv");
}

View File

@ -17,6 +17,7 @@ using System.Xml;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using Jellyfin.Data.Events; using Jellyfin.Data.Events;
using Jellyfin.Extensions; using Jellyfin.Extensions;
using Jellyfin.LiveTv.Configuration;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Progress; using MediaBrowser.Common.Progress;
@ -126,7 +127,7 @@ namespace Jellyfin.LiveTv.EmbyTV
{ {
get get
{ {
var path = GetConfiguration().RecordingPath; var path = _config.GetLiveTvConfiguration().RecordingPath;
return string.IsNullOrWhiteSpace(path) return string.IsNullOrWhiteSpace(path)
? DefaultRecordingPath ? DefaultRecordingPath
@ -189,7 +190,7 @@ namespace Jellyfin.LiveTv.EmbyTV
pathsAdded.AddRange(pathsToCreate); pathsAdded.AddRange(pathsToCreate);
} }
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
var pathsToRemove = config.MediaLocationsCreated var pathsToRemove = config.MediaLocationsCreated
.Except(recordingFolders.SelectMany(i => i.Locations)) .Except(recordingFolders.SelectMany(i => i.Locations))
@ -831,7 +832,7 @@ namespace Jellyfin.LiveTv.EmbyTV
public Task<SeriesTimerInfo> GetNewTimerDefaultsAsync(CancellationToken cancellationToken, ProgramInfo program = null) public Task<SeriesTimerInfo> GetNewTimerDefaultsAsync(CancellationToken cancellationToken, ProgramInfo program = null)
{ {
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
var defaults = new SeriesTimerInfo() var defaults = new SeriesTimerInfo()
{ {
@ -932,7 +933,7 @@ namespace Jellyfin.LiveTv.EmbyTV
private List<Tuple<IListingsProvider, ListingsProviderInfo>> GetListingProviders() private List<Tuple<IListingsProvider, ListingsProviderInfo>> GetListingProviders()
{ {
return GetConfiguration().ListingProviders return _config.GetLiveTvConfiguration().ListingProviders
.Select(i => .Select(i =>
{ {
var provider = _liveTvManager.ListingProviders.FirstOrDefault(l => string.Equals(l.Type, i.Type, StringComparison.OrdinalIgnoreCase)); var provider = _liveTvManager.ListingProviders.FirstOrDefault(l => string.Equals(l.Type, i.Type, StringComparison.OrdinalIgnoreCase));
@ -1076,7 +1077,7 @@ namespace Jellyfin.LiveTv.EmbyTV
private string GetRecordingPath(TimerInfo timer, RemoteSearchResult metadata, out string seriesPath) private string GetRecordingPath(TimerInfo timer, RemoteSearchResult metadata, out string seriesPath)
{ {
var recordPath = RecordingPath; var recordPath = RecordingPath;
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
seriesPath = null; seriesPath = null;
if (timer.IsProgramSeries) if (timer.IsProgramSeries)
@ -1596,7 +1597,7 @@ namespace Jellyfin.LiveTv.EmbyTV
private void PostProcessRecording(TimerInfo timer, string path) private void PostProcessRecording(TimerInfo timer, string path)
{ {
var options = GetConfiguration(); var options = _config.GetLiveTvConfiguration();
if (string.IsNullOrWhiteSpace(options.RecordingPostProcessor)) if (string.IsNullOrWhiteSpace(options.RecordingPostProcessor))
{ {
return; return;
@ -1777,7 +1778,7 @@ namespace Jellyfin.LiveTv.EmbyTV
program.AddGenre("News"); program.AddGenre("News");
} }
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
if (config.SaveRecordingNFO) if (config.SaveRecordingNFO)
{ {
@ -2128,11 +2129,6 @@ namespace Jellyfin.LiveTv.EmbyTV
return _libraryManager.GetItemList(query).Cast<LiveTvProgram>().FirstOrDefault(); return _libraryManager.GetItemList(query).Cast<LiveTvProgram>().FirstOrDefault();
} }
private LiveTvOptions GetConfiguration()
{
return _config.GetConfiguration<LiveTvOptions>("livetv");
}
private bool ShouldCancelTimerForSeriesTimer(SeriesTimerInfo seriesTimer, TimerInfo timer) private bool ShouldCancelTimerForSeriesTimer(SeriesTimerInfo seriesTimer, TimerInfo timer)
{ {
if (timer.IsManual) if (timer.IsManual)
@ -2519,7 +2515,7 @@ namespace Jellyfin.LiveTv.EmbyTV
}; };
} }
var customPath = GetConfiguration().MovieRecordingPath; var customPath = _config.GetLiveTvConfiguration().MovieRecordingPath;
if (!string.IsNullOrWhiteSpace(customPath) && !string.Equals(customPath, defaultFolder, StringComparison.OrdinalIgnoreCase) && Directory.Exists(customPath)) if (!string.IsNullOrWhiteSpace(customPath) && !string.Equals(customPath, defaultFolder, StringComparison.OrdinalIgnoreCase) && Directory.Exists(customPath))
{ {
yield return new VirtualFolderInfo yield return new VirtualFolderInfo
@ -2530,7 +2526,7 @@ namespace Jellyfin.LiveTv.EmbyTV
}; };
} }
customPath = GetConfiguration().SeriesRecordingPath; customPath = _config.GetLiveTvConfiguration().SeriesRecordingPath;
if (!string.IsNullOrWhiteSpace(customPath) && !string.Equals(customPath, defaultFolder, StringComparison.OrdinalIgnoreCase) && Directory.Exists(customPath)) if (!string.IsNullOrWhiteSpace(customPath) && !string.Equals(customPath, defaultFolder, StringComparison.OrdinalIgnoreCase) && Directory.Exists(customPath))
{ {
yield return new VirtualFolderInfo yield return new VirtualFolderInfo
@ -2546,7 +2542,7 @@ namespace Jellyfin.LiveTv.EmbyTV
{ {
var list = new List<TunerHostInfo>(); var list = new List<TunerHostInfo>();
var configuredDeviceIds = GetConfiguration().TunerHosts var configuredDeviceIds = _config.GetLiveTvConfiguration().TunerHosts
.Where(i => !string.IsNullOrWhiteSpace(i.DeviceId)) .Where(i => !string.IsNullOrWhiteSpace(i.DeviceId))
.Select(i => i.DeviceId) .Select(i => i.DeviceId)
.ToList(); .ToList();
@ -2579,7 +2575,7 @@ namespace Jellyfin.LiveTv.EmbyTV
{ {
var discoveredDevices = await DiscoverDevices(host, TunerDiscoveryDurationMs, cancellationToken).ConfigureAwait(false); var discoveredDevices = await DiscoverDevices(host, TunerDiscoveryDurationMs, cancellationToken).ConfigureAwait(false);
var configuredDevices = GetConfiguration().TunerHosts var configuredDevices = _config.GetLiveTvConfiguration().TunerHosts
.Where(i => string.Equals(i.Type, host.Type, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.Type, host.Type, StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
using Jellyfin.Data.Entities; using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using Jellyfin.Data.Events; using Jellyfin.Data.Events;
using MediaBrowser.Common.Configuration; using Jellyfin.LiveTv.Configuration;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Progress; using MediaBrowser.Common.Progress;
using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Channels;
@ -108,11 +108,6 @@ namespace Jellyfin.LiveTv
public IReadOnlyList<IListingsProvider> ListingProviders => _listingProviders; public IReadOnlyList<IListingsProvider> ListingProviders => _listingProviders;
private LiveTvOptions GetConfiguration()
{
return _config.GetConfiguration<LiveTvOptions>("livetv");
}
public string GetEmbyTvActiveRecordingPath(string id) public string GetEmbyTvActiveRecordingPath(string id)
{ {
return EmbyTV.EmbyTV.Current.GetActiveRecordingPath(id); return EmbyTV.EmbyTV.Current.GetActiveRecordingPath(id);
@ -1302,7 +1297,7 @@ namespace Jellyfin.LiveTv
private double GetGuideDays() private double GetGuideDays()
{ {
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
if (config.GuideDays.HasValue) if (config.GuideDays.HasValue)
{ {
@ -2125,7 +2120,7 @@ namespace Jellyfin.LiveTv
private bool IsLiveTvEnabled(User user) private bool IsLiveTvEnabled(User user)
{ {
return user.HasPermission(PermissionKind.EnableLiveTvAccess) && (Services.Count > 1 || GetConfiguration().TunerHosts.Length > 0); return user.HasPermission(PermissionKind.EnableLiveTvAccess) && (Services.Count > 1 || _config.GetLiveTvConfiguration().TunerHosts.Length > 0);
} }
public IEnumerable<User> GetEnabledUsers() public IEnumerable<User> GetEnabledUsers()
@ -2187,7 +2182,7 @@ namespace Jellyfin.LiveTv
await configurable.Validate(info).ConfigureAwait(false); await configurable.Validate(info).ConfigureAwait(false);
} }
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
var list = config.TunerHosts.ToList(); var list = config.TunerHosts.ToList();
var index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); var index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase));
@ -2232,7 +2227,7 @@ namespace Jellyfin.LiveTv
await provider.Validate(info, validateLogin, validateListings).ConfigureAwait(false); await provider.Validate(info, validateLogin, validateListings).ConfigureAwait(false);
LiveTvOptions config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
var list = config.ListingProviders.ToList(); var list = config.ListingProviders.ToList();
int index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); int index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase));
@ -2257,7 +2252,7 @@ namespace Jellyfin.LiveTv
public void DeleteListingsProvider(string id) public void DeleteListingsProvider(string id)
{ {
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
config.ListingProviders = config.ListingProviders.Where(i => !string.Equals(id, i.Id, StringComparison.OrdinalIgnoreCase)).ToArray(); config.ListingProviders = config.ListingProviders.Where(i => !string.Equals(id, i.Id, StringComparison.OrdinalIgnoreCase)).ToArray();
@ -2267,7 +2262,7 @@ namespace Jellyfin.LiveTv
public async Task<TunerChannelMapping> SetChannelMapping(string providerId, string tunerChannelNumber, string providerChannelNumber) public async Task<TunerChannelMapping> SetChannelMapping(string providerId, string tunerChannelNumber, string providerChannelNumber)
{ {
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
var listingsProviderInfo = config.ListingProviders.First(i => string.Equals(providerId, i.Id, StringComparison.OrdinalIgnoreCase)); var listingsProviderInfo = config.ListingProviders.First(i => string.Equals(providerId, i.Id, StringComparison.OrdinalIgnoreCase));
listingsProviderInfo.ChannelMappings = listingsProviderInfo.ChannelMappings.Where(i => !string.Equals(i.Name, tunerChannelNumber, StringComparison.OrdinalIgnoreCase)).ToArray(); listingsProviderInfo.ChannelMappings = listingsProviderInfo.ChannelMappings.Where(i => !string.Equals(i.Name, tunerChannelNumber, StringComparison.OrdinalIgnoreCase)).ToArray();
@ -2327,7 +2322,7 @@ namespace Jellyfin.LiveTv
public Task<List<NameIdPair>> GetLineups(string providerType, string providerId, string country, string location) public Task<List<NameIdPair>> GetLineups(string providerType, string providerId, string country, string location)
{ {
var config = GetConfiguration(); var config = _config.GetLiveTvConfiguration();
if (string.IsNullOrWhiteSpace(providerId)) if (string.IsNullOrWhiteSpace(providerId))
{ {
@ -2357,13 +2352,13 @@ namespace Jellyfin.LiveTv
public Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken) public Task<List<ChannelInfo>> GetChannelsForListingsProvider(string id, CancellationToken cancellationToken)
{ {
var info = GetConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase)); var info = _config.GetLiveTvConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));
return EmbyTV.EmbyTV.Current.GetChannelsForListingsProvider(info, cancellationToken); return EmbyTV.EmbyTV.Current.GetChannelsForListingsProvider(info, cancellationToken);
} }
public Task<List<ChannelInfo>> GetChannelsFromListingsProviderData(string id, CancellationToken cancellationToken) public Task<List<ChannelInfo>> GetChannelsFromListingsProviderData(string id, CancellationToken cancellationToken)
{ {
var info = GetConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase)); var info = _config.GetLiveTvConfiguration().ListingProviders.First(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));
var provider = _listingProviders.First(i => string.Equals(i.Type, info.Type, StringComparison.OrdinalIgnoreCase)); var provider = _listingProviders.First(i => string.Equals(i.Type, info.Type, StringComparison.OrdinalIgnoreCase));
return provider.GetChannels(info, cancellationToken); return provider.GetChannels(info, cancellationToken);
} }

View File

@ -2,9 +2,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Jellyfin.LiveTv.Configuration;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Tasks; using MediaBrowser.Model.Tasks;
namespace Jellyfin.LiveTv namespace Jellyfin.LiveTv
@ -38,7 +38,7 @@ namespace Jellyfin.LiveTv
public string Category => "Live TV"; public string Category => "Live TV";
/// <inheritdoc /> /// <inheritdoc />
public bool IsHidden => _liveTvManager.Services.Count == 1 && GetConfiguration().TunerHosts.Length == 0; public bool IsHidden => _liveTvManager.Services.Count == 1 && _config.GetLiveTvConfiguration().TunerHosts.Length == 0;
/// <inheritdoc /> /// <inheritdoc />
public bool IsEnabled => true; public bool IsEnabled => true;
@ -66,10 +66,5 @@ namespace Jellyfin.LiveTv
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks } new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks }
}; };
} }
private LiveTvOptions GetConfiguration()
{
return _config.GetConfiguration<LiveTvOptions>("livetv");
}
} }
} }

View File

@ -10,7 +10,7 @@ using System.Linq;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Common.Configuration; using Jellyfin.LiveTv.Configuration;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
@ -69,7 +69,7 @@ namespace Jellyfin.LiveTv.TunerHosts
protected virtual IList<TunerHostInfo> GetTunerHosts() protected virtual IList<TunerHostInfo> GetTunerHosts()
{ {
return GetConfiguration().TunerHosts return Config.GetLiveTvConfiguration().TunerHosts
.Where(i => string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase))
.ToList(); .ToList();
} }
@ -228,10 +228,5 @@ namespace Jellyfin.LiveTv.TunerHosts
return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase); return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase);
} }
protected LiveTvOptions GetConfiguration()
{
return Config.GetConfiguration<LiveTvOptions>("livetv");
}
} }
} }

View File

@ -16,6 +16,7 @@ using System.Threading.Tasks;
using Jellyfin.Extensions; using Jellyfin.Extensions;
using Jellyfin.Extensions.Json; using Jellyfin.Extensions.Json;
using Jellyfin.Extensions.Json.Converters; using Jellyfin.Extensions.Json.Converters;
using Jellyfin.LiveTv.Configuration;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller; using MediaBrowser.Controller;
@ -278,7 +279,7 @@ namespace Jellyfin.LiveTv.TunerHosts.HdHomerun
{ {
var list = new List<LiveTvTunerInfo>(); var list = new List<LiveTvTunerInfo>();
foreach (var host in GetConfiguration().TunerHosts foreach (var host in Config.GetLiveTvConfiguration().TunerHosts
.Where(i => string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase))) .Where(i => string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase)))
{ {
try try