mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-03 19:17:24 -05:00 
			
		
		
		
	Add LiveTv configuration extension
This commit is contained in:
		
							parent
							
								
									93e5135391
								
							
						
					
					
						commit
						ad51f4f95d
					
				@ -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");
 | 
			
		||||
}
 | 
			
		||||
@ -17,6 +17,7 @@ using System.Xml;
 | 
			
		||||
using Jellyfin.Data.Enums;
 | 
			
		||||
using Jellyfin.Data.Events;
 | 
			
		||||
using Jellyfin.Extensions;
 | 
			
		||||
using Jellyfin.LiveTv.Configuration;
 | 
			
		||||
using MediaBrowser.Common.Configuration;
 | 
			
		||||
using MediaBrowser.Common.Extensions;
 | 
			
		||||
using MediaBrowser.Common.Progress;
 | 
			
		||||
@ -126,7 +127,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                var path = GetConfiguration().RecordingPath;
 | 
			
		||||
                var path = _config.GetLiveTvConfiguration().RecordingPath;
 | 
			
		||||
 | 
			
		||||
                return string.IsNullOrWhiteSpace(path)
 | 
			
		||||
                    ? DefaultRecordingPath
 | 
			
		||||
@ -189,7 +190,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
                    pathsAdded.AddRange(pathsToCreate);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var config = GetConfiguration();
 | 
			
		||||
                var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
                var pathsToRemove = config.MediaLocationsCreated
 | 
			
		||||
                    .Except(recordingFolders.SelectMany(i => i.Locations))
 | 
			
		||||
@ -831,7 +832,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
 | 
			
		||||
        public Task<SeriesTimerInfo> GetNewTimerDefaultsAsync(CancellationToken cancellationToken, ProgramInfo program = null)
 | 
			
		||||
        {
 | 
			
		||||
            var config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
            var defaults = new SeriesTimerInfo()
 | 
			
		||||
            {
 | 
			
		||||
@ -932,7 +933,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
 | 
			
		||||
        private List<Tuple<IListingsProvider, ListingsProviderInfo>> GetListingProviders()
 | 
			
		||||
        {
 | 
			
		||||
            return GetConfiguration().ListingProviders
 | 
			
		||||
            return _config.GetLiveTvConfiguration().ListingProviders
 | 
			
		||||
                .Select(i =>
 | 
			
		||||
                {
 | 
			
		||||
                    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)
 | 
			
		||||
        {
 | 
			
		||||
            var recordPath = RecordingPath;
 | 
			
		||||
            var config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
            seriesPath = null;
 | 
			
		||||
 | 
			
		||||
            if (timer.IsProgramSeries)
 | 
			
		||||
@ -1596,7 +1597,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
 | 
			
		||||
        private void PostProcessRecording(TimerInfo timer, string path)
 | 
			
		||||
        {
 | 
			
		||||
            var options = GetConfiguration();
 | 
			
		||||
            var options = _config.GetLiveTvConfiguration();
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(options.RecordingPostProcessor))
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
@ -1777,7 +1778,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
                    program.AddGenre("News");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var config = GetConfiguration();
 | 
			
		||||
                var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
                if (config.SaveRecordingNFO)
 | 
			
		||||
                {
 | 
			
		||||
@ -2128,11 +2129,6 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
            return _libraryManager.GetItemList(query).Cast<LiveTvProgram>().FirstOrDefault();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private LiveTvOptions GetConfiguration()
 | 
			
		||||
        {
 | 
			
		||||
            return _config.GetConfiguration<LiveTvOptions>("livetv");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool ShouldCancelTimerForSeriesTimer(SeriesTimerInfo seriesTimer, TimerInfo timer)
 | 
			
		||||
        {
 | 
			
		||||
            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))
 | 
			
		||||
            {
 | 
			
		||||
                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))
 | 
			
		||||
            {
 | 
			
		||||
                yield return new VirtualFolderInfo
 | 
			
		||||
@ -2546,7 +2542,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
        {
 | 
			
		||||
            var list = new List<TunerHostInfo>();
 | 
			
		||||
 | 
			
		||||
            var configuredDeviceIds = GetConfiguration().TunerHosts
 | 
			
		||||
            var configuredDeviceIds = _config.GetLiveTvConfiguration().TunerHosts
 | 
			
		||||
               .Where(i => !string.IsNullOrWhiteSpace(i.DeviceId))
 | 
			
		||||
               .Select(i => i.DeviceId)
 | 
			
		||||
               .ToList();
 | 
			
		||||
@ -2579,7 +2575,7 @@ namespace Jellyfin.LiveTv.EmbyTV
 | 
			
		||||
        {
 | 
			
		||||
            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))
 | 
			
		||||
                .ToList();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,7 @@ using System.Threading.Tasks;
 | 
			
		||||
using Jellyfin.Data.Entities;
 | 
			
		||||
using Jellyfin.Data.Enums;
 | 
			
		||||
using Jellyfin.Data.Events;
 | 
			
		||||
using MediaBrowser.Common.Configuration;
 | 
			
		||||
using Jellyfin.LiveTv.Configuration;
 | 
			
		||||
using MediaBrowser.Common.Extensions;
 | 
			
		||||
using MediaBrowser.Common.Progress;
 | 
			
		||||
using MediaBrowser.Controller.Channels;
 | 
			
		||||
@ -108,11 +108,6 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
 | 
			
		||||
        public IReadOnlyList<IListingsProvider> ListingProviders => _listingProviders;
 | 
			
		||||
 | 
			
		||||
        private LiveTvOptions GetConfiguration()
 | 
			
		||||
        {
 | 
			
		||||
            return _config.GetConfiguration<LiveTvOptions>("livetv");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetEmbyTvActiveRecordingPath(string id)
 | 
			
		||||
        {
 | 
			
		||||
            return EmbyTV.EmbyTV.Current.GetActiveRecordingPath(id);
 | 
			
		||||
@ -1302,7 +1297,7 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
 | 
			
		||||
        private double GetGuideDays()
 | 
			
		||||
        {
 | 
			
		||||
            var config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
            if (config.GuideDays.HasValue)
 | 
			
		||||
            {
 | 
			
		||||
@ -2125,7 +2120,7 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
 | 
			
		||||
        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()
 | 
			
		||||
@ -2187,7 +2182,7 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
                await configurable.Validate(info).ConfigureAwait(false);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
            var list = config.TunerHosts.ToList();
 | 
			
		||||
            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);
 | 
			
		||||
 | 
			
		||||
            LiveTvOptions config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
            var list = config.ListingProviders.ToList();
 | 
			
		||||
            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)
 | 
			
		||||
        {
 | 
			
		||||
            var config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
            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)
 | 
			
		||||
        {
 | 
			
		||||
            var config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
            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();
 | 
			
		||||
@ -2327,7 +2322,7 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
 | 
			
		||||
        public Task<List<NameIdPair>> GetLineups(string providerType, string providerId, string country, string location)
 | 
			
		||||
        {
 | 
			
		||||
            var config = GetConfiguration();
 | 
			
		||||
            var config = _config.GetLiveTvConfiguration();
 | 
			
		||||
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(providerId))
 | 
			
		||||
            {
 | 
			
		||||
@ -2357,13 +2352,13 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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));
 | 
			
		||||
            return provider.GetChannels(info, cancellationToken);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -2,9 +2,9 @@ using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Jellyfin.LiveTv.Configuration;
 | 
			
		||||
using MediaBrowser.Common.Configuration;
 | 
			
		||||
using MediaBrowser.Controller.LiveTv;
 | 
			
		||||
using MediaBrowser.Model.LiveTv;
 | 
			
		||||
using MediaBrowser.Model.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace Jellyfin.LiveTv
 | 
			
		||||
@ -38,7 +38,7 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
        public string Category => "Live TV";
 | 
			
		||||
 | 
			
		||||
        /// <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 />
 | 
			
		||||
        public bool IsEnabled => true;
 | 
			
		||||
@ -66,10 +66,5 @@ namespace Jellyfin.LiveTv
 | 
			
		||||
                new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks }
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private LiveTvOptions GetConfiguration()
 | 
			
		||||
        {
 | 
			
		||||
            return _config.GetConfiguration<LiveTvOptions>("livetv");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ using System.Linq;
 | 
			
		||||
using System.Text.Json;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using MediaBrowser.Common.Configuration;
 | 
			
		||||
using Jellyfin.LiveTv.Configuration;
 | 
			
		||||
using MediaBrowser.Controller.Configuration;
 | 
			
		||||
using MediaBrowser.Controller.Library;
 | 
			
		||||
using MediaBrowser.Controller.LiveTv;
 | 
			
		||||
@ -69,7 +69,7 @@ namespace Jellyfin.LiveTv.TunerHosts
 | 
			
		||||
 | 
			
		||||
        protected virtual IList<TunerHostInfo> GetTunerHosts()
 | 
			
		||||
        {
 | 
			
		||||
            return GetConfiguration().TunerHosts
 | 
			
		||||
            return Config.GetLiveTvConfiguration().TunerHosts
 | 
			
		||||
                .Where(i => string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase))
 | 
			
		||||
                .ToList();
 | 
			
		||||
        }
 | 
			
		||||
@ -228,10 +228,5 @@ namespace Jellyfin.LiveTv.TunerHosts
 | 
			
		||||
 | 
			
		||||
            return channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected LiveTvOptions GetConfiguration()
 | 
			
		||||
        {
 | 
			
		||||
            return Config.GetConfiguration<LiveTvOptions>("livetv");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,7 @@ using System.Threading.Tasks;
 | 
			
		||||
using Jellyfin.Extensions;
 | 
			
		||||
using Jellyfin.Extensions.Json;
 | 
			
		||||
using Jellyfin.Extensions.Json.Converters;
 | 
			
		||||
using Jellyfin.LiveTv.Configuration;
 | 
			
		||||
using MediaBrowser.Common.Extensions;
 | 
			
		||||
using MediaBrowser.Common.Net;
 | 
			
		||||
using MediaBrowser.Controller;
 | 
			
		||||
@ -278,7 +279,7 @@ namespace Jellyfin.LiveTv.TunerHosts.HdHomerun
 | 
			
		||||
        {
 | 
			
		||||
            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)))
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user