Fix - FFMPEG default dub/sub
Fix - Calendar/Search not working if the downloader wasn't used for a while
This commit is contained in:
Elwador 2024-08-03 14:44:04 +02:00
parent 93e71d3786
commit b451120bde
6 changed files with 96 additions and 110 deletions

View File

@ -45,7 +45,7 @@ public class CrAuth{
PreferredContentSubtitleLanguage = "de-DE" PreferredContentSubtitleLanguage = "de-DE"
}; };
CrunchyrollManager.Instance.CmsToken = new CrCmsToken(); // CrunchyrollManager.Instance.CmsToken = new CrCmsToken();
} }
@ -171,7 +171,7 @@ public class CrAuth{
await GetProfile(); await GetProfile();
} }
await GetCmsToken(); // await GetCmsToken();
} }
public async Task RefreshToken(bool needsToken){ public async Task RefreshToken(bool needsToken){
@ -210,52 +210,52 @@ public class CrAuth{
Console.Error.WriteLine("Refresh Token Auth Failed"); Console.Error.WriteLine("Refresh Token Auth Failed");
} }
await GetCmsToken(); // await GetCmsToken();
} }
public async Task GetCmsToken(){ // public async Task GetCmsToken(){
if (crunInstance.Token?.access_token == null){ // if (crunInstance.Token?.access_token == null){
Console.Error.WriteLine($"Missing Access Token: {crunInstance.Token?.access_token}"); // Console.Error.WriteLine($"Missing Access Token: {crunInstance.Token?.access_token}");
return; // return;
} // }
//
var request = HttpClientReq.CreateRequestMessage(Api.BetaCmsToken, HttpMethod.Get, true, true, null); // var request = HttpClientReq.CreateRequestMessage(Api.BetaCmsToken, HttpMethod.Get, true, true, null);
//
var response = await HttpClientReq.Instance.SendHttpRequest(request); // var response = await HttpClientReq.Instance.SendHttpRequest(request);
//
if (response.IsOk){ // if (response.IsOk){
crunInstance.CmsToken = JsonConvert.DeserializeObject<CrCmsToken>(response.ResponseContent, crunInstance.SettingsJsonSerializerSettings); // crunInstance.CmsToken = JsonConvert.DeserializeObject<CrCmsToken>(response.ResponseContent, crunInstance.SettingsJsonSerializerSettings);
} else{ // } else{
Console.Error.WriteLine("CMS Token Auth Failed"); // Console.Error.WriteLine("CMS Token Auth Failed");
} // }
} // }
//
public async Task GetCmsData(){ // public async Task GetCmsData(){
if (crunInstance.CmsToken?.Cms == null){ // if (crunInstance.CmsToken?.Cms == null){
Console.Error.WriteLine("Missing CMS Token"); // Console.Error.WriteLine("Missing CMS Token");
return; // return;
} // }
//
UriBuilder uriBuilder = new UriBuilder(Api.BetaCms + crunInstance.CmsToken.Cms.Bucket + "/index?"); // UriBuilder uriBuilder = new UriBuilder(Api.BetaCms + crunInstance.CmsToken.Cms.Bucket + "/index?");
//
NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query); // NameValueCollection query = HttpUtility.ParseQueryString(uriBuilder.Query);
//
query["preferred_audio_language"] = "ja-JP"; // query["preferred_audio_language"] = "ja-JP";
query["Policy"] = crunInstance.CmsToken.Cms.Policy; // query["Policy"] = crunInstance.CmsToken.Cms.Policy;
query["Signature"] = crunInstance.CmsToken.Cms.Signature; // query["Signature"] = crunInstance.CmsToken.Cms.Signature;
query["Key-Pair-Id"] = crunInstance.CmsToken.Cms.KeyPairId; // query["Key-Pair-Id"] = crunInstance.CmsToken.Cms.KeyPairId;
//
uriBuilder.Query = query.ToString(); // uriBuilder.Query = query.ToString();
//
var request = new HttpRequestMessage(HttpMethod.Get, uriBuilder.ToString()); // var request = new HttpRequestMessage(HttpMethod.Get, uriBuilder.ToString());
//
var response = await HttpClientReq.Instance.SendHttpRequest(request); // var response = await HttpClientReq.Instance.SendHttpRequest(request);
//
if (response.IsOk){ // if (response.IsOk){
Console.WriteLine(response.ResponseContent); // Console.WriteLine(response.ResponseContent);
} else{ // } else{
Console.Error.WriteLine("Failed to Get CMS Index"); // Console.Error.WriteLine("Failed to Get CMS Index");
} // }
} // }
} }

View File

@ -15,10 +15,10 @@ public class CrEpisode(){
private readonly CrunchyrollManager crunInstance = CrunchyrollManager.Instance; private readonly CrunchyrollManager crunInstance = CrunchyrollManager.Instance;
public async Task<CrunchyEpisode?> ParseEpisodeById(string id, string crLocale, bool forcedLang = false){ public async Task<CrunchyEpisode?> ParseEpisodeById(string id, string crLocale, bool forcedLang = false){
if (crunInstance.CmsToken?.Cms == null){ // if (crunInstance.CmsToken?.Cms == null){
Console.Error.WriteLine("Missing CMS Access Token"); // Console.Error.WriteLine("Missing CMS Access Token");
return null; // return null;
} // }
NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query); NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query);
@ -130,30 +130,7 @@ public class CrEpisode(){
if (!serieshasversions){ if (!serieshasversions){
Console.WriteLine("Couldn\'t find versions on episode, fell back to old method."); Console.WriteLine("Couldn\'t find versions on episode, fell back to old method.");
} }
// crunchySeriesList.Data = sortedEpisodes;
//
//
// var images = (episode.EpisodeAndLanguages.Items[0].Images?.Thumbnail ?? new List<List<Image>>{ new List<Image>{ new Image{ Source = "/notFound.png" } } });
// var seconds = (int)Math.Floor(episode.EpisodeAndLanguages.Items[0].DurationMs / 1000.0);
//
// var newEpisode = new Episode{
// E = episode.Key.StartsWith("E") ? episode.Key.Substring(1) : episode.Key,
// Lang = episode.EpisodeAndLanguages.Langs.Select(a => a.Code).ToList(),
// Name = episode.EpisodeAndLanguages.Items[0].Title,
// Season = Helpers.ExtractNumberAfterS(episode.EpisodeAndLanguages.Items[0].Identifier) ?? episode.EpisodeAndLanguages.Items[0].SeasonNumber.ToString(),
// SeriesTitle = Regex.Replace(episode.EpisodeAndLanguages.Items[0].SeriesTitle, @"\(\w+ Dub\)", "").TrimEnd(),
// SeasonTitle = Regex.Replace(episode.EpisodeAndLanguages.Items[0].SeasonTitle, @"\(\w+ Dub\)", "").TrimEnd(),
// EpisodeNum = episode.EpisodeAndLanguages.Items[0].EpisodeNumber?.ToString() ?? episode.EpisodeAndLanguages.Items[0].Episode ?? "?",
// Id = episode.EpisodeAndLanguages.Items[0].SeasonId,
// Img = images[images.Count / 2].FirstOrDefault().Source,
// Description = episode.EpisodeAndLanguages.Items[0].Description,
// Time = $"{seconds / 60}:{seconds % 60:D2}" // Ensures two digits for seconds.
// };
//
// CrunchySeriesList crunchySeriesList = new CrunchySeriesList();
return episode; return episode;
} }
@ -243,6 +220,7 @@ public class CrEpisode(){
} }
public async Task<CrBrowseEpisodeBase?> GetNewEpisodes(string? crLocale, int requestAmount,DateTime? firstWeekDay = null , bool forcedLang = false){ public async Task<CrBrowseEpisodeBase?> GetNewEpisodes(string? crLocale, int requestAmount,DateTime? firstWeekDay = null , bool forcedLang = false){
await crunInstance.CrAuth.RefreshToken(true);
CrBrowseEpisodeBase? complete = new CrBrowseEpisodeBase(); CrBrowseEpisodeBase? complete = new CrBrowseEpisodeBase();
complete.Data =[]; complete.Data =[];

View File

@ -234,14 +234,16 @@ public class CrSeries(){
newKey = $"{(isSpecial ? "SP" : 'E')}{(isSpecial ? (specialIndex + " " + item.Items[0].Id) : epIndex + "")}"; newKey = $"{(isSpecial ? "SP" : 'E')}{(isSpecial ? (specialIndex + " " + item.Items[0].Id) : epIndex + "")}";
} }
episodes.Remove(key);
int counter = 1; int counter = 1;
string originalKey = newKey; string originalKey = newKey;
while (episodes.ContainsKey(newKey)){ while (episodes.ContainsKey(newKey)){
newKey = originalKey + "_" + counter; newKey = originalKey + "_" + counter;
counter++; counter++;
} }
episodes.Remove(key);
episodes.Add(newKey, item); episodes.Add(newKey, item);
if (isSpecial){ if (isSpecial){
@ -389,6 +391,7 @@ public class CrSeries(){
} }
public async Task<CrSeriesSearch?> ParseSeriesById(string id, string? crLocale, bool forced = false){ public async Task<CrSeriesSearch?> ParseSeriesById(string id, string? crLocale, bool forced = false){
await crunInstance.CrAuth.RefreshToken(true);
NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query); NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query);
query["preferred_audio_language"] = "ja-JP"; query["preferred_audio_language"] = "ja-JP";
@ -420,6 +423,7 @@ public class CrSeries(){
} }
public async Task<CrSeriesBase?> SeriesById(string id, string? crLocale, bool forced = false){ public async Task<CrSeriesBase?> SeriesById(string id, string? crLocale, bool forced = false){
await crunInstance.CrAuth.RefreshToken(true);
NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query); NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query);
query["preferred_audio_language"] = "ja-JP"; query["preferred_audio_language"] = "ja-JP";
@ -451,6 +455,7 @@ public class CrSeries(){
public async Task<CrSearchSeriesBase?> Search(string searchString, string? crLocale){ public async Task<CrSearchSeriesBase?> Search(string searchString, string? crLocale){
await crunInstance.CrAuth.RefreshToken(true);
NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query); NameValueCollection query = HttpUtility.ParseQueryString(new UriBuilder().Query);
if (!string.IsNullOrEmpty(crLocale)){ if (!string.IsNullOrEmpty(crLocale)){

View File

@ -28,7 +28,7 @@ namespace CRD.Downloader.Crunchyroll;
public class CrunchyrollManager{ public class CrunchyrollManager{
public CrToken? Token; public CrToken? Token;
public CrCmsToken? CmsToken; // public CrCmsToken? CmsToken;
public CrProfile Profile = new(); public CrProfile Profile = new();
private readonly Lazy<CrDownloadOptions> _optionsLazy; private readonly Lazy<CrDownloadOptions> _optionsLazy;
@ -382,16 +382,16 @@ public class CrunchyrollManager{
} }
private async Task<DownloadResponse> DownloadMediaList(CrunchyEpMeta data, CrDownloadOptions options){ private async Task<DownloadResponse> DownloadMediaList(CrunchyEpMeta data, CrDownloadOptions options){
if (CmsToken?.Cms == null){ // if (CmsToken?.Cms == null){
Console.WriteLine("Missing CMS Token"); // Console.WriteLine("Missing CMS Token");
MainWindow.Instance.ShowError("Missing CMS Token - are you signed in?"); // MainWindow.Instance.ShowError("Missing CMS Token - are you signed in?");
return new DownloadResponse{ // return new DownloadResponse{
Data = new List<DownloadedMedia>(), // Data = new List<DownloadedMedia>(),
Error = true, // Error = true,
FileName = "./unknown", // FileName = "./unknown",
ErrorText = "Login problem" // ErrorText = "Login problem"
}; // };
} // }
if (Profile.Username == "???"){ if (Profile.Username == "???"){
MainWindow.Instance.ShowError("User Account not recognized - are you signed in?"); MainWindow.Instance.ShowError("User Account not recognized - are you signed in?");
@ -453,16 +453,16 @@ public class CrunchyrollManager{
List<DownloadedMedia> files = new List<DownloadedMedia>(); List<DownloadedMedia> files = new List<DownloadedMedia>();
if (data.Data != null && data.Data.All(a => a.Playback == null)){ // if (data.Data != null && data.Data.All(a => a.Playback == null)){
Console.WriteLine("No Video Data found - Are you trying to download a premium episode without havíng a premium account?"); // Console.WriteLine("No Video Data found - Are you trying to download a premium episode without havíng a premium account?");
MainWindow.Instance.ShowError("No Video Data found - Are you trying to download a premium episode without havíng a premium account?"); // MainWindow.Instance.ShowError("No Video Data found - Are you trying to download a premium episode without havíng a premium account?");
return new DownloadResponse{ // return new DownloadResponse{
Data = files, // Data = files,
Error = true, // Error = true,
FileName = "./unknown", // FileName = "./unknown",
ErrorText = "Video Data not found" // ErrorText = "Video Data not found"
}; // };
} // }
bool dlFailed = false; bool dlFailed = false;

View File

@ -207,5 +207,6 @@ public enum SonarrSeriesType{
public enum SonarrStatus{ public enum SonarrStatus{
Continuing, Continuing,
Upcoming, Upcoming,
Ended Ended,
Deleted
}; };

View File

@ -56,6 +56,11 @@ public class Merger{
args.Add($"-i \"{aud.Path}\""); args.Add($"-i \"{aud.Path}\"");
metaData.Add($"-map {index}:a"); metaData.Add($"-map {index}:a");
metaData.Add($"-metadata:s:a:{audioIndex} language={aud.Language.Code}"); metaData.Add($"-metadata:s:a:{audioIndex} language={aud.Language.Code}");
if (options.Defaults.Audio.Code == aud.Language.Code){
metaData.Add($"-disposition:a:{audioIndex} default");
} else{
metaData.Add($"-disposition:a:{audioIndex} 0");
}
index++; index++;
audioIndex++; audioIndex++;
} }
@ -75,20 +80,17 @@ public class Merger{
} }
args.Add($"-i \"{sub.value.File}\""); args.Add($"-i \"{sub.value.File}\"");
} metaData.Add($"-map {index}:s");
if (options.Defaults.Sub.Code == sub.value.Language.Code && CrunchyrollManager.Instance.CrunOptions.DefaultSubSigns == sub.value.Signs && sub.value.ClosedCaption == false){
if (options.Output.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)){ args.Add($"-disposition:s:{sub.i} default");
if (options.Fonts != null){ } else{
int fontIndex = 0; args.Add($"-disposition:s:{sub.i} 0");
foreach (var font in options.Fonts){
args.Add($"-attach {font.Path} -metadata:s:t:{fontIndex} mimetype={font.Mime}");
fontIndex++;
}
} }
index++;
} }
args.AddRange(metaData); args.AddRange(metaData);
args.AddRange(options.Subtitles.Select((sub, subIndex) => $"-map {subIndex + index}")); // args.AddRange(options.Subtitles.Select((sub, subIndex) => $"-map {subIndex + index}"));
args.Add("-c:v copy"); args.Add("-c:v copy");
args.Add("-c:a copy"); args.Add("-c:a copy");
args.Add(options.Output.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) ? "-c:s mov_text" : "-c:s ass"); args.Add(options.Output.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) ? "-c:s mov_text" : "-c:s ass");