Crunchy-Downloader/CRD/ViewModels/Utils/ContentDialogFeaturedMusicViewModel.cs
Elwador 67f3d7a84a Add - Added option to **download audio only as MP3**
Add - Added **File Name Whitespace Substitute** option in settings [#284](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/284)
Add - Added **download mode toggle (video/audio/subs)** for seasons with the ability to switch between options [#281](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/281)
Add - Added **download all** for only (video/audio/subs) for a season [#281](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/281)
Chg - Changed to **display a message** when the calendar fails to load due to Cloudflare issues [#283](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/283)
Chg - Adjusted **Calendar upcoming filter** for improved accuracy
Fix - Fixed **duplicate/wrong Crunchyroll versions** appearing in downloads [#285](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/285)
Fix - Fixed issue where **episodes with non-Japanese audio URLs** couldn't be added
Fix - Fixed **calendar crash** on Cloudflare failure [#283](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/283)
Fix - Fixed **audio-only downloads** [#279](https://github.com/Crunchy-DL/Crunchy-Downloader/issues/279)
Fix - Fixed **crash when no featured music** is present
Fix - Fixed **"All" button not working** for music in the Add Downloads tab
Fix - Fixed that an **empty File Name Whitespace Substitute** removed all whitespaces
2025-06-28 09:13:28 +02:00

92 lines
No EOL
3.6 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;
using CRD.Downloader.Crunchyroll;
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;
public ContentDialogFeaturedMusicViewModel(CustomContentDialog contentDialog, CrunchyMusicVideoList featuredMusic, bool crunOptionsHistoryIncludeCrArtists){
ArgumentNullException.ThrowIfNull(contentDialog);
this.featuredMusic = featuredMusic;
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();
}
private void SaveButton(ContentDialog sender, ContentDialogButtonClickEventArgs args){
dialog.PrimaryButtonClick -= SaveButton;
}
private void DialogOnClosed(ContentDialog sender, ContentDialogClosedEventArgs args){
dialog.Closed -= DialogOnClosed;
}
}