Use ? and ?? where applicable

This commit is contained in:
Patrick Barron 2020-04-05 12:45:01 -04:00
parent 6a3f9253db
commit 961f48f5bc
13 changed files with 42 additions and 102 deletions

View file

@ -258,7 +258,7 @@ namespace MediaBrowser.Api
public void ReportTranscodingProgress(TranscodingJob job, StreamState state, TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate) public void ReportTranscodingProgress(TranscodingJob job, StreamState state, TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate)
{ {
var ticks = transcodingPosition.HasValue ? transcodingPosition.Value.Ticks : (long?)null; var ticks = transcodingPosition?.Ticks;
if (job != null) if (job != null)
{ {
@ -561,10 +561,7 @@ namespace MediaBrowser.Api
lock (job.ProcessLock) lock (job.ProcessLock)
{ {
if (job.TranscodingThrottler != null) job.TranscodingThrottler?.Stop().GetAwaiter().GetResult();
{
job.TranscodingThrottler.Stop().GetAwaiter().GetResult();
}
var process = job.Process; var process = job.Process;

View file

@ -274,36 +274,26 @@ namespace MediaBrowser.Api
private T GetItemFromSlugName<T>(ILibraryManager libraryManager, string name, DtoOptions dtoOptions) private T GetItemFromSlugName<T>(ILibraryManager libraryManager, string name, DtoOptions dtoOptions)
where T : BaseItem, new() where T : BaseItem, new()
{ {
var result = libraryManager.GetItemList(new InternalItemsQuery var result = (libraryManager.GetItemList(new InternalItemsQuery
{ {
Name = name.Replace(BaseItem.SlugChar, '&'), Name = name.Replace(BaseItem.SlugChar, '&'),
IncludeItemTypes = new[] { typeof(T).Name }, IncludeItemTypes = new[] { typeof(T).Name },
DtoOptions = dtoOptions DtoOptions = dtoOptions
}).OfType<T>().FirstOrDefault() ?? libraryManager.GetItemList(new InternalItemsQuery
{
Name = name.Replace(BaseItem.SlugChar, '/'),
IncludeItemTypes = new[] { typeof(T).Name },
DtoOptions = dtoOptions
}).OfType<T>().FirstOrDefault()) ?? libraryManager.GetItemList(new InternalItemsQuery
{
Name = name.Replace(BaseItem.SlugChar, '?'),
IncludeItemTypes = new[] { typeof(T).Name },
DtoOptions = dtoOptions
}).OfType<T>().FirstOrDefault(); }).OfType<T>().FirstOrDefault();
if (result == null)
{
result = libraryManager.GetItemList(new InternalItemsQuery
{
Name = name.Replace(BaseItem.SlugChar, '/'),
IncludeItemTypes = new[] { typeof(T).Name },
DtoOptions = dtoOptions
}).OfType<T>().FirstOrDefault();
}
if (result == null)
{
result = libraryManager.GetItemList(new InternalItemsQuery
{
Name = name.Replace(BaseItem.SlugChar, '?'),
IncludeItemTypes = new[] { typeof(T).Name },
DtoOptions = dtoOptions
}).OfType<T>().FirstOrDefault();
}
return result; return result;
} }

View file

@ -391,7 +391,6 @@ namespace MediaBrowser.Api
} }
return (SeriesStatus)Enum.Parse(typeof(SeriesStatus), item.Status, true); return (SeriesStatus)Enum.Parse(typeof(SeriesStatus), item.Status, true);
} }
} }
} }

View file

@ -327,15 +327,11 @@ namespace MediaBrowser.Api.Library
try try
{ {
var mediaPath = request.PathInfo; var mediaPath = request.PathInfo ?? new MediaPathInfo
if (mediaPath == null)
{ {
mediaPath = new MediaPathInfo Path = request.Path
{ };
Path = request.Path
};
}
_libraryManager.AddMediaPath(request.Name, mediaPath); _libraryManager.AddMediaPath(request.Name, mediaPath);
} }
finally finally

View file

@ -248,14 +248,8 @@ namespace MediaBrowser.Api.Playback
if (state.VideoRequest != null if (state.VideoRequest != null
&& string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)) && string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{ {
if (string.Equals(state.OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase)) logFilePrefix = string.Equals(state.OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase)
{ ? "ffmpeg-remux" : "ffmpeg-directstream";
logFilePrefix = "ffmpeg-remux";
}
else
{
logFilePrefix = "ffmpeg-directstream";
}
} }
var logFilePath = Path.Combine(ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, logFilePrefix + "-" + Guid.NewGuid() + ".txt"); var logFilePath = Path.Combine(ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, logFilePrefix + "-" + Guid.NewGuid() + ".txt");
@ -862,14 +856,7 @@ namespace MediaBrowser.Api.Playback
{ {
var caps = DeviceManager.GetCapabilities(state.Request.DeviceId); var caps = DeviceManager.GetCapabilities(state.Request.DeviceId);
if (caps != null) state.DeviceProfile = caps != null ? caps.DeviceProfile : DlnaManager.GetProfile(headers);
{
state.DeviceProfile = caps.DeviceProfile;
}
else
{
state.DeviceProfile = DlnaManager.GetProfile(headers);
}
} }
} }

View file

@ -140,7 +140,7 @@ namespace MediaBrowser.Api.Playback.Hls
if (isLive) if (isLive)
{ {
job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType); job ??= ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType);
if (job != null) if (job != null)
{ {
@ -156,7 +156,7 @@ namespace MediaBrowser.Api.Playback.Hls
var playlistText = GetMasterPlaylistFileText(playlist, videoBitrate + audioBitrate, baselineStreamBitrate); var playlistText = GetMasterPlaylistFileText(playlist, videoBitrate + audioBitrate, baselineStreamBitrate);
job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType); job ??= ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType);
if (job != null) if (job != null)
{ {

View file

@ -284,7 +284,7 @@ namespace MediaBrowser.Api.Playback.Hls
//} //}
Logger.LogDebug("returning {0} [general case]", segmentPath); Logger.LogDebug("returning {0} [general case]", segmentPath);
job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); job ??= ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);
return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false); return await GetSegmentResult(state, playlistPath, segmentPath, segmentExtension, requestedIndex, job, cancellationToken).ConfigureAwait(false);
} }
@ -934,7 +934,7 @@ namespace MediaBrowser.Api.Playback.Hls
var framerate = state.VideoStream?.RealFrameRate; var framerate = state.VideoStream?.RealFrameRate;
if (framerate != null && framerate.HasValue) if (framerate.HasValue)
{ {
// This is to make sure keyframe interval is limited to our segment, // This is to make sure keyframe interval is limited to our segment,
// as forcing keyframes is not enough. // as forcing keyframes is not enough.

View file

@ -583,7 +583,7 @@ namespace MediaBrowser.Api.Playback
private long? GetMaxBitrate(long? clientMaxBitrate, User user) private long? GetMaxBitrate(long? clientMaxBitrate, User user)
{ {
var maxBitrate = clientMaxBitrate; var maxBitrate = clientMaxBitrate;
var remoteClientMaxBitrate = user == null ? 0 : user.Policy.RemoteClientBitrateLimit; var remoteClientMaxBitrate = user?.Policy.RemoteClientBitrateLimit ?? 0;
if (remoteClientMaxBitrate <= 0) if (remoteClientMaxBitrate <= 0)
{ {

View file

@ -167,7 +167,7 @@ namespace MediaBrowser.Api.Playback
AudioCodec = request.AudioCodec, AudioCodec = request.AudioCodec,
Protocol = request.TranscodingProtocol, Protocol = request.TranscodingProtocol,
BreakOnNonKeyFrames = request.BreakOnNonKeyFrames, BreakOnNonKeyFrames = request.BreakOnNonKeyFrames,
MaxAudioChannels = request.TranscodingAudioChannels.HasValue ? request.TranscodingAudioChannels.Value.ToString(CultureInfo.InvariantCulture) : null MaxAudioChannels = request.TranscodingAudioChannels?.ToString(CultureInfo.InvariantCulture)
} }
}; };

View file

@ -279,7 +279,7 @@ namespace MediaBrowser.Api
if (!item.ChannelId.Equals(Guid.Empty)) if (!item.ChannelId.Equals(Guid.Empty))
{ {
var channel = _libraryManager.GetItemById(item.ChannelId); var channel = _libraryManager.GetItemById(item.ChannelId);
result.ChannelName = channel == null ? null : channel.Name; result.ChannelName = channel?.Name;
} }
return result; return result;
@ -316,12 +316,8 @@ namespace MediaBrowser.Api
private void SetBackdropImageInfo(SearchHint hint, BaseItem item) private void SetBackdropImageInfo(SearchHint hint, BaseItem item)
{ {
var itemWithImage = item.HasImage(ImageType.Backdrop) ? item : null; var itemWithImage = (item.HasImage(ImageType.Backdrop) ? item : null)
?? GetParentWithImage<BaseItem>(item, ImageType.Backdrop);
if (itemWithImage == null)
{
itemWithImage = GetParentWithImage<BaseItem>(item, ImageType.Backdrop);
}
if (itemWithImage != null) if (itemWithImage != null)
{ {

View file

@ -92,10 +92,7 @@ namespace MediaBrowser.Api
{ {
lock (_timerLock) lock (_timerLock)
{ {
if (KillTimer != null) KillTimer?.Change(Timeout.Infinite, Timeout.Infinite);
{
KillTimer.Change(Timeout.Infinite, Timeout.Infinite);
}
} }
} }

View file

@ -442,14 +442,7 @@ namespace MediaBrowser.Api
var season = series.GetSeasons(user, dtoOptions).FirstOrDefault(i => i.IndexNumber == request.Season.Value); var season = series.GetSeasons(user, dtoOptions).FirstOrDefault(i => i.IndexNumber == request.Season.Value);
if (season == null) episodes = season == null ? new List<BaseItem>() : ((Season)season).GetEpisodes(user, dtoOptions);
{
episodes = new List<BaseItem>();
}
else
{
episodes = ((Season)season).GetEpisodes(user, dtoOptions);
}
} }
else else
{ {

View file

@ -138,32 +138,17 @@ namespace MediaBrowser.Api
var videosWithVersions = items.Where(i => i.MediaSourceCount > 1) var videosWithVersions = items.Where(i => i.MediaSourceCount > 1)
.ToList(); .ToList();
var primaryVersion = videosWithVersions.FirstOrDefault(); var primaryVersion = videosWithVersions.FirstOrDefault() ?? items.OrderBy(i =>
{
return (i.Video3DFormat.HasValue || i.VideoType != Model.Entities.VideoType.VideoFile) ? 1 : 0;
})
.ThenByDescending(i =>
{
var stream = i.GetDefaultVideoStream();
if (primaryVersion == null) return stream?.Width ?? 0;
{
primaryVersion = items.OrderBy(i =>
{
if (i.Video3DFormat.HasValue)
{
return 1;
}
if (i.VideoType != Model.Entities.VideoType.VideoFile) }).First();
{
return 1;
}
return 0;
})
.ThenByDescending(i =>
{
var stream = i.GetDefaultVideoStream();
return stream == null || stream.Width == null ? 0 : stream.Width.Value;
}).First();
}
var list = primaryVersion.LinkedAlternateVersions.ToList(); var list = primaryVersion.LinkedAlternateVersions.ToList();