Fix: support Emby >= 4.8.0.57 (#240)

* by replacing sorting extensions for Emby
* reformat and clean up code
This commit is contained in:
Jason Lyu
2023-12-01 04:47:09 +08:00
committed by GitHub
parent 5a1b93479d
commit f79c707ea8
3 changed files with 128 additions and 17 deletions

View File

@@ -1,4 +1,6 @@
#if __EMBY__
using System.Text;
using MediaBrowser.Model.Logging;
namespace Jellyfin.Plugin.MetaTube.Extensions;
@@ -13,6 +15,115 @@ public static class EmbyExtensions
}
#endregion
#region Sorting
public static IEnumerable<T> OrderByString<T>(this IEnumerable<T> list, Func<T, string> getName)
{
return list.OrderBy(getName, new AlphanumComparator());
}
public static IEnumerable<T> OrderByStringDescending<T>(
this IEnumerable<T> list,
Func<T, string> getName)
{
return list.OrderByDescending(getName, new AlphanumComparator());
}
public static IOrderedEnumerable<T> ThenByString<T>(
this IOrderedEnumerable<T> list,
Func<T, string> getName)
{
return list.ThenBy(getName, new AlphanumComparator());
}
public static IOrderedEnumerable<T> ThenByStringDescending<T>(
this IOrderedEnumerable<T> list,
Func<T, string> getName)
{
return list.ThenByDescending(getName, new AlphanumComparator());
}
private sealed class AlphanumComparator : IComparer<string>
{
public int Compare(string x, string y)
{
return CompareValues(x, y);
}
private static bool InChunk(char ch, char otherCh)
{
var chunkType = ChunkType.Alphanumeric;
if (char.IsDigit(otherCh))
chunkType = ChunkType.Numeric;
return (chunkType != ChunkType.Alphanumeric || !char.IsDigit(ch)) &&
(chunkType != ChunkType.Numeric || char.IsDigit(ch));
}
private static int CompareValues(string s1, string s2)
{
if (s1 == null || s2 == null)
return 0;
var index1 = 0;
var index2 = 0;
while (index1 < s1.Length || index2 < s2.Length)
{
if (index1 >= s1.Length)
return -1;
if (index2 >= s2.Length)
return 1;
var ch1 = s1[index1];
var ch2 = s2[index2];
var stringBuilder1 = new StringBuilder();
var stringBuilder2 = new StringBuilder();
while (index1 < s1.Length && (stringBuilder1.Length == 0 || InChunk(ch1, stringBuilder1[0])))
{
stringBuilder1.Append(ch1);
++index1;
if (index1 < s1.Length)
ch1 = s1[index1];
}
while (index2 < s2.Length && (stringBuilder2.Length == 0 || InChunk(ch2, stringBuilder2[0])))
{
stringBuilder2.Append(ch2);
++index2;
if (index2 < s2.Length)
ch2 = s2[index2];
}
var num = 0;
if (char.IsDigit(stringBuilder1[0]) && char.IsDigit(stringBuilder2[0]))
{
if (!int.TryParse(stringBuilder1.ToString(), out var result1) ||
!int.TryParse(stringBuilder2.ToString(), out var result2))
return 0;
if (result1 < result2)
num = -1;
if (result1 > result2)
num = 1;
}
else
{
num = string.Compare(stringBuilder1.ToString(), stringBuilder2.ToString(),
StringComparison.CurrentCulture);
}
if (num != 0)
return num;
}
return 0;
}
private enum ChunkType
{
Alphanumeric,
Numeric
}
}
#endregion
}
#endif

View File

@@ -25,39 +25,39 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Memory" Version="4.5.5"/>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug' or '$(Configuration)'=='Release'">
<PackageReference Include="Jellyfin.Controller" Version="10.8.0" />
<PackageReference Include="Jellyfin.Model" Version="10.8.0" />
<PackageReference Include="Jellyfin.Controller" Version="10.8.0"/>
<PackageReference Include="Jellyfin.Model" Version="10.8.0"/>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug.Emby' or '$(Configuration)'=='Release.Emby'">
<PackageReference Include="MediaBrowser.Server.Core" Version="4.7.1" />
<PackageReference Include="MediaBrowser.Server.Core" Version="4.7.1"/>
</ItemGroup>
<ItemGroup>
<None Remove="Configuration\configPage.html" />
<EmbeddedResource Include="Configuration\configPage.html" />
<None Remove="Configuration\configPage.html"/>
<EmbeddedResource Include="Configuration\configPage.html"/>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug.Emby' or '$(Configuration)'=='Release.Emby'">
<None Remove="thumb.png" />
<EmbeddedResource Include="thumb.png" />
<None Remove="thumb.png"/>
<EmbeddedResource Include="thumb.png"/>
</ItemGroup>
<Target Name="Zip" AfterTargets="PostBuildEvent" Condition="'$(Configuration)'=='Release' or '$(Configuration)'=='Release.Emby'">
<ItemGroup>
<FilesToDelete Include="$(BaseOutputPath)Jellyfin.MetaTube*.zip" Condition="'$(Configuration)'=='Release'" />
<FilesToDelete Include="$(BaseOutputPath)Emby.MetaTube*.zip" Condition="'$(Configuration)'=='Release.Emby'" />
<TempZipDirectory Include="$(OutputPath)output" />
<FilesToDelete Include="$(BaseOutputPath)Jellyfin.MetaTube*.zip" Condition="'$(Configuration)'=='Release'"/>
<FilesToDelete Include="$(BaseOutputPath)Emby.MetaTube*.zip" Condition="'$(Configuration)'=='Release.Emby'"/>
<TempZipDirectory Include="$(OutputPath)output"/>
</ItemGroup>
<Delete Files="@(FilesToDelete)" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="@(TempZipDirectory)" />
<ZipDirectory SourceDirectory="@(TempZipDirectory)" DestinationFile="$(BaseOutputPath)Jellyfin.MetaTube@v$(Version).zip" Condition="'$(Configuration)'=='Release'" />
<ZipDirectory SourceDirectory="@(TempZipDirectory)" DestinationFile="$(BaseOutputPath)Emby.MetaTube@v$(Version).zip" Condition="'$(Configuration)'=='Release.Emby'" />
<RemoveDir Directories="@(TempZipDirectory)" />
<Delete Files="@(FilesToDelete)"/>
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="@(TempZipDirectory)"/>
<ZipDirectory SourceDirectory="@(TempZipDirectory)" DestinationFile="$(BaseOutputPath)Jellyfin.MetaTube@v$(Version).zip" Condition="'$(Configuration)'=='Release'"/>
<ZipDirectory SourceDirectory="@(TempZipDirectory)" DestinationFile="$(BaseOutputPath)Emby.MetaTube@v$(Version).zip" Condition="'$(Configuration)'=='Release.Emby'"/>
<RemoveDir Directories="@(TempZipDirectory)"/>
</Target>
</Project>

View File

@@ -2,7 +2,6 @@ using System.Text.RegularExpressions;
using Jellyfin.Plugin.MetaTube.Extensions;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Tasks;
#if __EMBY__
@@ -10,6 +9,7 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Model.Logging;
#else
using MediaBrowser.Controller.Sorting;
using Microsoft.Extensions.Logging;
using Jellyfin.Data.Enums;
#endif