Crunchy-Downloader/CRD/ViewModels/Utils/ContentDialogFeaturedMusicViewModel.cs
Elwador 985fd9c00f Added **tray icon** [#393](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/393).
Added **ability to switch between account profiles** [#372](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/372).
Added option to **execute a file when the download queue finishes** [#392](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/392).
Added **auto history refresh / auto add to queue** [#394](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/394).
Changed **font loading** to also include fonts from the local fonts folder that are not available on Crunchyroll [#371](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/371).
Updated packages to latest versions
Fixed **history not being saved** after it was updated via the calendar
Fixed **Downloaded toggle in history** being slow for large seasons
2026-03-04 18:17:28 +01:00

94 lines
No EOL
3.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CRD.Downloader.Crunchyroll;
using CRD.Utils;
using CRD.Utils.Structs.Crunchyroll.Music;
using CRD.Utils.Structs.History;
using CRD.Utils.UI;
using DynamicData;
using FluentAvalonia.UI.Controls;
namespace CRD.ViewModels.Utils;
public partial class ContentDialogFeaturedMusicViewModel : ViewModelBase{
private readonly CustomContentDialog dialog;
[ObservableProperty]
private ObservableCollection<HistoryEpisode> _featuredMusicList = new();
[ObservableProperty]
private bool _musicInHistory;
private CrunchyMusicVideoList featuredMusic;
private string FolderPath = "";
public ContentDialogFeaturedMusicViewModel(CustomContentDialog contentDialog, CrunchyMusicVideoList featuredMusic, bool crunOptionsHistoryIncludeCrArtists, string overrideDownloadPath = ""){
ArgumentNullException.ThrowIfNull(contentDialog);
this.featuredMusic = featuredMusic;
this.FolderPath = overrideDownloadPath + "/OST";
dialog = contentDialog;
dialog.Closed += DialogOnClosed;
dialog.PrimaryButtonClick += SaveButton;
if (crunOptionsHistoryIncludeCrArtists){
var episodeList = featuredMusic.Data
.Select(video =>
CrunchyrollManager.Instance.HistoryList
.FirstOrDefault(h => h.SeriesId == video.GetSeriesId())?
.Seasons.FirstOrDefault(s => s.SeasonId == video.GetSeasonId())?
.EpisodesList.FirstOrDefault(e => e.EpisodeId == video.GetEpisodeId()))
.Where(episode => episode != null)
.ToList();
if (episodeList.Count > 0){
FeaturedMusicList.Clear();
FeaturedMusicList!.AddRange(episodeList);
}
} else{
List<HistoryEpisode> episodeList =[];
foreach (var crunchyMusicVideo in featuredMusic.Data){
var newHistoryEpisode = new HistoryEpisode{
EpisodeTitle = crunchyMusicVideo.GetEpisodeTitle(),
EpisodeDescription = crunchyMusicVideo.GetEpisodeDescription(),
EpisodeId = crunchyMusicVideo.GetEpisodeId(),
Episode = crunchyMusicVideo.GetEpisodeNumber(),
EpisodeSeasonNum = crunchyMusicVideo.GetSeasonNum(),
SpecialEpisode = crunchyMusicVideo.IsSpecialEpisode(),
HistoryEpisodeAvailableDubLang = crunchyMusicVideo.GetEpisodeAvailableDubLang(),
HistoryEpisodeAvailableSoftSubs = crunchyMusicVideo.GetEpisodeAvailableSoftSubs(),
EpisodeCrPremiumAirDate = crunchyMusicVideo.GetAvailableDate(),
EpisodeType = crunchyMusicVideo.GetEpisodeType(),
IsEpisodeAvailableOnStreamingService = true,
ThumbnailImageUrl = crunchyMusicVideo.GetImageUrl(),
};
episodeList.Add(newHistoryEpisode);
newHistoryEpisode.LoadImage();
}
if (episodeList.Count > 0){
FeaturedMusicList.Clear();
FeaturedMusicList.AddRange(episodeList);
}
}
}
[RelayCommand]
public void DownloadEpisode(HistoryEpisode episode){
episode.DownloadEpisode(EpisodeDownloadMode.Default, FolderPath,false);
}
private void SaveButton(ContentDialog sender, ContentDialogButtonClickEventArgs args){
dialog.PrimaryButtonClick -= SaveButton;
}
private void DialogOnClosed(ContentDialog sender, ContentDialogClosedEventArgs args){
dialog.Closed -= DialogOnClosed;
}
}