Enable nullable for more files

This commit is contained in:
Bond_009 2021-08-28 17:32:09 +02:00
parent e88367fe70
commit 645825db36
12 changed files with 42 additions and 58 deletions

View file

@ -95,7 +95,7 @@ namespace Emby.Server.Implementations.Collections
var libraryOptions = new LibraryOptions var libraryOptions = new LibraryOptions
{ {
PathInfos = new[] { new MediaPathInfo { Path = path } }, PathInfos = new[] { new MediaPathInfo(path) },
EnableRealtimeMonitor = false, EnableRealtimeMonitor = false,
SaveLocalMetadata = true SaveLocalMetadata = true
}; };

View file

@ -3173,10 +3173,7 @@ namespace Emby.Server.Implementations.Library
{ {
if (!list.Any(i => string.Equals(i.Path, location, StringComparison.Ordinal))) if (!list.Any(i => string.Equals(i.Path, location, StringComparison.Ordinal)))
{ {
list.Add(new MediaPathInfo list.Add(new MediaPathInfo(location));
{
Path = location
});
} }
} }

View file

@ -1,5 +1,3 @@
#nullable disable
#pragma warning disable CS1591 #pragma warning disable CS1591
using System; using System;
@ -33,7 +31,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
return targetFile; return targetFile;
} }
public Task Record(IDirectStreamProvider directStreamProvider, MediaSourceInfo mediaSource, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken) public Task Record(IDirectStreamProvider? directStreamProvider, MediaSourceInfo mediaSource, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken)
{ {
if (directStreamProvider != null) if (directStreamProvider != null)
{ {
@ -45,7 +43,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private async Task RecordFromDirectStreamProvider(IDirectStreamProvider directStreamProvider, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken) private async Task RecordFromDirectStreamProvider(IDirectStreamProvider directStreamProvider, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken)
{ {
Directory.CreateDirectory(Path.GetDirectoryName(targetFile)); Directory.CreateDirectory(Path.GetDirectoryName(targetFile) ?? throw new ArgumentException("Path can't be a root directory.", nameof(targetFile)));
// use FileShare.None as this bypasses dotnet bug dotnet/runtime#42790 . // use FileShare.None as this bypasses dotnet bug dotnet/runtime#42790 .
using (var output = new FileStream(targetFile, FileMode.Create, FileAccess.Write, FileShare.None)) using (var output = new FileStream(targetFile, FileMode.Create, FileAccess.Write, FileShare.None))
@ -71,7 +69,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_logger.LogInformation("Opened recording stream from tuner provider"); _logger.LogInformation("Opened recording stream from tuner provider");
Directory.CreateDirectory(Path.GetDirectoryName(targetFile)); Directory.CreateDirectory(Path.GetDirectoryName(targetFile) ?? throw new ArgumentException("Path can't be a root directory.", nameof(targetFile)));
// use FileShare.None as this bypasses dotnet bug dotnet/runtime#42790 . // use FileShare.None as this bypasses dotnet bug dotnet/runtime#42790 .
await using var output = new FileStream(targetFile, FileMode.Create, FileAccess.Write, FileShare.None); await using var output = new FileStream(targetFile, FileMode.Create, FileAccess.Write, FileShare.None);

View file

@ -159,8 +159,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
try try
{ {
var recordingFolders = GetRecordingFolders().ToArray(); var recordingFolders = GetRecordingFolders().ToArray();
var virtualFolders = _libraryManager.GetVirtualFolders() var virtualFolders = _libraryManager.GetVirtualFolders();
.ToList();
var allExistingPaths = virtualFolders.SelectMany(i => i.Locations).ToList(); var allExistingPaths = virtualFolders.SelectMany(i => i.Locations).ToList();
@ -177,7 +176,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
continue; continue;
} }
var mediaPathInfos = pathsToCreate.Select(i => new MediaPathInfo { Path = i }).ToArray(); var mediaPathInfos = pathsToCreate.Select(i => new MediaPathInfo(i)).ToArray();
var libraryOptions = new LibraryOptions var libraryOptions = new LibraryOptions
{ {
@ -210,7 +209,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
foreach (var path in pathsToRemove) foreach (var path in pathsToRemove)
{ {
await RemovePathFromLibrary(path).ConfigureAwait(false); await RemovePathFromLibraryAsync(path).ConfigureAwait(false);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -219,13 +218,12 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
} }
} }
private async Task RemovePathFromLibrary(string path) private async Task RemovePathFromLibraryAsync(string path)
{ {
_logger.LogDebug("Removing path from library: {0}", path); _logger.LogDebug("Removing path from library: {0}", path);
var requiresRefresh = false; var requiresRefresh = false;
var virtualFolders = _libraryManager.GetVirtualFolders() var virtualFolders = _libraryManager.GetVirtualFolders();
.ToList();
foreach (var virtualFolder in virtualFolders) foreach (var virtualFolder in virtualFolders)
{ {
@ -460,7 +458,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
if (!string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId)) if (!string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId))
{ {
var tunerChannelId = tunerChannel.TunerChannelId; var tunerChannelId = tunerChannel.TunerChannelId;
if (tunerChannelId.IndexOf(".json.schedulesdirect.org", StringComparison.OrdinalIgnoreCase) != -1) if (tunerChannelId.Contains(".json.schedulesdirect.org", StringComparison.OrdinalIgnoreCase))
{ {
tunerChannelId = tunerChannelId.Replace(".json.schedulesdirect.org", string.Empty, StringComparison.OrdinalIgnoreCase).TrimStart('I'); tunerChannelId = tunerChannelId.Replace(".json.schedulesdirect.org", string.Empty, StringComparison.OrdinalIgnoreCase).TrimStart('I');
} }
@ -620,8 +618,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
if (existingTimer != null) if (existingTimer != null)
{ {
if (existingTimer.Status == RecordingStatus.Cancelled || if (existingTimer.Status == RecordingStatus.Cancelled
existingTimer.Status == RecordingStatus.Completed) || existingTimer.Status == RecordingStatus.Completed)
{ {
existingTimer.Status = RecordingStatus.New; existingTimer.Status = RecordingStatus.New;
existingTimer.IsManual = true; existingTimer.IsManual = true;
@ -913,18 +911,14 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var epgChannel = await GetEpgChannelFromTunerChannel(provider.Item1, provider.Item2, channel, cancellationToken).ConfigureAwait(false); var epgChannel = await GetEpgChannelFromTunerChannel(provider.Item1, provider.Item2, channel, cancellationToken).ConfigureAwait(false);
List<ProgramInfo> programs;
if (epgChannel == null) if (epgChannel == null)
{ {
_logger.LogDebug("EPG channel not found for tuner channel {0}-{1} from {2}-{3}", channel.Number, channel.Name, provider.Item1.Name, provider.Item2.ListingsId ?? string.Empty); _logger.LogDebug("EPG channel not found for tuner channel {0}-{1} from {2}-{3}", channel.Number, channel.Name, provider.Item1.Name, provider.Item2.ListingsId ?? string.Empty);
programs = new List<ProgramInfo>(); continue;
} }
else
{ List<ProgramInfo> programs = (await provider.Item1.GetProgramsAsync(provider.Item2, epgChannel.Id, startDateUtc, endDateUtc, cancellationToken)
programs = (await provider.Item1.GetProgramsAsync(provider.Item2, epgChannel.Id, startDateUtc, endDateUtc, cancellationToken)
.ConfigureAwait(false)).ToList(); .ConfigureAwait(false)).ToList();
}
// Replace the value that came from the provider with a normalized value // Replace the value that came from the provider with a normalized value
foreach (var program in programs) foreach (var program in programs)
@ -940,7 +934,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
} }
} }
return new List<ProgramInfo>(); return Enumerable.Empty<ProgramInfo>();
} }
private List<Tuple<IListingsProvider, ListingsProviderInfo>> GetListingProviders() private List<Tuple<IListingsProvider, ListingsProviderInfo>> GetListingProviders()
@ -1292,7 +1286,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_logger.LogInformation("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture)); _logger.LogInformation("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture));
_logger.LogInformation("Writing file to path: " + recordPath); _logger.LogInformation("Writing file to: {Path}", recordPath);
Action onStarted = async () => Action onStarted = async () =>
{ {
@ -1417,13 +1411,13 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private void TriggerRefresh(string path) private void TriggerRefresh(string path)
{ {
_logger.LogInformation("Triggering refresh on {path}", path); _logger.LogInformation("Triggering refresh on {Path}", path);
var item = GetAffectedBaseItem(Path.GetDirectoryName(path)); var item = GetAffectedBaseItem(Path.GetDirectoryName(path));
if (item != null) if (item != null)
{ {
_logger.LogInformation("Refreshing recording parent {path}", item.Path); _logger.LogInformation("Refreshing recording parent {Path}", item.Path);
_providerManager.QueueRefresh( _providerManager.QueueRefresh(
item.Id, item.Id,
@ -1458,7 +1452,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
if (item.GetType() == typeof(Folder) && string.Equals(item.Path, parentPath, StringComparison.OrdinalIgnoreCase)) if (item.GetType() == typeof(Folder) && string.Equals(item.Path, parentPath, StringComparison.OrdinalIgnoreCase))
{ {
var parentItem = item.GetParent(); var parentItem = item.GetParent();
if (parentItem != null && !(parentItem is AggregateFolder)) if (parentItem != null && parentItem is not AggregateFolder)
{ {
item = parentItem; item = parentItem;
} }
@ -1512,8 +1506,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
DeleteLibraryItemsForTimers(timersToDelete); DeleteLibraryItemsForTimers(timersToDelete);
var librarySeries = _libraryManager.FindByPath(seriesPath, true) as Folder; if (_libraryManager.FindByPath(seriesPath, true) is not Folder librarySeries)
if (librarySeries == null)
{ {
return; return;
} }
@ -1667,7 +1660,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_logger.LogInformation("Running recording post processor {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); _logger.LogInformation("Running recording post processor {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
process.Exited += Process_Exited; process.Exited += OnProcessExited;
process.Start(); process.Start();
} }
catch (Exception ex) catch (Exception ex)
@ -1681,7 +1674,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
return arguments.Replace("{path}", path, StringComparison.OrdinalIgnoreCase); return arguments.Replace("{path}", path, StringComparison.OrdinalIgnoreCase);
} }
private void Process_Exited(object sender, EventArgs e) private void OnProcessExited(object sender, EventArgs e)
{ {
using (var process = (Process)sender) using (var process = (Process)sender)
{ {
@ -2239,7 +2232,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
var enabledTimersForSeries = new List<TimerInfo>(); var enabledTimersForSeries = new List<TimerInfo>();
foreach (var timer in allTimers) foreach (var timer in allTimers)
{ {
var existingTimer = _timerProvider.GetTimer(timer.Id) var existingTimer = _timerProvider.GetTimer(timer.Id)
?? (string.IsNullOrWhiteSpace(timer.ProgramId) ?? (string.IsNullOrWhiteSpace(timer.ProgramId)
? null ? null
: _timerProvider.GetTimerByProgramId(timer.ProgramId)); : _timerProvider.GetTimerByProgramId(timer.ProgramId));

View file

@ -319,11 +319,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
} }
} }
} }
catch (ObjectDisposedException)
{
// TODO Investigate and properly fix.
// Don't spam the log. This doesn't seem to throw in windows, but sometimes under linux
}
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error reading ffmpeg recording log"); _logger.LogError(ex, "Error reading ffmpeg recording log");

View file

@ -8,7 +8,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{ {
internal class EpgChannelData internal class EpgChannelData
{ {
private readonly Dictionary<string, ChannelInfo> _channelsById; private readonly Dictionary<string, ChannelInfo> _channelsById;
private readonly Dictionary<string, ChannelInfo> _channelsByNumber; private readonly Dictionary<string, ChannelInfo> _channelsByNumber;

View file

@ -13,7 +13,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
/// <summary> /// <summary>
/// Records the specified media source. /// Records the specified media source.
/// </summary> /// </summary>
Task Record(IDirectStreamProvider directStreamProvider, MediaSourceInfo mediaSource, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken); Task Record(IDirectStreamProvider? directStreamProvider, MediaSourceInfo mediaSource, string targetFile, TimeSpan duration, Action onStarted, CancellationToken cancellationToken);
string GetOutputPath(MediaSourceInfo mediaSource, string targetFile); string GetOutputPath(MediaSourceInfo mediaSource, string targetFile);
} }

View file

@ -1,5 +1,3 @@
#nullable disable
#pragma warning disable CS1591 #pragma warning disable CS1591
using System; using System;
@ -23,7 +21,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{ {
} }
public event EventHandler<GenericEventArgs<TimerInfo>> TimerFired; public event EventHandler<GenericEventArgs<TimerInfo>>? TimerFired;
public void RestartTimers() public void RestartTimers()
{ {
@ -145,9 +143,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
} }
} }
private void TimerCallback(object state) private void TimerCallback(object? state)
{ {
var timerId = (string)state; var timerId = (string?)state ?? throw new ArgumentNullException(nameof(state));
var timer = GetAll().FirstOrDefault(i => string.Equals(i.Id, timerId, StringComparison.OrdinalIgnoreCase)); var timer = GetAll().FirstOrDefault(i => string.Equals(i.Id, timerId, StringComparison.OrdinalIgnoreCase));
if (timer != null) if (timer != null)
@ -156,12 +154,12 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
} }
} }
public TimerInfo GetTimer(string id) public TimerInfo? GetTimer(string id)
{ {
return GetAll().FirstOrDefault(r => string.Equals(r.Id, id, StringComparison.OrdinalIgnoreCase)); return GetAll().FirstOrDefault(r => string.Equals(r.Id, id, StringComparison.OrdinalIgnoreCase));
} }
public TimerInfo GetTimerByProgramId(string programId) public TimerInfo? GetTimerByProgramId(string programId)
{ {
return GetAll().FirstOrDefault(r => string.Equals(r.ProgramId, programId, StringComparison.OrdinalIgnoreCase)); return GetAll().FirstOrDefault(r => string.Equals(r.ProgramId, programId, StringComparison.OrdinalIgnoreCase));
} }

View file

@ -14,8 +14,8 @@ using System.Text;
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;
using Jellyfin.Extensions.Json; using Jellyfin.Extensions.Json;
using MediaBrowser.Common;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Cryptography;

View file

@ -84,7 +84,7 @@ namespace Jellyfin.Api.Controllers
if (paths != null && paths.Length > 0) if (paths != null && paths.Length > 0)
{ {
libraryOptions.PathInfos = paths.Select(i => new MediaPathInfo { Path = i }).ToArray(); libraryOptions.PathInfos = paths.Select(i => new MediaPathInfo(i)).ToArray();
} }
await _libraryManager.AddVirtualFolder(name, collectionType, libraryOptions, refreshLibrary).ConfigureAwait(false); await _libraryManager.AddVirtualFolder(name, collectionType, libraryOptions, refreshLibrary).ConfigureAwait(false);
@ -212,7 +212,7 @@ namespace Jellyfin.Api.Controllers
try try
{ {
var mediaPath = mediaPathDto.PathInfo ?? new MediaPathInfo { Path = mediaPathDto.Path }; var mediaPath = mediaPathDto.PathInfo ?? new MediaPathInfo(mediaPathDto.Path ?? throw new ArgumentException("PathInfo and Path can't both be null."));
_libraryManager.AddMediaPath(mediaPathDto.Name, mediaPath); _libraryManager.AddMediaPath(mediaPathDto.Name, mediaPath);
} }

View file

@ -1,12 +1,16 @@
#nullable disable
#pragma warning disable CS1591 #pragma warning disable CS1591
namespace MediaBrowser.Model.Configuration namespace MediaBrowser.Model.Configuration
{ {
public class MediaPathInfo public class MediaPathInfo
{ {
public MediaPathInfo(string path)
{
Path = path;
}
public string Path { get; set; } public string Path { get; set; }
public string NetworkPath { get; set; } public string? NetworkPath { get; set; }
} }
} }

View file

@ -15,8 +15,8 @@ namespace MediaBrowser.XbmcMetadata.Configuration
{ {
new ConfigurationStore new ConfigurationStore
{ {
ConfigurationType = typeof(XbmcMetadataOptions), ConfigurationType = typeof(XbmcMetadataOptions),
Key = "xbmcmetadata" Key = "xbmcmetadata"
} }
}; };
} }