Browse Source

support filling with groups of song artists (#1537)

pull/1540/head
Jason Dove 2 years ago committed by GitHub
parent
commit
6708d6b4d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      ErsatzTV.Core/Domain/PlayoutProgramScheduleAnchor.cs
  2. 1
      ErsatzTV.Core/Domain/ProgramScheduleItem.cs
  3. 4
      ErsatzTV.Core/Domain/ProgramScheduleItemCollectionType.cs
  4. 6
      ErsatzTV.Core/Scheduling/CollectionKey.cs
  5. 1
      ErsatzTV.Core/Scheduling/CollectionWithItems.cs
  6. 42
      ErsatzTV.Core/Scheduling/PlayoutBuilder.cs
  7. 4527
      ErsatzTV.Infrastructure.MySql/Migrations/20240105162621_AddFakeCollectionGroup.Designer.cs
  8. 40
      ErsatzTV.Infrastructure.MySql/Migrations/20240105162621_AddFakeCollectionGroup.cs
  9. 8
      ErsatzTV.Infrastructure.MySql/Migrations/TvContextModelSnapshot.cs
  10. 4525
      ErsatzTV.Infrastructure.Sqlite/Migrations/20240105161014_AddFakeCollectionGroup.Designer.cs
  11. 38
      ErsatzTV.Infrastructure.Sqlite/Migrations/20240105161014_AddFakeCollectionGroup.cs
  12. 8
      ErsatzTV.Infrastructure.Sqlite/Migrations/TvContextModelSnapshot.cs
  13. 10
      ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs

1
ErsatzTV.Core/Domain/PlayoutProgramScheduleAnchor.cs

@ -25,5 +25,6 @@ public class PlayoutProgramScheduleAnchor @@ -25,5 +25,6 @@ public class PlayoutProgramScheduleAnchor
public SmartCollection SmartCollection { get; set; }
public int? MediaItemId { get; set; }
public MediaItem MediaItem { get; set; }
public string FakeCollectionKey { get; set; }
public CollectionEnumeratorState EnumeratorState { get; set; }
}

1
ErsatzTV.Core/Domain/ProgramScheduleItem.cs

@ -25,6 +25,7 @@ public abstract class ProgramScheduleItem @@ -25,6 +25,7 @@ public abstract class ProgramScheduleItem
public MultiCollection MultiCollection { get; set; }
public int? SmartCollectionId { get; set; }
public SmartCollection SmartCollection { get; set; }
public string FakeCollectionKey { get; set; }
public PlaybackOrder PlaybackOrder { get; set; }
public int? PreRollFillerId { get; set; }
public FillerPreset PreRollFiller { get; set; }

4
ErsatzTV.Core/Domain/ProgramScheduleItemCollectionType.cs

@ -7,5 +7,7 @@ public enum ProgramScheduleItemCollectionType @@ -7,5 +7,7 @@ public enum ProgramScheduleItemCollectionType
TelevisionSeason = 2,
Artist = 3,
MultiCollection = 4,
SmartCollection = 5
SmartCollection = 5,
FakeCollection = 100
}

6
ErsatzTV.Core/Scheduling/CollectionKey.cs

@ -10,6 +10,7 @@ public class CollectionKey : Record<CollectionKey> @@ -10,6 +10,7 @@ public class CollectionKey : Record<CollectionKey>
public int? MultiCollectionId { get; set; }
public int? SmartCollectionId { get; set; }
public int? MediaItemId { get; set; }
public string FakeCollectionKey { get; set; }
public static CollectionKey ForScheduleItem(ProgramScheduleItem item) =>
item.CollectionType switch
@ -44,6 +45,11 @@ public class CollectionKey : Record<CollectionKey> @@ -44,6 +45,11 @@ public class CollectionKey : Record<CollectionKey>
CollectionType = item.CollectionType,
SmartCollectionId = item.SmartCollectionId
},
ProgramScheduleItemCollectionType.FakeCollection => new CollectionKey
{
CollectionType = item.CollectionType,
FakeCollectionKey = item.FakeCollectionKey
},
_ => throw new ArgumentOutOfRangeException(nameof(item))
};

1
ErsatzTV.Core/Scheduling/CollectionWithItems.cs

@ -5,6 +5,7 @@ namespace ErsatzTV.Core.Scheduling; @@ -5,6 +5,7 @@ namespace ErsatzTV.Core.Scheduling;
public record CollectionWithItems(
int ShowId,
int ArtistId,
string Key,
List<MediaItem> MediaItems,
bool ScheduleAsGroup,
PlaybackOrder PlaybackOrder,

42
ErsatzTV.Core/Scheduling/PlayoutBuilder.cs

@ -438,10 +438,9 @@ public class PlayoutBuilder : IPlayoutBuilder @@ -438,10 +438,9 @@ public class PlayoutBuilder : IPlayoutBuilder
_artistRepository,
collectionKey);
var fakeCollections = _mediaCollectionRepository.GroupIntoFakeCollections(mediaItems)
.Filter(c => c.ShowId > 0 || c.ArtistId > 0)
.Filter(c => c.ShowId > 0 || c.ArtistId > 0 || !string.IsNullOrWhiteSpace(c.Key))
.ToList();
List<ProgramScheduleItem> fakeScheduleItems = []
;
List<ProgramScheduleItem> fakeScheduleItems = [];
// this will be used to clone a schedule item
MethodInfo generic = typeof(JsonConvert).GetMethods()
@ -451,18 +450,36 @@ public class PlayoutBuilder : IPlayoutBuilder @@ -451,18 +450,36 @@ public class PlayoutBuilder : IPlayoutBuilder
foreach (CollectionWithItems fakeCollection in fakeCollections)
{
var key = new CollectionKey
CollectionKey key = (fakeCollection.ShowId, fakeCollection.ArtistId, fakeCollection.Key) switch
{
CollectionType = fakeCollection.ShowId > 0
? ProgramScheduleItemCollectionType.TelevisionShow
: ProgramScheduleItemCollectionType.Artist,
MediaItemId = fakeCollection.ShowId > 0 ? fakeCollection.ShowId : fakeCollection.ArtistId
var (showId, _, _) when showId > 0 => new CollectionKey
{
CollectionType = ProgramScheduleItemCollectionType.TelevisionShow,
MediaItemId = showId
},
var (_, artistId, _) when artistId > 0 => new CollectionKey
{
CollectionType = ProgramScheduleItemCollectionType.Artist,
MediaItemId = artistId
},
var (_, _, k) when k is not null => new CollectionKey
{
CollectionType = ProgramScheduleItemCollectionType.FakeCollection,
FakeCollectionKey = k
},
var (_, _, _) => null
};
if (key is null)
{
continue;
}
string serialized = JsonConvert.SerializeObject(scheduleItem);
var copyScheduleItem = generic.Invoke(this, [serialized]) as ProgramScheduleItem;
copyScheduleItem.CollectionType = key.CollectionType;
copyScheduleItem.MediaItemId = key.MediaItemId;
copyScheduleItem.FakeCollectionKey = key.FakeCollectionKey;
fakeScheduleItems.Add(copyScheduleItem);
IMediaCollectionEnumerator enumerator = await GetMediaCollectionEnumerator(
@ -669,11 +686,7 @@ public class PlayoutBuilder : IPlayoutBuilder @@ -669,11 +686,7 @@ public class PlayoutBuilder : IPlayoutBuilder
}
// build program schedule anchors
playout.ProgramScheduleAnchors = BuildProgramScheduleAnchors(
playout,
activeSchedule,
collectionEnumerators,
saveAnchorDate);
playout.ProgramScheduleAnchors = BuildProgramScheduleAnchors(playout, collectionEnumerators, saveAnchorDate);
// build fill group indices
playout.FillGroupIndices = BuildFillGroupIndices(playout, scheduleItemsFillGroupEnumerators);
@ -817,7 +830,6 @@ public class PlayoutBuilder : IPlayoutBuilder @@ -817,7 +830,6 @@ public class PlayoutBuilder : IPlayoutBuilder
private static List<PlayoutProgramScheduleAnchor> BuildProgramScheduleAnchors(
Playout playout,
ProgramSchedule activeSchedule,
Dictionary<CollectionKey, IMediaCollectionEnumerator> collectionEnumerators,
bool saveAnchorDate)
{
@ -829,6 +841,7 @@ public class PlayoutBuilder : IPlayoutBuilder @@ -829,6 +841,7 @@ public class PlayoutBuilder : IPlayoutBuilder
a => a.CollectionType == collectionKey.CollectionType
&& a.CollectionId == collectionKey.CollectionId
&& a.MediaItemId == collectionKey.MediaItemId
&& a.FakeCollectionKey == collectionKey.FakeCollectionKey
&& a.SmartCollectionId == collectionKey.SmartCollectionId
&& a.MultiCollectionId == collectionKey.MultiCollectionId
&& a.AnchorDate is null);
@ -850,6 +863,7 @@ public class PlayoutBuilder : IPlayoutBuilder @@ -850,6 +863,7 @@ public class PlayoutBuilder : IPlayoutBuilder
MultiCollectionId = collectionKey.MultiCollectionId,
SmartCollectionId = collectionKey.SmartCollectionId,
MediaItemId = collectionKey.MediaItemId,
FakeCollectionKey = collectionKey.FakeCollectionKey,
EnumeratorState = maybeEnumeratorState[collectionKey]
});

4527
ErsatzTV.Infrastructure.MySql/Migrations/20240105162621_AddFakeCollectionGroup.Designer.cs generated

File diff suppressed because it is too large Load Diff

40
ErsatzTV.Infrastructure.MySql/Migrations/20240105162621_AddFakeCollectionGroup.cs

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.MySql.Migrations
{
/// <inheritdoc />
public partial class AddFakeCollectionGroup : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "FakeCollectionKey",
table: "ProgramScheduleItem",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "FakeCollectionKey",
table: "PlayoutProgramScheduleAnchor",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FakeCollectionKey",
table: "ProgramScheduleItem");
migrationBuilder.DropColumn(
name: "FakeCollectionKey",
table: "PlayoutProgramScheduleAnchor");
}
}
}

8
ErsatzTV.Infrastructure.MySql/Migrations/TvContextModelSnapshot.cs

@ -16,7 +16,7 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations @@ -16,7 +16,7 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.14")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("ErsatzTV.Core.Domain.Actor", b =>
@ -1511,6 +1511,9 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations @@ -1511,6 +1511,9 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations
b.Property<int>("CollectionType")
.HasColumnType("int");
b.Property<string>("FakeCollectionKey")
.HasColumnType("longtext");
b.Property<int?>("MediaItemId")
.HasColumnType("int");
@ -1700,6 +1703,9 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations @@ -1700,6 +1703,9 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations
b.Property<string>("CustomTitle")
.HasColumnType("longtext");
b.Property<string>("FakeCollectionKey")
.HasColumnType("longtext");
b.Property<int?>("FallbackFillerId")
.HasColumnType("int");

4525
ErsatzTV.Infrastructure.Sqlite/Migrations/20240105161014_AddFakeCollectionGroup.Designer.cs generated

File diff suppressed because it is too large Load Diff

38
ErsatzTV.Infrastructure.Sqlite/Migrations/20240105161014_AddFakeCollectionGroup.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.Sqlite.Migrations
{
/// <inheritdoc />
public partial class AddFakeCollectionGroup : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "FakeCollectionKey",
table: "ProgramScheduleItem",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "FakeCollectionKey",
table: "PlayoutProgramScheduleAnchor",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FakeCollectionKey",
table: "ProgramScheduleItem");
migrationBuilder.DropColumn(
name: "FakeCollectionKey",
table: "PlayoutProgramScheduleAnchor");
}
}
}

8
ErsatzTV.Infrastructure.Sqlite/Migrations/TvContextModelSnapshot.cs

@ -15,7 +15,7 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations @@ -15,7 +15,7 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.14");
modelBuilder.HasAnnotation("ProductVersion", "8.0.0");
modelBuilder.Entity("ErsatzTV.Core.Domain.Actor", b =>
{
@ -1509,6 +1509,9 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations @@ -1509,6 +1509,9 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations
b.Property<int>("CollectionType")
.HasColumnType("INTEGER");
b.Property<string>("FakeCollectionKey")
.HasColumnType("TEXT");
b.Property<int?>("MediaItemId")
.HasColumnType("INTEGER");
@ -1698,6 +1701,9 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations @@ -1698,6 +1701,9 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations
b.Property<string>("CustomTitle")
.HasColumnType("TEXT");
b.Property<string>("FakeCollectionKey")
.HasColumnType("TEXT");
b.Property<int?>("FallbackFillerId")
.HasColumnType("INTEGER");

10
ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs

@ -190,6 +190,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -190,6 +190,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository
new CollectionWithItems(
multiCollectionItem.CollectionId,
multiCollectionItem.CollectionId,
null,
sortedItems,
multiCollectionItem.ScheduleAsGroup,
multiCollectionItem.PlaybackOrder,
@ -202,6 +203,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -202,6 +203,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository
new CollectionWithItems(
multiCollectionItem.CollectionId,
multiCollectionItem.CollectionId,
null,
items,
multiCollectionItem.ScheduleAsGroup,
multiCollectionItem.PlaybackOrder,
@ -217,6 +219,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -217,6 +219,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository
new CollectionWithItems(
multiCollectionSmartItem.SmartCollectionId,
multiCollectionSmartItem.SmartCollectionId,
null,
items,
multiCollectionSmartItem.ScheduleAsGroup,
multiCollectionSmartItem.PlaybackOrder,
@ -357,6 +360,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -357,6 +360,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository
new CollectionWithItems(
showId,
0,
null,
list,
true,
PlaybackOrder.Chronological,
@ -384,6 +388,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -384,6 +388,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository
new CollectionWithItems(
0,
artistId,
null,
list,
true,
PlaybackOrder.Chronological,
@ -418,12 +423,13 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -418,12 +423,13 @@ public class MediaCollectionRepository : IMediaCollectionRepository
songArtistCollections[key] = list;
}
foreach ((int _, List<MediaItem> list) in songArtistCollections)
foreach ((int index, List<MediaItem> list) in songArtistCollections)
{
result.Add(
new CollectionWithItems(
id,
id,
allArtists[index],
list,
true,
PlaybackOrder.Chronological,
@ -436,6 +442,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -436,6 +442,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository
new CollectionWithItems(
id,
id,
null,
items.OfType<Movie>().Cast<MediaItem>().ToList(),
true,
PlaybackOrder.Chronological,
@ -446,6 +453,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository @@ -446,6 +453,7 @@ public class MediaCollectionRepository : IMediaCollectionRepository
new CollectionWithItems(
id,
id,
null,
items.OfType<OtherVideo>().Cast<MediaItem>().ToList(),
true,
PlaybackOrder.Chronological,

Loading…
Cancel
Save