Simplified Conditionals and returns

pull/2772/head
Patrick Barron 5 years ago
parent 80cfcf5643
commit add0a2088d

@ -86,12 +86,9 @@ namespace MediaBrowser.Api
return Array.Empty<string>();
}
if (removeEmpty)
{
return value.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries);
}
return value.Split(separator);
return removeEmpty
? value.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries)
: value.Split(separator);
}
public SemaphoreSlim GetTranscodingLock(string outputPath)
@ -487,16 +484,9 @@ namespace MediaBrowser.Api
/// <returns>Task.</returns>
internal Task KillTranscodingJobs(string deviceId, string playSessionId, Func<string, bool> deleteFiles)
{
return KillTranscodingJobs(j =>
{
if (!string.IsNullOrWhiteSpace(playSessionId))
{
return string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase);
}
return string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase);
}, deleteFiles);
return KillTranscodingJobs(j => !string.IsNullOrWhiteSpace(playSessionId)
? string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase)
: string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase), deleteFiles);
}
/// <summary>

@ -58,12 +58,9 @@ namespace MediaBrowser.Api
public static string[] SplitValue(string value, char delim)
{
if (value == null)
{
return Array.Empty<string>();
}
return value.Split(new[] { delim }, StringSplitOptions.RemoveEmptyEntries);
return value == null
? Array.Empty<string>()
: value.Split(new[] { delim }, StringSplitOptions.RemoveEmptyEntries);
}
public static Guid[] GetGuids(string value)
@ -97,21 +94,12 @@ namespace MediaBrowser.Api
var authenticatedUser = auth.User;
// If they're going to update the record of another user, they must be an administrator
if (!userId.Equals(auth.UserId))
{
if (!authenticatedUser.Policy.IsAdministrator)
if ((!userId.Equals(auth.UserId) && !authenticatedUser.Policy.IsAdministrator)
|| (restrictUserPreferences && !authenticatedUser.Policy.EnableUserPreferenceAccess))
{
throw new SecurityException("Unauthorized access.");
}
}
else if (restrictUserPreferences)
{
if (!authenticatedUser.Policy.EnableUserPreferenceAccess)
{
throw new SecurityException("Unauthorized access.");
}
}
}
/// <summary>
/// Gets the session.

@ -116,12 +116,9 @@ namespace MediaBrowser.Api
{
var val = Filters;
if (string.IsNullOrEmpty(val))
{
return new ItemFilter[] { };
}
return val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true));
return string.IsNullOrEmpty(val)
? new ItemFilter[] { }
: val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true));
}
/// <summary>
@ -175,12 +172,9 @@ namespace MediaBrowser.Api
{
var val = Filters;
if (string.IsNullOrEmpty(val))
{
return new ItemFilter[] { };
}
return val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true));
return string.IsNullOrEmpty(val)
? new ItemFilter[] { }
: val.Split(',').Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true));
}
}

@ -155,8 +155,7 @@ namespace MediaBrowser.Api.Devices
Id = id
});
}
else
{
return _deviceManager.AcceptCameraUpload(deviceId, request.RequestStream, new LocalFileInfo
{
MimeType = Request.ContentType,
@ -167,4 +166,3 @@ namespace MediaBrowser.Api.Devices
}
}
}
}

@ -258,12 +258,7 @@ namespace MediaBrowser.Api
return false;
}
if (!request.IncludeDirectories && isDirectory)
{
return false;
}
return true;
return request.IncludeDirectories || !isDirectory;
});
return entries.Select(f => new FileSystemEntryInfo

@ -348,28 +348,19 @@ namespace MediaBrowser.Api.Library
private string[] GetRepresentativeItemTypes(string contentType)
{
switch (contentType)
{
case CollectionType.BoxSets:
return new[] { "BoxSet" };
case CollectionType.Playlists:
return new[] { "Playlist" };
case CollectionType.Movies:
return new[] { "Movie" };
case CollectionType.TvShows:
return new[] { "Series", "Season", "Episode" };
case CollectionType.Books:
return new[] { "Book" };
case CollectionType.Music:
return new[] { "MusicAlbum", "MusicArtist", "Audio", "MusicVideo" };
case CollectionType.HomeVideos:
case CollectionType.Photos:
return new[] { "Video", "Photo" };
case CollectionType.MusicVideos:
return new[] { "MusicVideo" };
default:
return new[] { "Series", "Season", "Episode", "Movie" };
}
return contentType switch
{
CollectionType.BoxSets => new[] {"BoxSet"},
CollectionType.Playlists => new[] {"Playlist"},
CollectionType.Movies => new[] {"Movie"},
CollectionType.TvShows => new[] {"Series", "Season", "Episode"},
CollectionType.Books => new[] {"Book"},
CollectionType.Music => new[] {"MusicAlbum", "MusicArtist", "Audio", "MusicVideo"},
CollectionType.HomeVideos => new[] {"Video", "Photo"},
CollectionType.Photos => new[] {"Video", "Photo"},
CollectionType.MusicVideos => new[] {"MusicVideo"},
_ => new[] {"Series", "Season", "Episode", "Movie"}
};
}
private bool IsSaverEnabledByDefault(string name, string[] itemTypes, bool isNewLibrary)
@ -397,22 +388,18 @@ namespace MediaBrowser.Api.Library
{
if (string.Equals(name, "TheMovieDb", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(type, "Series", StringComparison.OrdinalIgnoreCase))
{
return true;
}
if (string.Equals(type, "Season", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (string.Equals(type, "MusicVideo", StringComparison.OrdinalIgnoreCase))
if (string.Equals(type, "Season", StringComparison.OrdinalIgnoreCase)
|| string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase)
|| string.Equals(type, "MusicVideo", StringComparison.OrdinalIgnoreCase))
{
return false;
}
return true;
}
else if (string.Equals(name, "TheTVDB", StringComparison.OrdinalIgnoreCase))
@ -439,12 +426,8 @@ namespace MediaBrowser.Api.Library
.Where(i => string.Equals(i.ItemType, type, StringComparison.OrdinalIgnoreCase))
.ToArray();
if (metadataOptions.Length == 0)
{
return true;
}
return metadataOptions.Any(i => !i.DisabledMetadataFetchers.Contains(name, StringComparer.OrdinalIgnoreCase));
return metadataOptions.Length == 0
|| metadataOptions.Any(i => !i.DisabledMetadataFetchers.Contains(name, StringComparer.OrdinalIgnoreCase));
}
private bool IsImageFetcherEnabledByDefault(string name, string type, bool isNewLibrary)
@ -919,12 +902,10 @@ namespace MediaBrowser.Api.Library
private BaseItem TranslateParentItem(BaseItem item, User user)
{
if (item.GetParent() is AggregateFolder)
{
return _libraryManager.GetUserRootFolder().GetChildren(user, true).FirstOrDefault(i => i.PhysicalLocations.Contains(item.Path));
}
return item;
return item.GetParent() is AggregateFolder
? _libraryManager.GetUserRootFolder().GetChildren(user, true)
.FirstOrDefault(i => i.PhysicalLocations.Contains(item.Path))
: item;
}
/// <summary>

@ -137,12 +137,7 @@ namespace MediaBrowser.Api.Playback
var ext = outputFileExtension.ToLowerInvariant();
var folder = ServerConfigurationManager.GetTranscodePath();
if (EnableOutputInSubFolder)
{
return Path.Combine(folder, filename, filename + ext);
}
return Path.Combine(folder, filename + ext);
return EnableOutputInSubFolder ? Path.Combine(folder, filename, filename + ext) : Path.Combine(folder, filename + ext);
}
protected virtual string GetDefaultEncoderPreset()
@ -383,143 +378,156 @@ namespace MediaBrowser.Api.Playback
continue;
}
if (i == 0)
switch (i)
{
case 0:
request.DeviceProfileId = val;
}
else if (i == 1)
{
break;
case 1:
request.DeviceId = val;
}
else if (i == 2)
{
break;
case 2:
request.MediaSourceId = val;
}
else if (i == 3)
{
break;
case 3:
request.Static = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
}
else if (i == 4)
break;
case 4:
{
if (videoRequest != null)
{
videoRequest.VideoCodec = val;
}
break;
}
else if (i == 5)
{
case 5:
request.AudioCodec = val;
}
else if (i == 6)
break;
case 6:
{
if (videoRequest != null)
{
videoRequest.AudioStreamIndex = int.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 7)
case 7:
{
if (videoRequest != null)
{
videoRequest.SubtitleStreamIndex = int.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 8)
case 8:
{
if (videoRequest != null)
{
videoRequest.VideoBitRate = int.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 9)
{
case 9:
request.AudioBitRate = int.Parse(val, CultureInfo.InvariantCulture);
}
else if (i == 10)
{
break;
case 10:
request.MaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture);
}
else if (i == 11)
break;
case 11:
{
if (videoRequest != null)
{
videoRequest.MaxFramerate = float.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 12)
case 12:
{
if (videoRequest != null)
{
videoRequest.MaxWidth = int.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 13)
case 13:
{
if (videoRequest != null)
{
videoRequest.MaxHeight = int.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 14)
{
case 14:
request.StartTimeTicks = long.Parse(val, CultureInfo.InvariantCulture);
}
else if (i == 15)
break;
case 15:
{
if (videoRequest != null)
{
videoRequest.Level = val;
}
break;
}
else if (i == 16)
case 16:
{
if (videoRequest != null)
{
videoRequest.MaxRefFrames = int.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 17)
case 17:
{
if (videoRequest != null)
{
videoRequest.MaxVideoBitDepth = int.Parse(val, CultureInfo.InvariantCulture);
}
break;
}
else if (i == 18)
case 18:
{
if (videoRequest != null)
{
videoRequest.Profile = val;
}
break;
}
else if (i == 19)
{
case 19:
// cabac no longer used
}
else if (i == 20)
{
break;
case 20:
request.PlaySessionId = val;
}
else if (i == 21)
{
break;
case 21:
// api_key
}
else if (i == 22)
{
break;
case 22:
request.LiveStreamId = val;
}
else if (i == 23)
{
break;
case 23:
// Duplicating ItemId because of MediaMonkey
}
else if (i == 24)
break;
case 24:
{
if (videoRequest != null)
{
videoRequest.CopyTimestamps = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
}
break;
}
else if (i == 25)
case 25:
{
if (!string.IsNullOrWhiteSpace(val) && videoRequest != null)
{
@ -528,50 +536,57 @@ namespace MediaBrowser.Api.Playback
videoRequest.SubtitleMethod = method;
}
}
break;
}
else if (i == 26)
{
case 26:
request.TranscodingMaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture);
}
else if (i == 27)
break;
case 27:
{
if (videoRequest != null)
{
videoRequest.EnableSubtitlesInManifest = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
}
break;
}
else if (i == 28)
{
case 28:
request.Tag = val;
}
else if (i == 29)
break;
case 29:
{
if (videoRequest != null)
{
videoRequest.RequireAvc = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
}
break;
}
else if (i == 30)
{
case 30:
request.SubtitleCodec = val;
}
else if (i == 31)
break;
case 31:
{
if (videoRequest != null)
{
videoRequest.RequireNonAnamorphic = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
}
break;
}
else if (i == 32)
case 32:
{
if (videoRequest != null)
{
videoRequest.DeInterlace = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
}
break;
}
else if (i == 33)
{
case 33:
request.TranscodeReasons = val;
break;
}
}
}
@ -624,14 +639,9 @@ namespace MediaBrowser.Api.Playback
throw new ArgumentException("Invalid timeseek header");
}
int index = value.IndexOf('-');
if (index == -1)
{
value = value.Substring(Npt.Length);
}
else
{
value = value.Substring(Npt.Length, index - Npt.Length);
}
value = index == -1
? value.Substring(Npt.Length)
: value.Substring(Npt.Length, index - Npt.Length);
if (value.IndexOf(':') == -1)
{

@ -662,17 +662,9 @@ namespace MediaBrowser.Api.Playback
};
}).ThenBy(i =>
{
if (maxBitrate.HasValue)
if (maxBitrate.HasValue && i.Bitrate.HasValue)
{
if (i.Bitrate.HasValue)
{
if (i.Bitrate.Value <= maxBitrate.Value)
{
return 0;
}
return 2;
}
return i.Bitrate.Value <= maxBitrate.Value ? 0 : 2;
}
return 1;

@ -234,46 +234,44 @@ namespace MediaBrowser.Api
SetThumbImageInfo(result, item);
SetBackdropImageInfo(result, item);
if (item is LiveTvProgram program)
{
result.StartDate = program.StartDate;
}
if (item is IHasSeries hasSeries)
switch (item)
{
case IHasSeries hasSeries:
result.Series = hasSeries.SeriesName;
}
if (item is Series series)
break;
case LiveTvProgram program:
result.StartDate = program.StartDate;
break;
case Series series:
{
if (series.Status.HasValue)
{
result.Status = series.Status.Value.ToString();
}
}
if (item is MusicAlbum album)
{
break;
}
case MusicAlbum album:
result.Artists = album.Artists;
result.AlbumArtist = album.AlbumArtist;
}
if (item is Audio song)
{
break;
case Audio song:
result.AlbumArtist = song.AlbumArtists.FirstOrDefault();
result.Artists = song.Artists;
album = song.AlbumEntity;
MusicAlbum musicAlbum = song.AlbumEntity;
if (album != null)
if (musicAlbum != null)
{
result.Album = album.Name;
result.AlbumId = album.Id;
result.Album = musicAlbum.Name;
result.AlbumId = musicAlbum.Id;
}
else
{
result.Album = song.Album;
}
break;
}
if (!item.ChannelId.Equals(Guid.Empty))
@ -289,13 +287,10 @@ namespace MediaBrowser.Api
{
var itemWithImage = item.HasImage(ImageType.Thumb) ? item : null;
if (itemWithImage == null)
{
if (item is Episode)
if (itemWithImage == null && item is Episode)
{
itemWithImage = GetParentWithImage<Series>(item, ImageType.Thumb);
}
}
if (itemWithImage == null)
{

@ -168,12 +168,8 @@ namespace MediaBrowser.Api.System
.First(i => string.Equals(i.Name, request.Name, StringComparison.OrdinalIgnoreCase));
// For older files, assume fully static
if (file.LastWriteTimeUtc < DateTime.UtcNow.AddHours(-1))
{
return ResultFactory.GetStaticFileResult(Request, file.FullName, FileShare.Read);
}
return ResultFactory.GetStaticFileResult(Request, file.FullName, FileShare.ReadWrite);
return ResultFactory.GetStaticFileResult(Request, file.FullName,
file.LastWriteTimeUtc < DateTime.UtcNow.AddHours(-1) ? FileShare.Read : FileShare.ReadWrite);
}
/// <summary>

@ -126,12 +126,7 @@ namespace MediaBrowser.Api.UserLibrary
protected override QueryResult<(BaseItem, ItemCounts)> GetItems(GetItemsByName request, InternalItemsQuery query)
{
if (request is GetAlbumArtists)
{
return LibraryManager.GetAlbumArtists(query);
}
return LibraryManager.GetArtists(query);
return request is GetAlbumArtists ? LibraryManager.GetAlbumArtists(query) : LibraryManager.GetArtists(query);
}
/// <summary>

@ -396,12 +396,10 @@ namespace MediaBrowser.Api.UserLibrary
public VideoType[] GetVideoTypes()
{
if (string.IsNullOrEmpty(VideoTypes))
{
return Array.Empty<VideoType>();
}
return VideoTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(v => (VideoType)Enum.Parse(typeof(VideoType), v, true)).ToArray();
return string.IsNullOrEmpty(VideoTypes)
? Array.Empty<VideoType>()
: VideoTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(v => (VideoType)Enum.Parse(typeof(VideoType), v, true)).ToArray();
}
/// <summary>
@ -412,12 +410,10 @@ namespace MediaBrowser.Api.UserLibrary
{
var val = Filters;
if (string.IsNullOrEmpty(val))
{
return new ItemFilter[] { };
}
return val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true)).ToArray();
return string.IsNullOrEmpty(val)
? new ItemFilter[] { }
: val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).
Select(v => (ItemFilter)Enum.Parse(typeof(ItemFilter), v, true)).ToArray();
}
/// <summary>
@ -428,12 +424,9 @@ namespace MediaBrowser.Api.UserLibrary
{
var val = ImageTypes;
if (string.IsNullOrEmpty(val))
{
return new ImageType[] { };
}
return val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToArray();
return string.IsNullOrEmpty(val)
? new ImageType[] { }
: val.Split(',').Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToArray();
}
/// <summary>

Loading…
Cancel
Save