freetubesync/FreeTubeSync/Model/Playlist.cs
Mario Steele 561ba4f34a 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.
2025-07-21 17:05:27 -05:00

39 lines
No EOL
1.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.Query.Internal;
namespace FreeTubeSync.Model;
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class Playlist
{
[Key]
public string _id { get; set; } = string.Empty;
public string playlistName { get; set; } = string.Empty;
public bool @protected { get; set; }
public List<Video> videos { get; set; } = [];
public long createdAt { get; set; }
public long lastUpdatedAt { get; set; }
public void Update(Playlist other)
{
if (other.playlistName != playlistName) playlistName = other.playlistName;
if (other.@protected != @protected) @protected = other.@protected;
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;
}
}