2022-05-05 15:14:26 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2022-05-11 20:50:50 +02:00
|
|
|
|
using System.Threading;
|
2022-05-05 15:14:26 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using VDownload.Core.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace VDownload.Core.Services
|
|
|
|
|
|
{
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
|
public class Subscription
|
|
|
|
|
|
{
|
|
|
|
|
|
#region CONSTRUCTORS
|
|
|
|
|
|
|
|
|
|
|
|
public Subscription(IPlaylist playlist)
|
|
|
|
|
|
{
|
|
|
|
|
|
Playlist = playlist;
|
|
|
|
|
|
SavedVideos = Playlist.Videos;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PROPERTIES
|
|
|
|
|
|
|
|
|
|
|
|
public IPlaylist Playlist { get; private set; }
|
|
|
|
|
|
public IVideo[] SavedVideos { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PUBLIC METHODS
|
|
|
|
|
|
|
2022-05-11 20:50:50 +02:00
|
|
|
|
public async Task<IVideo[]> GetNewVideosAsync(CancellationToken cancellationToken = default)
|
2022-05-05 15:14:26 +02:00
|
|
|
|
{
|
2022-05-11 20:50:50 +02:00
|
|
|
|
await Playlist.GetVideosAsync(cancellationToken);
|
2022-05-05 15:14:26 +02:00
|
|
|
|
return GetUnsavedVideos();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-11 20:50:50 +02:00
|
|
|
|
public async Task<IVideo[]> GetNewVideosAndUpdateAsync(CancellationToken cancellationToken = default)
|
2022-05-05 15:14:26 +02:00
|
|
|
|
{
|
2022-05-11 20:50:50 +02:00
|
|
|
|
await Playlist.GetVideosAsync(cancellationToken);
|
2022-05-05 15:14:26 +02:00
|
|
|
|
IVideo[] newVideos = GetUnsavedVideos();
|
|
|
|
|
|
SavedVideos = Playlist.Videos;
|
|
|
|
|
|
return newVideos;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PRIVATE METHODS
|
|
|
|
|
|
|
|
|
|
|
|
private IVideo[] GetUnsavedVideos()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<IVideo> newVideos = Playlist.Videos.ToList();
|
|
|
|
|
|
foreach (IVideo savedVideo in SavedVideos)
|
|
|
|
|
|
{
|
|
|
|
|
|
newVideos.RemoveAll((v) => v.Source == savedVideo.Source && v.ID == savedVideo.ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
return newVideos.ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|