Review changes

This commit is contained in:
cvium 2021-05-19 08:51:46 +02:00
parent 81ac11828b
commit 1027792b16
5 changed files with 33 additions and 28 deletions

View File

@ -59,7 +59,7 @@ namespace Emby.Naming.Video
}
bool isStub = false;
ReadOnlySpan<char> container = null;
ReadOnlySpan<char> container = ReadOnlySpan<char>.Empty;
string? stubType = null;
if (!isDirectory)
@ -105,7 +105,7 @@ namespace Emby.Naming.Video
return new VideoFileInfo(
path: path,
container: container.ToString(),
container: container.IsEmpty ? null : container.ToString(),
isStub: isStub,
name: name,
year: year,

View File

@ -130,7 +130,7 @@ namespace Emby.Server.Implementations.Data
return true;
}
private static bool IsDbNull(this IResultSetValue result)
public static bool IsDbNull(this IResultSetValue result)
{
return result.SQLiteType == SQLiteType.Null;
}
@ -158,12 +158,12 @@ namespace Emby.Server.Implementations.Data
return result[index].ToBool();
}
public static bool TryGetBoolean(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out bool? result)
public static bool TryGetBoolean(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out bool result)
{
result = null;
var item = reader[index];
if (item.IsDbNull())
{
result = default;
return false;
}
@ -171,12 +171,12 @@ namespace Emby.Server.Implementations.Data
return true;
}
public static bool TryGetInt32(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out int? result)
public static bool TryGetInt32(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out int result)
{
result = null;
var item = reader[index];
if (item.IsDbNull())
{
result = default;
return false;
}
@ -189,12 +189,12 @@ namespace Emby.Server.Implementations.Data
return result[index].ToInt64();
}
public static bool TryGetInt64(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out long? result)
public static bool TryGetInt64(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out long result)
{
result = null;
var item = reader[index];
if (item.IsDbNull())
{
result = default;
return false;
}
@ -202,12 +202,12 @@ namespace Emby.Server.Implementations.Data
return true;
}
public static bool TryGetSingle(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out float? result)
public static bool TryGetSingle(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out float result)
{
result = null;
var item = reader[index];
if (item.IsDbNull())
{
result = default;
return false;
}
@ -215,12 +215,12 @@ namespace Emby.Server.Implementations.Data
return true;
}
public static bool TryGetDouble(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out double? result)
public static bool TryGetDouble(this IReadOnlyList<IResultSetValue> reader, int index, [NotNullWhen(true)] out double result)
{
result = null;
var item = reader[index];
if (item.IsDbNull())
{
result = default;
return false;
}

View File

@ -1346,7 +1346,7 @@ namespace Emby.Server.Implementations.Data
}
var channelId = reader[index];
if (channelId.SQLiteType != SQLiteType.Null)
if (!channelId.IsDbNull())
{
if (!Utf8Parser.TryParse(channelId.ToBlob(), out Guid value, out _, standardFormat: 'N'))
{
@ -1366,12 +1366,12 @@ namespace Emby.Server.Implementations.Data
{
if (reader.TryGetBoolean(index++, out var isMovie))
{
hasProgramAttributes.IsMovie = isMovie.Value;
hasProgramAttributes.IsMovie = isMovie;
}
if (reader.TryGetBoolean(index++, out var isSeries))
{
hasProgramAttributes.IsSeries = isSeries.Value;
hasProgramAttributes.IsSeries = isSeries;
}
if (reader.TryGetString(index++, out var episodeTitle))
@ -1381,7 +1381,7 @@ namespace Emby.Server.Implementations.Data
if (reader.TryGetBoolean(index++, out var isRepeat))
{
hasProgramAttributes.IsRepeat = isRepeat.Value;
hasProgramAttributes.IsRepeat = isRepeat;
}
}
else
@ -1412,7 +1412,7 @@ namespace Emby.Server.Implementations.Data
{
if (reader.TryGetBoolean(index++, out var isLocked))
{
item.IsLocked = isLocked.Value;
item.IsLocked = isLocked;
}
if (reader.TryGetString(index++, out var preferredMetadataLanguage))
@ -1430,7 +1430,7 @@ namespace Emby.Server.Implementations.Data
{
if (reader.TryGetInt32(index++, out var width))
{
item.Width = width.Value;
item.Width = width;
}
}
@ -1438,7 +1438,7 @@ namespace Emby.Server.Implementations.Data
{
if (reader.TryGetInt32(index++, out var height))
{
item.Height = height.Value;
item.Height = height;
}
}
@ -1536,6 +1536,7 @@ namespace Emby.Server.Implementations.Data
if (reader.TryGetString(index++, out var audioString))
{
// TODO Span overload coming in the future https://github.com/dotnet/runtime/issues/1916
if (Enum.TryParse(audioString, true, out ProgramAudio audio))
{
item.Audio = audio;
@ -1559,7 +1560,7 @@ namespace Emby.Server.Implementations.Data
if (reader.TryGetBoolean(index++, out var isInMixedFolder))
{
item.IsInMixedFolder = isInMixedFolder.Value;
item.IsInMixedFolder = isInMixedFolder;
}
if (HasField(query, ItemFields.DateLastSaved))
@ -1669,7 +1670,7 @@ namespace Emby.Server.Implementations.Data
if (reader.TryGetBoolean(index++, out var isVirtualItem))
{
item.IsVirtualItem = isVirtualItem.Value;
item.IsVirtualItem = isVirtualItem;
}
if (item is IHasSeries hasSeriesName)
@ -1731,7 +1732,7 @@ namespace Emby.Server.Implementations.Data
{
if (reader.TryGetInt32(index++, out var parentalRating))
{
item.InheritedParentalRatingValue = parentalRating.Value;
item.InheritedParentalRatingValue = parentalRating;
}
}

View File

@ -148,7 +148,7 @@ namespace Jellyfin.Naming.Tests.Video
yield return new object[]
{
new VideoFileInfo(
path: @"/server/Movies/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - Ozlem/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - Ozlem.mp4",
path: @"/server/Movies/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - JEFF/Rain Man 1988 REMASTERED 1080p BluRay x264 AAC - JEFF.mp4",
container: "mp4",
name: "Rain Man",
year: 1988)
@ -200,6 +200,10 @@ namespace Jellyfin.Naming.Tests.Video
Assert.NotNull(results[0]);
Assert.NotNull(results[1]);
Assert.Null(results[2]);
foreach (var result in results)
{
Assert.Null(result?.Container);
}
}
}
}

View File

@ -38,7 +38,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
"/video/My.Video.With.Additional.Garbage.en.srt",
"/video/My.Video With Additional Garbage.srt"
},
new List<MediaStream>
new[]
{
CreateMediaStream("/video/My.Video.srt", "srt", null, index++),
CreateMediaStream("/video/My.Video.vtt", "vtt", null, index++),
@ -58,12 +58,12 @@ namespace Jellyfin.Providers.Tests.MediaInfo
[Theory]
[MemberData(nameof(AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles_TestData))]
public void AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles(List<MediaStream> streams, string videoPath, int startIndex, string[] files, List<MediaStream> expectedResult)
public void AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles(List<MediaStream> streams, string videoPath, int startIndex, string[] files, MediaStream[] expectedResult)
{
new SubtitleResolver(Mock.Of<ILocalizationManager>()).AddExternalSubtitleStreams(streams, videoPath, startIndex, files);
Assert.Equal(expectedResult.Count, streams.Count);
for (var i = 0; i < expectedResult.Count; i++)
Assert.Equal(expectedResult.Length, streams.Count);
for (var i = 0; i < expectedResult.Length; i++)
{
var expected = expectedResult[i];
var actual = streams[i];