twitch vod downloading done
ffmpeg essentials fix Project reorganized git lfs ffmpeg removed ffmpeg added
This commit is contained in:
248
VDownload.Core/VDownload.Core.ViewModels/Home/HomeViewModel.cs
Normal file
248
VDownload.Core/VDownload.Core.ViewModels/Home/HomeViewModel.cs
Normal file
@@ -0,0 +1,248 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Models;
|
||||
using VDownload.Services.Data.Configuration;
|
||||
using VDownload.Services.Data.Settings;
|
||||
using VDownload.Services.UI.StringResources;
|
||||
using VDownload.Sources;
|
||||
using VDownload.Sources.Common;
|
||||
|
||||
namespace VDownload.Core.ViewModels.Home
|
||||
{
|
||||
public partial class HomeViewModel : ObservableObject
|
||||
{
|
||||
#region ENUMS
|
||||
|
||||
public enum OptionBarContentType
|
||||
{
|
||||
None,
|
||||
VideoSearch,
|
||||
PlaylistSearch
|
||||
}
|
||||
|
||||
public enum MainContentType
|
||||
{
|
||||
Downloads,
|
||||
Video
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region SERVICES
|
||||
|
||||
protected readonly IConfigurationService _configurationService;
|
||||
protected readonly ISettingsService _settingsService;
|
||||
protected readonly IStringResourcesService _stringResourcesService;
|
||||
protected readonly ISearchService _searchService;
|
||||
|
||||
protected readonly HomeVideoViewModel _videoViewModel;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
protected readonly Type _downloadsView = typeof(HomeDownloadsViewModel);
|
||||
protected readonly Type _videoView = typeof(HomeVideoViewModel);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PROPERTIES
|
||||
|
||||
[ObservableProperty]
|
||||
private Type _mainContent;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private OptionBarContentType _optionBarContent;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _optionBarMessage;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _optionBarLoading;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _optionBarVideoSearchButtonChecked;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _optionBarPlaylistSearchButtonChecked;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _optionBarSearchNotPending;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _optionBarVideoSearchTBValue;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _optionBarPlaylistSearchTBValue;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _optionBarPlaylistSearchNBValue;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public HomeViewModel(IConfigurationService configurationService, ISettingsService settingsService, IStringResourcesService stringResourcesService, ISearchService searchService, HomeVideoViewModel videoViewModel)
|
||||
{
|
||||
_configurationService = configurationService;
|
||||
_settingsService = settingsService;
|
||||
_stringResourcesService = stringResourcesService;
|
||||
_searchService = searchService;
|
||||
|
||||
_videoViewModel = videoViewModel;
|
||||
_videoViewModel.TaskAdded += VideoViewModel_TaskAdded;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region COMMANDS
|
||||
|
||||
[RelayCommand]
|
||||
public async Task Navigation()
|
||||
{
|
||||
await _settingsService.Load();
|
||||
|
||||
MainContent = _downloadsView;
|
||||
|
||||
OptionBarContent = OptionBarContentType.None;
|
||||
OptionBarMessage = null;
|
||||
OptionBarVideoSearchButtonChecked = false;
|
||||
OptionBarPlaylistSearchButtonChecked = false;
|
||||
OptionBarSearchNotPending = true;
|
||||
OptionBarVideoSearchTBValue = string.Empty;
|
||||
OptionBarPlaylistSearchNBValue = _settingsService.Data.Common.MaxNumberOfVideosToGetFromPlaylist;
|
||||
OptionBarPlaylistSearchTBValue = string.Empty;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void LoadFromSubscription()
|
||||
{
|
||||
MainContent = _downloadsView;
|
||||
|
||||
OptionBarContent = OptionBarContentType.None;
|
||||
OptionBarVideoSearchButtonChecked = false;
|
||||
OptionBarPlaylistSearchButtonChecked = false;
|
||||
OptionBarSearchNotPending = false;
|
||||
|
||||
//TODO: Load videos
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void VideoSearchShow()
|
||||
{
|
||||
MainContent = _downloadsView;
|
||||
|
||||
if (OptionBarContent != OptionBarContentType.VideoSearch)
|
||||
{
|
||||
OptionBarContent = OptionBarContentType.VideoSearch;
|
||||
OptionBarPlaylistSearchButtonChecked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
OptionBarContent = OptionBarContentType.None;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void PlaylistSearchShow()
|
||||
{
|
||||
MainContent = _downloadsView;
|
||||
|
||||
if (OptionBarContent != OptionBarContentType.PlaylistSearch)
|
||||
{
|
||||
OptionBarContent = OptionBarContentType.PlaylistSearch;
|
||||
OptionBarVideoSearchButtonChecked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
OptionBarContent = OptionBarContentType.None;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task VideoSearchStart()
|
||||
{
|
||||
OptionBarSearchNotPending = false;
|
||||
OptionBarLoading = true;
|
||||
OptionBarMessage = _stringResourcesService.HomeViewResources.Get("OptionBarMessageLoading");
|
||||
|
||||
Video video;
|
||||
try
|
||||
{
|
||||
video = await _searchService.SearchVideo(OptionBarVideoSearchTBValue);
|
||||
}
|
||||
catch (MediaSearchException ex)
|
||||
{
|
||||
OptionBarLoading = false;
|
||||
OptionBarMessage = ex.Message;
|
||||
OptionBarSearchNotPending = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_videoViewModel.LoadVideo(video);
|
||||
|
||||
MainContent = _videoView;
|
||||
|
||||
OptionBarSearchNotPending = true;
|
||||
OptionBarLoading = false;
|
||||
OptionBarMessage = null;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task PlaylistSearchStart()
|
||||
{
|
||||
OptionBarSearchNotPending = false;
|
||||
OptionBarLoading = true;
|
||||
OptionBarMessage = _stringResourcesService.HomeViewResources.Get("OptionBarMessageLoading");
|
||||
|
||||
Playlist playlist;
|
||||
try
|
||||
{
|
||||
playlist = await _searchService.SearchPlaylist(OptionBarPlaylistSearchTBValue, OptionBarPlaylistSearchNBValue);
|
||||
}
|
||||
catch (MediaSearchException ex)
|
||||
{
|
||||
OptionBarLoading = false;
|
||||
OptionBarMessage = ex.Message;
|
||||
OptionBarSearchNotPending = true;
|
||||
return;
|
||||
}
|
||||
|
||||
OptionBarSearchNotPending = true;
|
||||
OptionBarLoading = false;
|
||||
OptionBarMessage = null;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void Download()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
private async void VideoViewModel_TaskAdded(object sender, EventArgs e) => await Navigation();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user