2024-06-19 00:16:02 +00:00
|
|
|
using System;
|
2024-05-04 15:35:32 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Collections.Specialized;
|
2024-07-12 02:35:33 +00:00
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Linq;
|
2024-05-04 15:35:32 +00:00
|
|
|
using System.Net.Http;
|
|
|
|
using System.Text.RegularExpressions;
|
2024-07-12 02:35:33 +00:00
|
|
|
using System.Threading;
|
2024-05-04 15:35:32 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Media.Imaging;
|
|
|
|
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-04 15:35:32 +00:00
|
|
|
using CRD.Utils;
|
|
|
|
using CRD.Utils.Structs;
|
2024-08-09 21:16:13 +00:00
|
|
|
using CRD.Utils.Structs.Crunchyroll.Music;
|
2024-05-04 15:35:32 +00:00
|
|
|
using CRD.Views;
|
2024-07-12 02:35:33 +00:00
|
|
|
using DynamicData;
|
2024-07-23 19:14:55 +00:00
|
|
|
using FluentAvalonia.Core;
|
2024-05-04 15:35:32 +00:00
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CRD.ViewModels;
|
|
|
|
|
|
|
|
public partial class AddDownloadPageViewModel : ViewModelBase{
|
2024-06-26 22:04:50 +00:00
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private string _urlInput = "";
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private string _buttonText = "Enter Url";
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private string _buttonTextSelectSeason = "Select Season";
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private bool _addAllEpisodes = false;
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private bool _buttonEnabled = false;
|
2024-06-26 22:04:50 +00:00
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private bool _allButtonEnabled = false;
|
2024-05-04 15:35:32 +00:00
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private bool _showLoading = false;
|
2024-07-12 02:35:33 +00:00
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private bool _searchEnabled = false;
|
2024-07-12 02:35:33 +00:00
|
|
|
|
|
|
|
[ObservableProperty]
|
2024-07-23 19:14:55 +00:00
|
|
|
private bool _searchVisible = true;
|
2024-08-09 21:16:13 +00:00
|
|
|
|
2024-07-23 19:14:55 +00:00
|
|
|
[ObservableProperty]
|
|
|
|
private bool _slectSeasonVisible = false;
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
private bool _searchPopupVisible = false;
|
2024-07-12 02:35:33 +00:00
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
public ObservableCollection<ItemModel> Items{ get; } = new();
|
2024-07-12 02:35:33 +00:00
|
|
|
public ObservableCollection<CrBrowseSeries> SearchItems{ get; set; } = new();
|
2024-05-04 15:35:32 +00:00
|
|
|
public ObservableCollection<ItemModel> SelectedItems{ get; } = new();
|
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
[ObservableProperty]
|
|
|
|
public CrBrowseSeries _selectedSearchItem;
|
|
|
|
|
2024-06-26 22:04:50 +00:00
|
|
|
[ObservableProperty]
|
|
|
|
public ComboBoxItem _currentSelectedSeason;
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
public ObservableCollection<ComboBoxItem> SeasonList{ get; } = new();
|
|
|
|
|
|
|
|
private Dictionary<string, List<ItemModel>> episodesBySeason = new();
|
|
|
|
|
|
|
|
private List<string> selectedEpisodes = new();
|
|
|
|
|
|
|
|
private CrunchySeriesList? currentSeriesList;
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private CrunchyMusicVideoList? currentMusicVideoList;
|
|
|
|
|
2024-07-23 19:14:55 +00:00
|
|
|
private bool CurrentSeasonFullySelected = false;
|
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
private readonly SemaphoreSlim _updateSearchSemaphore = new SemaphoreSlim(1, 1);
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
public AddDownloadPageViewModel(){
|
|
|
|
SelectedItems.CollectionChanged += OnSelectedItemsChanged;
|
|
|
|
}
|
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
private async Task UpdateSearch(string value){
|
2024-08-12 15:10:08 +00:00
|
|
|
if (string.IsNullOrEmpty(value)){
|
|
|
|
SearchPopupVisible = false;
|
|
|
|
RaisePropertyChanged(nameof(SearchVisible));
|
|
|
|
SearchItems.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-21 09:30:20 +00:00
|
|
|
var searchResults = await CrunchyrollManager.Instance.CrSeries.Search(value, CrunchyrollManager.Instance.CrunOptions.HistoryLang);
|
2024-05-04 15:35:32 +00:00
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
var searchItems = searchResults?.Data?.First().Items;
|
|
|
|
SearchItems.Clear();
|
|
|
|
if (searchItems is{ Count: > 0 }){
|
|
|
|
foreach (var episode in searchItems){
|
|
|
|
if (episode.ImageBitmap == null){
|
|
|
|
if (episode.Images.PosterTall != null){
|
|
|
|
var posterTall = episode.Images.PosterTall.First();
|
|
|
|
var imageUrl = posterTall.Find(ele => ele.Height == 180).Source
|
|
|
|
?? (posterTall.Count >= 2 ? posterTall[1].Source : posterTall.FirstOrDefault().Source);
|
|
|
|
episode.LoadImage(imageUrl);
|
|
|
|
}
|
|
|
|
}
|
2024-07-16 23:52:46 +00:00
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
SearchItems.Add(episode);
|
|
|
|
}
|
2024-07-23 19:14:55 +00:00
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
SearchPopupVisible = true;
|
|
|
|
RaisePropertyChanged(nameof(SearchItems));
|
|
|
|
RaisePropertyChanged(nameof(SearchVisible));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchPopupVisible = false;
|
|
|
|
RaisePropertyChanged(nameof(SearchVisible));
|
|
|
|
SearchItems.Clear();
|
|
|
|
}
|
2024-07-16 23:52:46 +00:00
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
#region UrlInput
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
partial void OnUrlInputChanged(string value){
|
2024-07-12 02:35:33 +00:00
|
|
|
if (SearchEnabled){
|
2024-08-09 21:16:13 +00:00
|
|
|
_ = UpdateSearch(value);
|
|
|
|
SetButtonProperties("Select Searched Series", false);
|
2024-07-12 02:35:33 +00:00
|
|
|
} else if (UrlInput.Length > 9){
|
2024-08-09 21:16:13 +00:00
|
|
|
EvaluateUrlInput();
|
2024-07-12 02:35:33 +00:00
|
|
|
} else{
|
2024-08-09 21:16:13 +00:00
|
|
|
SetButtonProperties("Enter Url", false);
|
|
|
|
SetVisibility(true, false);
|
2024-07-12 02:35:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private void EvaluateUrlInput(){
|
|
|
|
var (buttonText, isButtonEnabled) = DetermineButtonTextAndState();
|
|
|
|
|
|
|
|
SetButtonProperties(buttonText, isButtonEnabled);
|
|
|
|
SetVisibility(false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private (string, bool) DetermineButtonTextAndState(){
|
|
|
|
return UrlInput switch{
|
|
|
|
_ when UrlInput.Contains("/artist/") => ("List Episodes", true),
|
|
|
|
_ when UrlInput.Contains("/watch/musicvideo/") => ("Add Music Video to Queue", true),
|
|
|
|
_ when UrlInput.Contains("/watch/concert/") => ("Add Concert to Queue", true),
|
|
|
|
_ when UrlInput.Contains("/watch/") => ("Add Episode to Queue", true),
|
|
|
|
_ when UrlInput.Contains("/series/") => ("List Episodes", true),
|
|
|
|
_ => ("Unknown", false),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetButtonProperties(string text, bool isEnabled){
|
|
|
|
ButtonText = text;
|
|
|
|
ButtonEnabled = isEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetVisibility(bool isSearchVisible, bool isSelectSeasonVisible){
|
|
|
|
SearchVisible = isSearchVisible;
|
|
|
|
SlectSeasonVisible = isSelectSeasonVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
partial void OnSearchEnabledChanged(bool value){
|
2024-08-09 21:16:13 +00:00
|
|
|
ButtonText = SearchEnabled ? "Select Searched Series" : "Enter Url";
|
|
|
|
ButtonEnabled = false;
|
2024-05-04 15:35:32 +00:00
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
#region OnButtonPress
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
[RelayCommand]
|
|
|
|
public async void OnButtonPress(){
|
2024-08-09 21:16:13 +00:00
|
|
|
if (HasSelectedItemsOrEpisodes()){
|
2024-05-04 15:35:32 +00:00
|
|
|
Console.WriteLine("Added to Queue");
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
if (currentMusicVideoList != null){
|
|
|
|
AddSelectedMusicVideosToQueue();
|
|
|
|
} else{
|
|
|
|
AddSelectedEpisodesToQueue();
|
2024-05-04 15:35:32 +00:00
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
ResetState();
|
|
|
|
} else if (UrlInput.Length > 9){
|
|
|
|
await HandleUrlInputAsync();
|
|
|
|
} else{
|
|
|
|
Console.Error.WriteLine("Unknown input");
|
|
|
|
}
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private bool HasSelectedItemsOrEpisodes(){
|
|
|
|
return selectedEpisodes.Count > 0 || SelectedItems.Count > 0 || AddAllEpisodes;
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private void AddSelectedMusicVideosToQueue(){
|
|
|
|
if (SelectedItems.Count > 0){
|
|
|
|
var musicClass = CrunchyrollManager.Instance.CrMusic;
|
|
|
|
foreach (var selectedItem in SelectedItems){
|
|
|
|
var music = currentMusicVideoList.Value.Data?.FirstOrDefault(ele => ele.Id == selectedItem.Id);
|
|
|
|
|
|
|
|
if (music != null){
|
|
|
|
var meta = musicClass.EpisodeMeta(music);
|
|
|
|
QueueManager.Instance.CrAddEpMetaToQueue(meta);
|
2024-05-04 15:35:32 +00:00
|
|
|
}
|
2024-08-09 21:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private async void AddSelectedEpisodesToQueue(){
|
|
|
|
AddItemsToSelectedEpisodes();
|
|
|
|
|
|
|
|
if (currentSeriesList != null){
|
|
|
|
await QueueManager.Instance.CrAddSeriesToQueue(
|
|
|
|
currentSeriesList.Value,
|
|
|
|
new CrunchyMultiDownload(
|
|
|
|
CrunchyrollManager.Instance.CrunOptions.DubLang,
|
|
|
|
AddAllEpisodes,
|
|
|
|
false,
|
|
|
|
selectedEpisodes));
|
|
|
|
}
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private void AddItemsToSelectedEpisodes(){
|
|
|
|
foreach (var selectedItem in SelectedItems){
|
|
|
|
if (!selectedEpisodes.Contains(selectedItem.AbsolutNum)){
|
|
|
|
selectedEpisodes.Add(selectedItem.AbsolutNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private void ResetState(){
|
|
|
|
currentMusicVideoList = null;
|
|
|
|
UrlInput = "";
|
|
|
|
selectedEpisodes.Clear();
|
|
|
|
SelectedItems.Clear();
|
|
|
|
Items.Clear();
|
|
|
|
currentSeriesList = null;
|
|
|
|
SeasonList.Clear();
|
|
|
|
episodesBySeason.Clear();
|
|
|
|
AllButtonEnabled = false;
|
|
|
|
AddAllEpisodes = false;
|
|
|
|
ButtonText = "Enter Url";
|
|
|
|
ButtonEnabled = false;
|
|
|
|
SearchVisible = true;
|
|
|
|
SlectSeasonVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task HandleUrlInputAsync(){
|
|
|
|
episodesBySeason.Clear();
|
|
|
|
SeasonList.Clear();
|
|
|
|
|
|
|
|
var matchResult = ExtractLocaleAndIdFromUrl();
|
|
|
|
|
|
|
|
if (matchResult is (string locale, string id)){
|
|
|
|
switch (GetUrlType()){
|
|
|
|
case CrunchyUrlType.Artist:
|
|
|
|
await HandleArtistUrlAsync(locale, id);
|
|
|
|
break;
|
|
|
|
case CrunchyUrlType.MusicVideo:
|
|
|
|
HandleMusicVideoUrl(id);
|
|
|
|
break;
|
|
|
|
case CrunchyUrlType.Concert:
|
|
|
|
HandleConcertUrl(id);
|
|
|
|
break;
|
|
|
|
case CrunchyUrlType.Episode:
|
|
|
|
HandleEpisodeUrl(locale, id);
|
|
|
|
break;
|
|
|
|
case CrunchyUrlType.Series:
|
|
|
|
await HandleSeriesUrlAsync(locale, id);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Console.Error.WriteLine("Unknown input");
|
|
|
|
break;
|
2024-05-04 15:35:32 +00:00
|
|
|
}
|
2024-08-09 21:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private (string locale, string id)? ExtractLocaleAndIdFromUrl(){
|
|
|
|
var match = Regex.Match(UrlInput, "/([^/]+)/(?:artist|watch|series)(?:/(?:musicvideo|concert))?/([^/]+)/?");
|
|
|
|
return match.Success ? (match.Groups[1].Value, match.Groups[2].Value) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private CrunchyUrlType GetUrlType(){
|
|
|
|
return UrlInput switch{
|
|
|
|
_ when UrlInput.Contains("/artist/") => CrunchyUrlType.Artist,
|
|
|
|
_ when UrlInput.Contains("/watch/musicvideo/") => CrunchyUrlType.MusicVideo,
|
|
|
|
_ when UrlInput.Contains("/watch/concert/") => CrunchyUrlType.Concert,
|
|
|
|
_ when UrlInput.Contains("/watch/") => CrunchyUrlType.Episode,
|
|
|
|
_ when UrlInput.Contains("/series/") => CrunchyUrlType.Series,
|
|
|
|
_ => CrunchyUrlType.Unknown,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task HandleArtistUrlAsync(string locale, string id){
|
|
|
|
SetLoadingState(true);
|
|
|
|
|
|
|
|
var list = await CrunchyrollManager.Instance.CrMusic.ParseArtistMusicVideosByIdAsync(
|
|
|
|
id, DetermineLocale(locale), true);
|
|
|
|
|
|
|
|
SetLoadingState(false);
|
|
|
|
|
|
|
|
if (list != null){
|
|
|
|
currentMusicVideoList = list;
|
|
|
|
PopulateItemsFromMusicVideoList();
|
|
|
|
UpdateUiForSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HandleMusicVideoUrl(string id){
|
|
|
|
_ = QueueManager.Instance.CrAddMusicVideoToQueue(id);
|
|
|
|
ResetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HandleConcertUrl(string id){
|
|
|
|
_ = QueueManager.Instance.CrAddConcertToQueue(id);
|
|
|
|
ResetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void HandleEpisodeUrl(string locale, string id){
|
|
|
|
_ = QueueManager.Instance.CrAddEpisodeToQueue(
|
|
|
|
id, DetermineLocale(locale),
|
|
|
|
CrunchyrollManager.Instance.CrunOptions.DubLang, true);
|
|
|
|
ResetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task HandleSeriesUrlAsync(string locale, string id){
|
|
|
|
SetLoadingState(true);
|
|
|
|
|
|
|
|
var list = await CrunchyrollManager.Instance.CrSeries.ListSeriesId(
|
|
|
|
id, DetermineLocale(locale),
|
|
|
|
new CrunchyMultiDownload(CrunchyrollManager.Instance.CrunOptions.DubLang, true));
|
|
|
|
|
|
|
|
SetLoadingState(false);
|
|
|
|
|
|
|
|
if (list != null){
|
|
|
|
currentSeriesList = list;
|
|
|
|
PopulateEpisodesBySeason();
|
|
|
|
UpdateUiForSelection();
|
2024-05-04 15:35:32 +00:00
|
|
|
} else{
|
2024-08-09 21:16:13 +00:00
|
|
|
ButtonEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PopulateItemsFromMusicVideoList(){
|
|
|
|
if (currentMusicVideoList?.Data != null){
|
|
|
|
foreach (var episode in currentMusicVideoList.Value.Data){
|
|
|
|
var imageUrl = episode.Images?.Thumbnail?.FirstOrDefault().Source ?? "";
|
|
|
|
var time = $"{(episode.DurationMs / 1000) / 60}:{(episode.DurationMs / 1000) % 60:D2}";
|
|
|
|
|
|
|
|
var newItem = new ItemModel(episode.Id ?? "", imageUrl, episode.Description ?? "", time, episode.Title ?? "", "",
|
|
|
|
episode.SequenceNumber.ToString(), episode.SequenceNumber.ToString(), new List<string>());
|
|
|
|
|
|
|
|
newItem.LoadImage(imageUrl);
|
|
|
|
Items.Add(newItem);
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private void PopulateEpisodesBySeason(){
|
|
|
|
foreach (var episode in currentSeriesList?.List ?? Enumerable.Empty<Episode>()){
|
|
|
|
var seasonKey = "S" + episode.Season;
|
|
|
|
var itemModel = new ItemModel(
|
|
|
|
episode.Id, episode.Img, episode.Description, episode.Time, episode.Name, seasonKey,
|
|
|
|
episode.EpisodeNum.StartsWith("SP") ? episode.EpisodeNum : "E" + episode.EpisodeNum,
|
|
|
|
episode.E, episode.Lang);
|
|
|
|
|
|
|
|
if (!episodesBySeason.ContainsKey(seasonKey)){
|
|
|
|
episodesBySeason[seasonKey] = new List<ItemModel>{ itemModel };
|
|
|
|
SeasonList.Add(new ComboBoxItem{ Content = seasonKey });
|
|
|
|
} else{
|
|
|
|
episodesBySeason[seasonKey].Add(itemModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentSelectedSeason = SeasonList.First();
|
|
|
|
}
|
|
|
|
|
|
|
|
private string DetermineLocale(string locale){
|
|
|
|
return string.IsNullOrEmpty(locale)
|
|
|
|
? (string.IsNullOrEmpty(CrunchyrollManager.Instance.CrunOptions.HistoryLang)
|
|
|
|
? CrunchyrollManager.Instance.DefaultLocale
|
|
|
|
: CrunchyrollManager.Instance.CrunOptions.HistoryLang)
|
|
|
|
: Languages.Locale2language(locale).CrLocale;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetLoadingState(bool isLoading){
|
|
|
|
ButtonEnabled = !isLoading;
|
|
|
|
ShowLoading = isLoading;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateUiForSelection(){
|
|
|
|
ButtonEnabled = false;
|
|
|
|
AllButtonEnabled = true;
|
|
|
|
SlectSeasonVisible = false;
|
|
|
|
ButtonText = "Select Episodes";
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
2024-07-23 19:14:55 +00:00
|
|
|
[RelayCommand]
|
|
|
|
public void OnSelectSeasonPressed(){
|
|
|
|
if (CurrentSeasonFullySelected){
|
|
|
|
foreach (var item in Items){
|
|
|
|
selectedEpisodes.Remove(item.AbsolutNum);
|
|
|
|
SelectedItems.Remove(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonTextSelectSeason = "Select Season";
|
|
|
|
} else{
|
|
|
|
var selectedItemsSet = new HashSet<ItemModel>(SelectedItems);
|
|
|
|
|
|
|
|
foreach (var item in Items){
|
|
|
|
if (selectedItemsSet.Add(item)){
|
|
|
|
SelectedItems.Add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonTextSelectSeason = "Deselect Season";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
partial void OnCurrentSelectedSeasonChanging(ComboBoxItem? oldValue, ComboBoxItem newValue){
|
|
|
|
foreach (var selectedItem in SelectedItems){
|
|
|
|
if (!selectedEpisodes.Contains(selectedItem.AbsolutNum)){
|
|
|
|
selectedEpisodes.Add(selectedItem.AbsolutNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedEpisodes.Count > 0 || SelectedItems.Count > 0 || AddAllEpisodes){
|
|
|
|
ButtonText = "Add Episodes to Queue";
|
|
|
|
ButtonEnabled = true;
|
|
|
|
} else{
|
|
|
|
ButtonEnabled = false;
|
|
|
|
ButtonText = "Select Episodes";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnSelectedItemsChanged(object? sender, NotifyCollectionChangedEventArgs e){
|
2024-07-23 19:14:55 +00:00
|
|
|
CurrentSeasonFullySelected = Items.All(item => SelectedItems.Contains(item));
|
|
|
|
|
|
|
|
if (CurrentSeasonFullySelected){
|
|
|
|
ButtonTextSelectSeason = "Deselect Season";
|
|
|
|
} else{
|
|
|
|
ButtonTextSelectSeason = "Select Season";
|
|
|
|
}
|
|
|
|
|
2024-05-04 15:35:32 +00:00
|
|
|
if (selectedEpisodes.Count > 0 || SelectedItems.Count > 0 || AddAllEpisodes){
|
|
|
|
ButtonText = "Add Episodes to Queue";
|
|
|
|
ButtonEnabled = true;
|
|
|
|
} else{
|
|
|
|
ButtonEnabled = false;
|
|
|
|
ButtonText = "Select Episodes";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
partial void OnAddAllEpisodesChanged(bool value){
|
|
|
|
if ((selectedEpisodes.Count > 0 || SelectedItems.Count > 0 || AddAllEpisodes)){
|
|
|
|
ButtonText = "Add Episodes to Queue";
|
|
|
|
ButtonEnabled = true;
|
|
|
|
} else{
|
|
|
|
ButtonEnabled = false;
|
|
|
|
ButtonText = "Select Episodes";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
|
|
|
|
#region SearchItemSelection
|
|
|
|
|
2024-07-16 23:52:46 +00:00
|
|
|
async partial void OnSelectedSearchItemChanged(CrBrowseSeries? value){
|
2024-08-09 21:16:13 +00:00
|
|
|
if (value is null || string.IsNullOrEmpty(value.Id)){
|
2024-07-12 02:35:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
UpdateUiForSearchSelection();
|
|
|
|
|
|
|
|
var list = await FetchSeriesListAsync(value.Id);
|
|
|
|
|
|
|
|
if (list != null){
|
|
|
|
currentSeriesList = list;
|
|
|
|
SearchPopulateEpisodesBySeason();
|
|
|
|
UpdateUiForEpisodeSelection();
|
|
|
|
} else{
|
|
|
|
ButtonEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateUiForSearchSelection(){
|
2024-07-12 02:35:33 +00:00
|
|
|
SearchPopupVisible = false;
|
|
|
|
RaisePropertyChanged(nameof(SearchVisible));
|
|
|
|
SearchItems.Clear();
|
|
|
|
SearchVisible = false;
|
2024-07-23 19:14:55 +00:00
|
|
|
SlectSeasonVisible = true;
|
2024-07-12 02:35:33 +00:00
|
|
|
ButtonEnabled = false;
|
|
|
|
ShowLoading = true;
|
2024-08-09 21:16:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private async Task<CrunchySeriesList?> FetchSeriesListAsync(string seriesId){
|
|
|
|
var locale = string.IsNullOrEmpty(CrunchyrollManager.Instance.CrunOptions.HistoryLang)
|
|
|
|
? CrunchyrollManager.Instance.DefaultLocale
|
|
|
|
: CrunchyrollManager.Instance.CrunOptions.HistoryLang;
|
|
|
|
|
|
|
|
return await CrunchyrollManager.Instance.CrSeries.ListSeriesId(
|
|
|
|
seriesId,
|
|
|
|
locale,
|
2024-07-21 09:30:20 +00:00
|
|
|
new CrunchyMultiDownload(CrunchyrollManager.Instance.CrunOptions.DubLang, true));
|
2024-08-09 21:16:13 +00:00
|
|
|
}
|
2024-07-12 02:35:33 +00:00
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
private void SearchPopulateEpisodesBySeason(){
|
|
|
|
if (currentSeriesList?.List == null){
|
|
|
|
return;
|
2024-07-12 02:35:33 +00:00
|
|
|
}
|
2024-08-09 21:16:13 +00:00
|
|
|
|
|
|
|
foreach (var episode in currentSeriesList.Value.List){
|
|
|
|
var seasonKey = "S" + episode.Season;
|
|
|
|
var episodeModel = new ItemModel(
|
|
|
|
episode.Id,
|
|
|
|
episode.Img,
|
|
|
|
episode.Description,
|
|
|
|
episode.Time,
|
|
|
|
episode.Name,
|
|
|
|
seasonKey,
|
|
|
|
episode.EpisodeNum.StartsWith("SP") ? episode.EpisodeNum : "E" + episode.EpisodeNum,
|
|
|
|
episode.E,
|
|
|
|
episode.Lang);
|
|
|
|
|
|
|
|
if (!episodesBySeason.ContainsKey(seasonKey)){
|
|
|
|
episodesBySeason[seasonKey] = new List<ItemModel>{ episodeModel };
|
|
|
|
SeasonList.Add(new ComboBoxItem{ Content = seasonKey });
|
|
|
|
} else{
|
|
|
|
episodesBySeason[seasonKey].Add(episodeModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentSelectedSeason = SeasonList.First();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateUiForEpisodeSelection(){
|
|
|
|
ShowLoading = false;
|
|
|
|
ButtonEnabled = false;
|
|
|
|
AllButtonEnabled = true;
|
|
|
|
ButtonText = "Select Episodes";
|
2024-07-12 02:35:33 +00:00
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
partial void OnCurrentSelectedSeasonChanged(ComboBoxItem? value){
|
2024-05-04 15:35:32 +00:00
|
|
|
if (value == null){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
string key = value.Content + "";
|
|
|
|
Items.Clear();
|
|
|
|
if (episodesBySeason.TryGetValue(key, out var season)){
|
|
|
|
foreach (var episode in season){
|
|
|
|
if (episode.ImageBitmap == null){
|
2024-07-12 02:35:33 +00:00
|
|
|
episode.LoadImage(episode.ImageUrl);
|
2024-05-04 15:35:32 +00:00
|
|
|
Items.Add(episode);
|
|
|
|
if (selectedEpisodes.Contains(episode.AbsolutNum)){
|
|
|
|
SelectedItems.Add(episode);
|
|
|
|
}
|
|
|
|
} else{
|
|
|
|
Items.Add(episode);
|
|
|
|
if (selectedEpisodes.Contains(episode.AbsolutNum)){
|
|
|
|
SelectedItems.Add(episode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-23 19:14:55 +00:00
|
|
|
|
|
|
|
CurrentSeasonFullySelected = Items.All(item => SelectedItems.Contains(item));
|
|
|
|
|
|
|
|
if (CurrentSeasonFullySelected){
|
|
|
|
ButtonTextSelectSeason = "Deselect Season";
|
|
|
|
} else{
|
|
|
|
ButtonTextSelectSeason = "Select Season";
|
|
|
|
}
|
2024-05-04 15:35:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 21:16:13 +00:00
|
|
|
public class ItemModel(string id, string imageUrl, string description, string time, string title, string season, string episode, string absolutNum, List<string> availableAudios) : INotifyPropertyChanged{
|
|
|
|
public string Id{ get; set; } = id;
|
2024-05-04 15:35:32 +00:00
|
|
|
public string ImageUrl{ get; set; } = imageUrl;
|
|
|
|
public Bitmap? ImageBitmap{ get; set; }
|
|
|
|
public string Title{ get; set; } = title;
|
|
|
|
public string Description{ get; set; } = description;
|
|
|
|
public string Time{ get; set; } = time;
|
|
|
|
public string Season{ get; set; } = season;
|
|
|
|
public string Episode{ get; set; } = episode;
|
|
|
|
|
|
|
|
public string AbsolutNum{ get; set; } = absolutNum;
|
|
|
|
|
|
|
|
public string TitleFull{ get; set; } = season + episode + " - " + title;
|
|
|
|
|
|
|
|
public List<string> AvailableAudios{ get; set; } = availableAudios;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
2024-07-16 23:52:46 +00:00
|
|
|
|
2024-07-12 02:35:33 +00:00
|
|
|
public async void LoadImage(string url){
|
|
|
|
ImageBitmap = await Helpers.LoadImage(url);
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ImageBitmap)));
|
2024-05-04 15:35:32 +00:00
|
|
|
}
|
|
|
|
}
|