From efdf0bb6d4062376b8b72fbde2bd6f3fd183ac43 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:13:13 -0500 Subject: [PATCH] group music videos by album (#1849) --- ErsatzTV.Core/Extensions/StringExtensions.cs | 23 +++++++++++++++++++ .../YamlPlayoutMarathonHelper.cs | 10 +++++++- .../Repositories/MediaCollectionRepository.cs | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 ErsatzTV.Core/Extensions/StringExtensions.cs diff --git a/ErsatzTV.Core/Extensions/StringExtensions.cs b/ErsatzTV.Core/Extensions/StringExtensions.cs new file mode 100644 index 00000000..b808bda1 --- /dev/null +++ b/ErsatzTV.Core/Extensions/StringExtensions.cs @@ -0,0 +1,23 @@ +namespace ErsatzTV.Core.Extensions; + +public static class StringExtensions +{ + public static int GetStableHashCode(this string str) + { + unchecked + { + int hash1 = 5381; + int hash2 = hash1; + + for (int i = 0; i < str.Length && str[i] != '\0'; i += 2) + { + hash1 = ((hash1 << 5) + hash1) ^ str[i]; + if (i == str.Length - 1 || str[i + 1] == '\0') + break; + hash2 = ((hash2 << 5) + hash2) ^ str[i + 1]; + } + + return hash1 + (hash2 * 1566083941); + } + } +} \ No newline at end of file diff --git a/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutMarathonHelper.cs b/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutMarathonHelper.cs index 22ae3906..2cd308db 100644 --- a/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutMarathonHelper.cs +++ b/ErsatzTV.Core/Scheduling/YamlScheduling/YamlPlayoutMarathonHelper.cs @@ -1,4 +1,5 @@ using ErsatzTV.Core.Domain; +using ErsatzTV.Core.Extensions; using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Core.Interfaces.Scheduling; using ErsatzTV.Core.Scheduling.YamlScheduling.Models; @@ -111,7 +112,14 @@ public class YamlPlayoutMarathonHelper(IMediaCollectionRepository mediaCollectio { Song s => new GroupKey( ProgramScheduleItemCollectionType.Collection, - s.SongMetadata.HeadOrNone().Map(sm => sm.Album.GetHashCode()).IfNone(0), + s.SongMetadata.HeadOrNone().Map(sm => sm.Album.GetStableHashCode()).IfNone(0), + null, + null, + null), + MusicVideo mv => new GroupKey( + ProgramScheduleItemCollectionType.Collection, + mv.MusicVideoMetadata.HeadOrNone() + .Map(mvm => $"{mv.ArtistId}-${mvm.Album}".GetStableHashCode()).IfNone(0), null, null, null), diff --git a/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs b/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs index 27b2a824..8b275a98 100644 --- a/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs +++ b/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs @@ -1069,6 +1069,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository .Include(m => m.Artist) .ThenInclude(a => a.ArtistMetadata) .Include(m => m.MusicVideoMetadata) + .ThenInclude(mvm => mvm.Artists) .Include(m => m.MediaVersions) .ThenInclude(mv => mv.Chapters) .Include(m => m.MediaVersions)