filter controls, default thumbnail, playlist search video removing

This commit is contained in:
2024-03-02 01:05:44 +01:00
Unverified
parent 9465be8d76
commit 17245bb91f
28 changed files with 352 additions and 71 deletions

View File

@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -71,6 +72,8 @@ namespace VDownload.Core.ViewModels.Home.Helpers
[ObservableProperty]
protected AudioExtension _audioExtension;
public Video Video { get; protected set; }
#endregion
@@ -82,6 +85,8 @@ namespace VDownload.Core.ViewModels.Home.Helpers
_settingsService = settingsService;
_storagePickerService = storagePickerService;
Video = video;
ThumbnailUrl = video.ThumbnailUrl;
Title = video.Title;
Author = video.Author;
@@ -104,6 +109,26 @@ namespace VDownload.Core.ViewModels.Home.Helpers
#region PUBLIC METHODS
public VideoDownloadOptions BuildDownloadOptions()
{
return new VideoDownloadOptions(Duration)
{
MediaType = this.MediaType,
SelectedStream = this.SelectedStream,
TrimStart = this.TrimStart,
TrimEnd = this.TrimEnd,
Directory = this.DirectoryPath,
Filename = string.Join("_", this.Filename.Split(Path.GetInvalidFileNameChars())),
Extension = (this.MediaType == MediaType.OnlyAudio ? this.AudioExtension.ToString() : this.VideoExtension.ToString()).ToLower(),
};
}
#endregion
#region COMMANDS
[RelayCommand]

View File

@@ -1,7 +1,9 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@@ -32,6 +34,8 @@ namespace VDownload.Core.ViewModels.Home
protected Playlist _playlist;
protected Dictionary<VideoViewModel, bool> _allVideos;
#endregion
@@ -44,6 +48,9 @@ namespace VDownload.Core.ViewModels.Home
[ObservableProperty]
protected ObservableCollection<VideoViewModel> _videos;
[ObservableProperty]
protected int _removedCount;
#endregion
@@ -56,6 +63,7 @@ namespace VDownload.Core.ViewModels.Home
_settingsService = settingsService;
_storagePickerService = storagePickerService;
_allVideos = new Dictionary<VideoViewModel, bool>();
_videos = new ObservableCollection<VideoViewModel>();
}
@@ -65,17 +73,19 @@ namespace VDownload.Core.ViewModels.Home
#region PUBLIC METHODS
public async Task LoadPlaylist(Playlist playlist)
public void LoadPlaylist(Playlist playlist)
{
_playlist = playlist;
Videos.Clear();
Name = _playlist.Name;
_allVideos.Clear();
foreach (Video video in playlist)
{
Videos.Add(new VideoViewModel(video, _settingsService, _storagePickerService));
_allVideos.Add(new VideoViewModel(video, _settingsService, _storagePickerService), false);
}
Name = _playlist.Name;
Videos = new ObservableCollection<VideoViewModel>(_allVideos.Keys);
RemovedCount = 0;
}
#endregion
@@ -84,7 +94,64 @@ namespace VDownload.Core.ViewModels.Home
#region COMMANDS
[RelayCommand]
public async Task SelectDirectory()
{
string? newDirectory = await _storagePickerService.OpenDirectory();
if (newDirectory is not null)
{
foreach (VideoViewModel video in _allVideos.Keys)
{
video.DirectoryPath = newDirectory;
}
}
}
[RelayCommand]
public void RemoveVideo(VideoViewModel video)
{
_allVideos[video] = true;
Videos.Remove(video);
RemovedCount = _allVideos.Where(x => x.Value).Count();
}
[RelayCommand]
public void RestoreRemovedVideos()
{
foreach(VideoViewModel video in _allVideos.Where(x => x.Value == true).Select(x => x.Key))
{
_allVideos[video] = false;
Videos.Add(video);
}
RemovedCount = _allVideos.Where(x => x.Value).Count();
}
[RelayCommand]
public void CreateTasksAndDownload() => CreateTasks(true);
[RelayCommand]
public void CreateTasks() => CreateTasks(false);
#endregion
#region PRIVATE METHODS
protected void CreateTasks(bool download)
{
foreach (VideoViewModel video in Videos)
{
DownloadTask task = _tasksManager.AddTask(video.Video, video.BuildDownloadOptions());
if (download)
{
task.Enqueue();
}
}
CloseRequested?.Invoke(this, EventArgs.Empty);
}
#endregion

View File

@@ -234,7 +234,7 @@ namespace VDownload.Core.ViewModels.Home
return;
}
await _playlistViewModel.LoadPlaylist(playlist);
_playlistViewModel.LoadPlaylist(playlist);
MainContent = _playlistView;