Backport pull request #11648 from jellyfin/release-10.9.z
Fix series status parsing
Original-merge: c6c48a2b47
Merged-by: nielsvanvelzen <nielsvanvelzen@users.noreply.github.com>
Backported-by: Joshua M. Boniface <joshua@boniface.me>
pull/11711/head
parent
29a293f9e7
commit
b063dfd2e3
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace Emby.Naming.TV;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for TV metadata parsing.
|
||||
/// </summary>
|
||||
public static class TvParserHelpers
|
||||
{
|
||||
private static readonly string[] _continuingState = ["Pilot", "Returning Series", "Returning"];
|
||||
private static readonly string[] _endedState = ["Cancelled"];
|
||||
|
||||
/// <summary>
|
||||
/// Tries to parse a string into <see cref="SeriesStatus"/>.
|
||||
/// </summary>
|
||||
/// <param name="status">The status string.</param>
|
||||
/// <param name="enumValue">The <see cref="SeriesStatus"/>.</param>
|
||||
/// <returns>Returns true if parsing was successful.</returns>
|
||||
public static bool TryParseSeriesStatus(string status, out SeriesStatus? enumValue)
|
||||
{
|
||||
if (Enum.TryParse(status, true, out SeriesStatus seriesStatus))
|
||||
{
|
||||
enumValue = seriesStatus;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_continuingState.Contains(status, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
enumValue = SeriesStatus.Continuing;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_endedState.Contains(status, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
enumValue = SeriesStatus.Ended;
|
||||
return true;
|
||||
}
|
||||
|
||||
enumValue = null;
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using Emby.Naming.TV;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Naming.Tests.TV;
|
||||
|
||||
public class TvParserHelpersTest
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Ended", SeriesStatus.Ended)]
|
||||
[InlineData("Cancelled", SeriesStatus.Ended)]
|
||||
[InlineData("Continuing", SeriesStatus.Continuing)]
|
||||
[InlineData("Returning", SeriesStatus.Continuing)]
|
||||
[InlineData("Returning Series", SeriesStatus.Continuing)]
|
||||
[InlineData("Unreleased", SeriesStatus.Unreleased)]
|
||||
public void SeriesStatusParserTest_Valid(string statusString, SeriesStatus? status)
|
||||
{
|
||||
var successful = TvParserHelpers.TryParseSeriesStatus(statusString, out var parsered);
|
||||
Assert.True(successful);
|
||||
Assert.Equal(status, parsered);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("XXX")]
|
||||
public void SeriesStatusParserTest_InValid(string statusString)
|
||||
{
|
||||
var successful = TvParserHelpers.TryParseSeriesStatus(statusString, out var parsered);
|
||||
Assert.False(successful);
|
||||
Assert.Null(parsered);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue