2024-05-04 15:35:32 +00:00
|
|
|
|
using System;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
using System.Diagnostics;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
using CRD.Downloader;
|
2024-05-11 11:08:24 +00:00
|
|
|
|
using CRD.Utils;
|
2024-05-25 22:02:45 +00:00
|
|
|
|
using CRD.Utils.Sonarr;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
using CRD.Views;
|
|
|
|
|
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-05-25 22:02:45 +00:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public static bool _sonarrAvailable;
|
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
public SeriesPageViewModel(){
|
|
|
|
|
_selectedSeries = Crunchyroll.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-05-25 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(SelectedSeries.SonarrSeriesId)){
|
|
|
|
|
SonarrAvailable = SelectedSeries.SonarrSeriesId.Length > 0;
|
|
|
|
|
Crunchyroll.Instance.CrHistory.MatchHistoryEpisodesWithSonarr(true,SelectedSeries);
|
|
|
|
|
CfgManager.WriteJsonToFile(CfgManager.PathCrHistory, Crunchyroll.Instance.HistoryList);
|
|
|
|
|
} else{
|
|
|
|
|
SonarrAvailable = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|
2024-05-25 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
public void OpenSonarrPage(){
|
|
|
|
|
var sonarrProp = Crunchyroll.Instance.CrunOptions.SonarrProperties;
|
|
|
|
|
|
|
|
|
|
if (sonarrProp == null) return;
|
|
|
|
|
|
|
|
|
|
OpenUrl($"http{(sonarrProp.UseSsl ? "s" : "")}://{sonarrProp.Host}:{sonarrProp.Port}{(sonarrProp.UrlBase ?? "")}/series/{SelectedSeries.SonarrSlugTitle}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
public void OpenCrPage(){
|
|
|
|
|
|
|
|
|
|
OpenUrl($"https://www.crunchyroll.com/series/{SelectedSeries.SeriesId}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
|
[RelayCommand]
|
|
|
|
|
public async Task UpdateData(string? season){
|
|
|
|
|
await SelectedSeries.FetchData(season);
|
|
|
|
|
|
2024-05-25 22:02:45 +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){
|
|
|
|
|
HistorySeason? objectToRemove = SelectedSeries.Seasons.Find(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-05-25 22:02:45 +00:00
|
|
|
|
|
|
|
|
|
CfgManager.WriteJsonToFile(CfgManager.PathCrHistory, Crunchyroll.Instance.HistoryList);
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OpenUrl(string url){
|
|
|
|
|
try{
|
|
|
|
|
Process.Start(new ProcessStartInfo{
|
|
|
|
|
FileName = url,
|
|
|
|
|
UseShellExecute = true
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
Console.WriteLine($"An error occurred: {e.Message}");
|
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|