Updated Playlist

Updated code to filter out videos that have been removed from the
playlist, and insert new ones into the list in the Update() function.
This commit is contained in:
Mario Steele 2025-07-21 17:05:27 -05:00
parent 977b40c403
commit 561ba4f34a

View file

@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Query.Internal;
namespace FreeTubeSync.Model;
@ -18,7 +19,20 @@ public class Playlist
{
if (other.playlistName != playlistName) playlistName = other.playlistName;
if (other.@protected != @protected) @protected = other.@protected;
if (other.videos.Count != videos.Count) videos = other.videos;
var remove = new List<Video>();
foreach (var vid in videos)
{
if (other.videos.Any(x => x.playlistItemId == vid.playlistItemId)) continue;
remove.Add(vid);
}
videos.RemoveAll(x => remove.Contains(x));
remove.Clear();
foreach (var vid in other.videos)
{
if (videos.Any(x => x.playlistItemId == vid.playlistItemId)) continue;
remove.Add(vid);
}
videos.AddRange(remove);
if (other.createdAt != createdAt) createdAt = other.createdAt;
if (other.lastUpdatedAt != lastUpdatedAt) lastUpdatedAt = other.lastUpdatedAt;
}