2024-05-04 15:35:32 +00:00
|
|
|
|
using System;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
using System.Diagnostics;
|
2024-06-26 22:04:50 +00:00
|
|
|
|
using System.Linq;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
using Avalonia.Controls;
|
2024-06-21 01:49:44 +00:00
|
|
|
|
using Avalonia.Platform.Storage;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
using CRD.Downloader;
|
2024-07-21 09:30:20 +00:00
|
|
|
|
using CRD.Downloader.Crunchyroll;
|
2024-05-11 11:08:24 +00:00
|
|
|
|
using CRD.Utils;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
using CRD.Utils.Sonarr;
|
2024-06-26 22:04:50 +00:00
|
|
|
|
using CRD.Utils.Structs;
|
|
|
|
|
using CRD.Utils.Structs.History;
|
2024-08-15 00:27:49 +00:00
|
|
|
|
using CRD.ViewModels.Utils;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using CRD.Views;
|
2024-08-15 00:27:49 +00:00
|
|
|
|
using CRD.Views.Utils;
|
|
|
|
|
using FluentAvalonia.UI.Controls;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
|
|
|
namespace CRD.ViewModels;
|
|
|
|
|
|
|
|
|
|
public partial class SeriesPageViewModel : ViewModelBase{
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public HistorySeries _selectedSeries;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
2024-05-11 11:08:24 +00:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public static bool _editMode;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-05-25 22:02:45 +00:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public static bool _sonarrAvailable;
|
2024-08-15 00:27:49 +00:00
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public static bool _sonarrConnected;
|
|
|
|
|
|
2024-07-16 23:52:46 +00:00
|
|
|
|
private IStorageProvider? _storageProvider;
|
|
|
|
|
|
2024-08-15 00:27:49 +00:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string _availableDubs;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-08-15 00:27:49 +00:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string _availableSubs;
|
|
|
|
|
|
|
|
|
|
public SeriesPageViewModel(){
|
2024-07-21 09:30:20 +00:00
|
|
|
|
_selectedSeries = CrunchyrollManager.Instance.SelectedSeries;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
if (_selectedSeries.ThumbnailImage == null){
|
|
|
|
|
_selectedSeries.LoadImage();
|
|
|
|
|
}
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-08-15 00:27:49 +00:00
|
|
|
|
if (CrunchyrollManager.Instance.CrunOptions.SonarrProperties != null){
|
|
|
|
|
SonarrConnected = CrunchyrollManager.Instance.CrunOptions.SonarrProperties.SonarrEnabled;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(SelectedSeries.SonarrSeriesId)){
|
|
|
|
|
SonarrAvailable = SelectedSeries.SonarrSeriesId.Length > 0 && SonarrConnected;
|
|
|
|
|
} else{
|
|
|
|
|
SonarrAvailable = false;
|
|
|
|
|
}
|
2024-07-16 23:52:46 +00:00
|
|
|
|
} else{
|
2024-08-15 00:27:49 +00:00
|
|
|
|
SonarrConnected = SonarrAvailable = false;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
}
|
2024-08-15 00:27:49 +00:00
|
|
|
|
|
|
|
|
|
AvailableDubs = "Available Dubs: " + string.Join(", ", SelectedSeries.HistorySeriesAvailableDubLang);
|
|
|
|
|
AvailableSubs = "Available Subs: " + string.Join(", ", SelectedSeries.HistorySeriesAvailableSoftSubs);
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-06-21 01:49:44 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task OpenFolderDialogAsync(HistorySeason? season){
|
|
|
|
|
if (_storageProvider == null){
|
|
|
|
|
Console.Error.WriteLine("StorageProvider must be set before using the dialog.");
|
|
|
|
|
throw new InvalidOperationException("StorageProvider must be set before using the dialog.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = await _storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions{
|
|
|
|
|
Title = "Select Folder"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (result.Count > 0){
|
|
|
|
|
var selectedFolder = result[0];
|
|
|
|
|
// Do something with the selected folder path
|
|
|
|
|
Console.WriteLine($"Selected folder: {selectedFolder.Path.LocalPath}");
|
|
|
|
|
|
|
|
|
|
if (season != null){
|
|
|
|
|
season.SeasonDownloadPath = selectedFolder.Path.LocalPath;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
CfgManager.UpdateHistoryFile();
|
2024-06-21 01:49:44 +00:00
|
|
|
|
} else{
|
|
|
|
|
SelectedSeries.SeriesDownloadPath = selectedFolder.Path.LocalPath;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
CfgManager.UpdateHistoryFile();
|
2024-06-21 01:49:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetStorageProvider(IStorageProvider storageProvider){
|
|
|
|
|
_storageProvider = storageProvider ?? throw new ArgumentNullException(nameof(storageProvider));
|
|
|
|
|
}
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-08-15 00:27:49 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task MatchSonarrSeries_Button(){
|
|
|
|
|
var dialog = new ContentDialog(){
|
|
|
|
|
Title = "Sonarr Matching",
|
|
|
|
|
PrimaryButtonText = "Save",
|
|
|
|
|
CloseButtonText = "Close",
|
|
|
|
|
FullSizeDesired = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var viewModel = new ContentDialogSonarrMatchViewModel(dialog, SelectedSeries.SonarrSeriesId,SelectedSeries.SeriesTitle);
|
|
|
|
|
dialog.Content = new ContentDialogSonarrMatchView(){
|
|
|
|
|
DataContext = viewModel
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var dialogResult = await dialog.ShowAsync();
|
|
|
|
|
|
|
|
|
|
if (dialogResult == ContentDialogResult.Primary){
|
|
|
|
|
SelectedSeries.SonarrSeriesId = viewModel.CurrentSonarrSeries.Id.ToString();
|
|
|
|
|
SelectedSeries.SonarrTvDbId = viewModel.CurrentSonarrSeries.TvdbId.ToString();
|
|
|
|
|
SelectedSeries.SonarrSlugTitle = viewModel.CurrentSonarrSeries.TitleSlug;
|
|
|
|
|
|
|
|
|
|
if (CrunchyrollManager.Instance.CrunOptions.SonarrProperties != null){
|
|
|
|
|
SonarrConnected = CrunchyrollManager.Instance.CrunOptions.SonarrProperties.SonarrEnabled;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(SelectedSeries.SonarrSeriesId)){
|
|
|
|
|
SonarrAvailable = SelectedSeries.SonarrSeriesId.Length > 0 && SonarrConnected;
|
|
|
|
|
} else{
|
|
|
|
|
SonarrAvailable = false;
|
|
|
|
|
}
|
|
|
|
|
} else{
|
|
|
|
|
SonarrConnected = SonarrAvailable = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateData("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-07-23 19:14:55 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task DownloadSeasonAll(HistorySeason season){
|
2024-08-05 03:06:40 +00:00
|
|
|
|
var downloadTasks = season.EpisodesList
|
|
|
|
|
.Select(episode => episode.DownloadEpisode());
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(downloadTasks);
|
2024-07-23 19:14:55 +00:00
|
|
|
|
}
|
2024-08-05 03:06:40 +00:00
|
|
|
|
|
2024-07-23 19:14:55 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task DownloadSeasonMissing(HistorySeason season){
|
2024-08-05 03:06:40 +00:00
|
|
|
|
var downloadTasks = season.EpisodesList
|
|
|
|
|
.Where(episode => !episode.WasDownloaded)
|
|
|
|
|
.Select(episode => episode.DownloadEpisode());
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(downloadTasks);
|
2024-07-23 19:14:55 +00:00
|
|
|
|
}
|
2024-08-05 03:06:40 +00:00
|
|
|
|
|
2024-07-23 19:14:55 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task DownloadSeasonMissingSonarr(HistorySeason season){
|
2024-08-05 03:06:40 +00:00
|
|
|
|
var downloadTasks = season.EpisodesList
|
|
|
|
|
.Where(episode => !episode.SonarrHasFile)
|
|
|
|
|
.Select(episode => episode.DownloadEpisode());
|
|
|
|
|
|
|
|
|
|
await Task.WhenAll(downloadTasks);
|
2024-07-23 19:14:55 +00:00
|
|
|
|
}
|
2024-08-15 00:27:49 +00:00
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task UpdateData(string? season){
|
|
|
|
|
await SelectedSeries.FetchData(season);
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-06-29 20:15:34 +00:00
|
|
|
|
SelectedSeries.Seasons.Refresh();
|
2024-07-16 23:52:46 +00:00
|
|
|
|
|
2024-08-15 00:27:49 +00:00
|
|
|
|
AvailableDubs = "Available Dubs: " + string.Join(", ", SelectedSeries.HistorySeriesAvailableDubLang);
|
|
|
|
|
AvailableSubs = "Available Subs: " + string.Join(", ", SelectedSeries.HistorySeriesAvailableSoftSubs);
|
|
|
|
|
|
2024-06-27 20:52:12 +00:00
|
|
|
|
// MessageBus.Current.SendMessage(new NavigationMessage(typeof(SeriesPageViewModel), false, true));
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
2024-05-11 11:08:24 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public void RemoveSeason(string? season){
|
2024-06-26 22:04:50 +00:00
|
|
|
|
HistorySeason? objectToRemove = SelectedSeries.Seasons.FirstOrDefault(se => se.SeasonId == season) ?? null;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
if (objectToRemove != null){
|
2024-05-11 11:08:24 +00:00
|
|
|
|
SelectedSeries.Seasons.Remove(objectToRemove);
|
2024-07-16 23:52:46 +00:00
|
|
|
|
CfgManager.UpdateHistoryFile();
|
2024-05-11 11:08:24 +00:00
|
|
|
|
}
|
2024-08-15 00:27:49 +00:00
|
|
|
|
|
2024-05-25 22:02:45 +00:00
|
|
|
|
MessageBus.Current.SendMessage(new NavigationMessage(typeof(SeriesPageViewModel), false, true));
|
2024-05-11 11:08:24 +00:00
|
|
|
|
}
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public void NavBack(){
|
|
|
|
|
SelectedSeries.UpdateNewEpisodes();
|
2024-05-25 22:02:45 +00:00
|
|
|
|
MessageBus.Current.SendMessage(new NavigationMessage(null, true, false));
|
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|