filter controls, default thumbnail, playlist search video removing
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace VDownload.Core.ViewModels.Home
|
||||
return;
|
||||
}
|
||||
|
||||
await _playlistViewModel.LoadPlaylist(playlist);
|
||||
_playlistViewModel.LoadPlaylist(playlist);
|
||||
|
||||
MainContent = _playlistView;
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.240211001" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="SimpleToolkit.UI.Models" Version="1.4.0" />
|
||||
<PackageReference Include="SimpleToolkit.UI.Models" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user