From 17245bb91fff6add9985199137b598f4b85dd1f2 Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Sat, 2 Mar 2024 01:05:44 +0100 Subject: [PATCH] filter controls, default thumbnail, playlist search video removing --- .../en-US/HomePlaylistViewResources.resw | 36 ++++ .../VDownload.Core.Strings.csproj | 4 +- .../VDownload.Core.Tasks/DownloadTask.cs | 2 +- .../Home/Helpers/VideoViewModel.cs | 25 +++ .../Home/HomePlaylistViewModel.cs | 77 ++++++++- .../Home/HomeViewModel.cs | 2 +- .../VDownload.Core.ViewModels.csproj | 6 +- .../Home/HomeDownloadsView.xaml | 2 +- .../Home/HomePlaylistView.xaml | 156 +++++++++++++++--- .../Home/HomeVideoView.xaml | 2 +- .../VDownload.Core.Views.csproj | 9 +- VDownload.Models/Video.cs | 2 +- .../VDownload.Services.UI.Dialogs.csproj | 4 +- ...oad.Services.UI.DictionaryResources.csproj | 4 +- ...VDownload.Services.UI.Notifications.csproj | 4 +- ...VDownload.Services.UI.StoragePicker.csproj | 4 +- ...ownload.Services.UI.StringResources.csproj | 4 +- .../VDownload.Services.UI.WebView.csproj | 4 +- .../Models/Download.cs | 2 +- .../Models/DownloadVod.cs | 18 ++ .../Models/Search.cs | 2 +- .../Models/{Vod.cs => SearchVod.cs} | 11 +- .../TwitchSearchService.cs | 20 ++- VDownload/App.xaml | 1 + VDownload/Assets/Other/Thumbnail.png | Bin 0 -> 1250535 bytes .../Dictionaries/Images/ImagesOther.xaml | 6 + VDownload/VDownload.csproj | 15 +- VDownload/configuration.json | 1 + 28 files changed, 352 insertions(+), 71 deletions(-) create mode 100644 VDownload.Sources/VDownload.Sources.Twitch/VDownload.Sources.Twitch.Configuration/Models/DownloadVod.cs rename VDownload.Sources/VDownload.Sources.Twitch/VDownload.Sources.Twitch.Configuration/Models/{Vod.cs => SearchVod.cs} (67%) create mode 100644 VDownload/Assets/Other/Thumbnail.png create mode 100644 VDownload/Dictionaries/Images/ImagesOther.xaml diff --git a/VDownload.Core/VDownload.Core.Strings/Strings/en-US/HomePlaylistViewResources.resw b/VDownload.Core/VDownload.Core.Strings/Strings/en-US/HomePlaylistViewResources.resw index 0973f04..2eb1753 100644 --- a/VDownload.Core/VDownload.Core.Strings/Strings/en-US/HomePlaylistViewResources.resw +++ b/VDownload.Core/VDownload.Core.Strings/Strings/en-US/HomePlaylistViewResources.resw @@ -117,6 +117,15 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Selected directory will be applied to all videos in playlist + + + Create download tasks and start + + + Create download tasks + Directory @@ -135,6 +144,33 @@ File type + + Author + + + Enter regular expression + + + Date + + + Duration + + + Restore + + + Removed + + + Title + + + Enter regular expression + + + Views + Filter diff --git a/VDownload.Core/VDownload.Core.Strings/VDownload.Core.Strings.csproj b/VDownload.Core/VDownload.Core.Strings/VDownload.Core.Strings.csproj index 0b0aa2a..7a200cb 100644 --- a/VDownload.Core/VDownload.Core.Strings/VDownload.Core.Strings.csproj +++ b/VDownload.Core/VDownload.Core.Strings/VDownload.Core.Strings.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/VDownload.Core/VDownload.Core.Tasks/DownloadTask.cs b/VDownload.Core/VDownload.Core.Tasks/DownloadTask.cs index bd7293e..15b82f1 100644 --- a/VDownload.Core/VDownload.Core.Tasks/DownloadTask.cs +++ b/VDownload.Core/VDownload.Core.Tasks/DownloadTask.cs @@ -140,7 +140,7 @@ namespace VDownload.Core.Tasks await _settingsService.Load(); - string tempDirectory = $"{_settingsService.Data.Common.Temp.Directory}\\{_configurationService.Common.Path.Temp.TasksDirectory}\\{_id}"; + string tempDirectory = $"{_settingsService.Data.Common.Temp.Directory}\\{_configurationService.Common.Path.Temp.TasksDirectory}\\{Id}"; Directory.CreateDirectory(tempDirectory); List content = new List() diff --git a/VDownload.Core/VDownload.Core.ViewModels/Home/Helpers/VideoViewModel.cs b/VDownload.Core/VDownload.Core.ViewModels/Home/Helpers/VideoViewModel.cs index 380a4ae..513cb3e 100644 --- a/VDownload.Core/VDownload.Core.ViewModels/Home/Helpers/VideoViewModel.cs +++ b/VDownload.Core/VDownload.Core.ViewModels/Home/Helpers/VideoViewModel.cs @@ -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] diff --git a/VDownload.Core/VDownload.Core.ViewModels/Home/HomePlaylistViewModel.cs b/VDownload.Core/VDownload.Core.ViewModels/Home/HomePlaylistViewModel.cs index c705040..f8b137d 100644 --- a/VDownload.Core/VDownload.Core.ViewModels/Home/HomePlaylistViewModel.cs +++ b/VDownload.Core/VDownload.Core.ViewModels/Home/HomePlaylistViewModel.cs @@ -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 _allVideos; + #endregion @@ -44,6 +48,9 @@ namespace VDownload.Core.ViewModels.Home [ObservableProperty] protected ObservableCollection _videos; + [ObservableProperty] + protected int _removedCount; + #endregion @@ -56,6 +63,7 @@ namespace VDownload.Core.ViewModels.Home _settingsService = settingsService; _storagePickerService = storagePickerService; + _allVideos = new Dictionary(); _videos = new ObservableCollection(); } @@ -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(_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 diff --git a/VDownload.Core/VDownload.Core.ViewModels/Home/HomeViewModel.cs b/VDownload.Core/VDownload.Core.ViewModels/Home/HomeViewModel.cs index 55e2944..c6b8fcc 100644 --- a/VDownload.Core/VDownload.Core.ViewModels/Home/HomeViewModel.cs +++ b/VDownload.Core/VDownload.Core.ViewModels/Home/HomeViewModel.cs @@ -234,7 +234,7 @@ namespace VDownload.Core.ViewModels.Home return; } - await _playlistViewModel.LoadPlaylist(playlist); + _playlistViewModel.LoadPlaylist(playlist); MainContent = _playlistView; diff --git a/VDownload.Core/VDownload.Core.ViewModels/VDownload.Core.ViewModels.csproj b/VDownload.Core/VDownload.Core.ViewModels/VDownload.Core.ViewModels.csproj index 5118828..db183b6 100644 --- a/VDownload.Core/VDownload.Core.ViewModels/VDownload.Core.ViewModels.csproj +++ b/VDownload.Core/VDownload.Core.ViewModels/VDownload.Core.ViewModels.csproj @@ -10,10 +10,10 @@ - - + + - + diff --git a/VDownload.Core/VDownload.Core.Views/Home/HomeDownloadsView.xaml b/VDownload.Core/VDownload.Core.Views/Home/HomeDownloadsView.xaml index e7d0345..911e767 100644 --- a/VDownload.Core/VDownload.Core.Views/Home/HomeDownloadsView.xaml +++ b/VDownload.Core/VDownload.Core.Views/Home/HomeDownloadsView.xaml @@ -46,7 +46,7 @@ + Background="{ThemeResource ViewBackgroundColor}" + x:Name="Root"> @@ -27,7 +28,6 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +