Skip to content

Commit

Permalink
Fix - Hotfix for Filter by Air date overwriting Hide Dubs
Browse files Browse the repository at this point in the history
Fix - Crash when opening calendar for the first time
  • Loading branch information
Elwador committed Jul 13, 2024
1 parent 6b44dbf commit 53158b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
45 changes: 24 additions & 21 deletions CRD/Downloader/Crunchyroll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Crunchyroll{
#region Calendar Variables

private Dictionary<string, CalendarWeek> calendar = new();

private Dictionary<string, string> calendarLanguage = new(){
{ "en-us", "https://www.crunchyroll.com/simulcastcalendar" },
{ "es", "https://www.crunchyroll.com/es/simulcastcalendar" },
Expand Down Expand Up @@ -134,7 +135,7 @@ public async Task Init(){
PreferredContentSubtitleLanguage = "de-DE",
HasPremium = false,
};

Console.WriteLine($"Can Decrypt: {_widevine.canDecrypt}");

CrunOptions.AutoDownload = false;
Expand All @@ -158,18 +159,18 @@ public async Task Init(){
CrunOptions.SimultaneousDownloads = 2;
CrunOptions.AccentColor = Colors.SlateBlue.ToString();
CrunOptions.Theme = "System";
CrunOptions.SelectedCalendarLanguage = "default";
CrunOptions.SelectedCalendarLanguage = "en-us";
CrunOptions.CalendarDubFilter = "none";
CrunOptions.DlVideoOnce = true;
CrunOptions.StreamEndpoint = "web/firefox";
CrunOptions.SubsAddScaledBorder = ScaledBorderAndShadowSelection.ScaledBorderAndShadowYes;
CrunOptions.HistoryLang = "";


CrunOptions.History = true;

CfgManager.UpdateSettingsFromFile();

if (CrunOptions.LogMode){
CfgManager.EnableLogMode();
} else{
Expand All @@ -182,17 +183,14 @@ public async Task Init(){
} else{
await CrAuth.AuthAnonymous();
}

if (CrunOptions.History){
if (File.Exists(CfgManager.PathCrHistory)){
HistoryList = JsonConvert.DeserializeObject<ObservableCollection<HistorySeries>>(File.ReadAllText(CfgManager.PathCrHistory)) ??[];
}

RefreshSonarr();
}



}

public async void RefreshSonarr(){
Expand All @@ -218,7 +216,7 @@ private void UpdateItemListOnRemove(object? sender, NotifyCollectionChangedEvent

UpdateDownloadListItems();
}

public void UpdateDownloadListItems(){
var list = Queue;

Expand All @@ -244,11 +242,14 @@ public async Task<CalendarWeek> GetCalendarForDate(string weeksMondayDate, bool
return forDate;
}

var request = HttpClientReq.CreateRequestMessage($"{calendarLanguage[CrunOptions.SelectedCalendarLanguage ?? "de"]}?filter=premium&date={weeksMondayDate}", HttpMethod.Get, false, false, null);
var request = calendarLanguage.ContainsKey(CrunOptions.SelectedCalendarLanguage ?? "de")
? HttpClientReq.CreateRequestMessage($"{calendarLanguage[CrunOptions.SelectedCalendarLanguage ?? "de"]}?filter=premium&date={weeksMondayDate}", HttpMethod.Get, false, false, null)
: HttpClientReq.CreateRequestMessage($"{calendarLanguage["en-us"]}?filter=premium&date={weeksMondayDate}", HttpMethod.Get, false, false, null);


request.Headers.Accept.ParseAdd("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
request.Headers.AcceptEncoding.ParseAdd("gzip, deflate, br");

var response = await HttpClientReq.Instance.SendHttpRequest(request);

CalendarWeek week = new CalendarWeek();
Expand Down Expand Up @@ -338,9 +339,9 @@ public async Task AddEpisodeToQue(string epId, string crLocale, List<string> dub
return;
}

var sList = await CrEpisode.EpisodeData((CrunchyEpisode)episodeL,updateHistory);
var sList = await CrEpisode.EpisodeData((CrunchyEpisode)episodeL, updateHistory);
var selected = CrEpisode.EpisodeMeta(sList, dubLang);

if (CrunOptions.IncludeVideoDescription){
if (selected.Data is{ Count: > 0 }){
var episode = await CrEpisode.ParseEpisodeById(selected.Data.First().MediaId, string.IsNullOrEmpty(CrunOptions.DescriptionLang) ? DefaultLocale : CrunOptions.DescriptionLang, true);
Expand All @@ -356,21 +357,21 @@ public async Task AddEpisodeToQue(string epId, string crLocale, List<string> dub
if (!string.IsNullOrEmpty(historyEpisode.historyEpisode.SonarrEpisodeNumber)){
selected.EpisodeNumber = historyEpisode.historyEpisode.SonarrEpisodeNumber;
}

if (!string.IsNullOrEmpty(historyEpisode.historyEpisode.SonarrSeasonNumber)){
selected.Season = historyEpisode.historyEpisode.SonarrSeasonNumber;
}
}
}

if (!string.IsNullOrEmpty(historyEpisode.downloadDirPath)){
selected.DownloadPath = historyEpisode.downloadDirPath;
}
}

Queue.Add(selected);


if (selected.Data.Count < dubLang.Count){
Console.WriteLine("Added Episode to Queue but couldn't find all selected dubs");
MessageBus.Current.SendMessage(new ToastMessage($"Added episode to the queue but couldn't find all selected dubs", ToastType.Warning, 2));
Expand Down Expand Up @@ -410,7 +411,7 @@ public async Task AddSeriesToQueue(CrunchySeriesList list, CrunchyMultiDownload
crunchyEpMeta.DownloadPath = historyEpisode.downloadDirPath;
}
}

if (CrunOptions.IncludeVideoDescription){
if (crunchyEpMeta.Data is{ Count: > 0 }){
var episode = await CrEpisode.ParseEpisodeById(crunchyEpMeta.Data.First().MediaId, string.IsNullOrEmpty(CrunOptions.DescriptionLang) ? DefaultLocale : CrunOptions.DescriptionLang, true);
Expand Down Expand Up @@ -1210,7 +1211,7 @@ private async Task<DownloadResponse> DownloadMediaList(CrunchyEpMeta data, CrDow
Doing = "Decrypting video"
};
Queue.Refresh();
var decryptVideo = await Helpers.ExecuteCommandAsyncWorkDir("mp4decrypt", CfgManager.PathMP4Decrypt, commandVideo,tempTsFileWorkDir);
var decryptVideo = await Helpers.ExecuteCommandAsyncWorkDir("mp4decrypt", CfgManager.PathMP4Decrypt, commandVideo, tempTsFileWorkDir);

if (!decryptVideo.IsOk){
Console.Error.WriteLine($"Decryption failed with exit code {decryptVideo.ErrorCode}");
Expand All @@ -1220,6 +1221,7 @@ private async Task<DownloadResponse> DownloadMediaList(CrunchyEpMeta data, CrDow
} catch (IOException ex){
Console.WriteLine($"An error occurred: {ex.Message}");
}

return new DownloadResponse{
Data = files,
Error = dlFailed,
Expand Down Expand Up @@ -1274,7 +1276,7 @@ private async Task<DownloadResponse> DownloadMediaList(CrunchyEpMeta data, CrDow
Doing = "Decrypting audio"
};
Queue.Refresh();
var decryptAudio = await Helpers.ExecuteCommandAsyncWorkDir("mp4decrypt", CfgManager.PathMP4Decrypt, commandAudio,tempTsFileWorkDir);
var decryptAudio = await Helpers.ExecuteCommandAsyncWorkDir("mp4decrypt", CfgManager.PathMP4Decrypt, commandAudio, tempTsFileWorkDir);

if (!decryptAudio.IsOk){
Console.Error.WriteLine($"Decryption failed with exit code {decryptAudio.ErrorCode}");
Expand All @@ -1283,6 +1285,7 @@ private async Task<DownloadResponse> DownloadMediaList(CrunchyEpMeta data, CrDow
} catch (IOException ex){
Console.WriteLine($"An error occurred: {ex.Message}");
}

return new DownloadResponse{
Data = files,
Error = dlFailed,
Expand Down
2 changes: 1 addition & 1 deletion CRD/ViewModels/CalendarPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public CalendarPageViewModel(){

CustomCalendar = Crunchyroll.Instance.CrunOptions.CustomCalendar;
HideDubs = Crunchyroll.Instance.CrunOptions.CalendarHideDubs;
HideDubs = Crunchyroll.Instance.CrunOptions.CalendarFilterByAirDate;
FilterByAirDate = Crunchyroll.Instance.CrunOptions.CalendarFilterByAirDate;

ComboBoxItem? dubfilter = CalendarDubFilter.FirstOrDefault(a => a.Content != null && (string)a.Content == Crunchyroll.Instance.CrunOptions.CalendarDubFilter) ?? null;
CurrentCalendarDubFilter = dubfilter ?? CalendarDubFilter[0];
Expand Down

0 comments on commit 53158b2

Please sign in to comment.