Fix - Chapters failed for series with only one dub https://github.com/Crunchy-DL/Crunchy-Downloader/issues/83
This commit is contained in:
parent
335a2a8bc5
commit
c7a2ef5af7
@ -565,7 +565,7 @@ public class CrunchyrollManager{
|
|||||||
List<string> compiledChapters = new List<string>();
|
List<string> compiledChapters = new List<string>();
|
||||||
|
|
||||||
if (options.Chapters){
|
if (options.Chapters){
|
||||||
await ParseChapters(primaryVersion.Guid, compiledChapters);
|
await ParseChapters(primaryVersion.Guid ?? mediaGuid, compiledChapters);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -1664,7 +1664,7 @@ public class CrunchyrollManager{
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
private async Task ParseChapters(string currentMediaId, List<string> compiledChapters){
|
private async Task<bool> ParseChapters(string currentMediaId, List<string> compiledChapters){
|
||||||
var showRequest = HttpClientReq.CreateRequestMessage($"https://static.crunchyroll.com/skip-events/production/{currentMediaId}.json", HttpMethod.Get, true, true, null);
|
var showRequest = HttpClientReq.CreateRequestMessage($"https://static.crunchyroll.com/skip-events/production/{currentMediaId}.json", HttpMethod.Get, true, true, null);
|
||||||
|
|
||||||
var showRequestResponse = await HttpClientReq.Instance.SendHttpRequest(showRequest);
|
var showRequestResponse = await HttpClientReq.Instance.SendHttpRequest(showRequest);
|
||||||
@ -1698,6 +1698,7 @@ public class CrunchyrollManager{
|
|||||||
}
|
}
|
||||||
} catch (Exception ex){
|
} catch (Exception ex){
|
||||||
Console.Error.WriteLine($"Error parsing JSON response: {ex.Message}");
|
Console.Error.WriteLine($"Error parsing JSON response: {ex.Message}");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chapterData.Chapters.Count > 0){
|
if (chapterData.Chapters.Count > 0){
|
||||||
@ -1749,6 +1750,8 @@ public class CrunchyrollManager{
|
|||||||
compiledChapters.Add($"CHAPTER{chapterNumber}NAME={formattedChapterType} End");
|
compiledChapters.Add($"CHAPTER{chapterNumber}NAME={formattedChapterType} End");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
Console.WriteLine("Chapter request failed, attempting old API ");
|
Console.WriteLine("Chapter request failed, attempting old API ");
|
||||||
@ -1786,9 +1789,13 @@ public class CrunchyrollManager{
|
|||||||
chapterNumber = (compiledChapters.Count / 2) + 1;
|
chapterNumber = (compiledChapters.Count / 2) + 1;
|
||||||
compiledChapters.Add($"CHAPTER{chapterNumber}={endFormatted}");
|
compiledChapters.Add($"CHAPTER{chapterNumber}={endFormatted}");
|
||||||
compiledChapters.Add($"CHAPTER{chapterNumber}NAME=Episode");
|
compiledChapters.Add($"CHAPTER{chapterNumber}NAME=Episode");
|
||||||
} else{
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("Old Chapter API request failed");
|
Console.WriteLine("Old Chapter API request failed");
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,12 +5,26 @@ namespace CRD.Utils.JsonConv;
|
|||||||
|
|
||||||
public class UtcToLocalTimeConverter : JsonConverter<DateTime>{
|
public class UtcToLocalTimeConverter : JsonConverter<DateTime>{
|
||||||
public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer){
|
public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer){
|
||||||
|
try{
|
||||||
return reader.Value switch{
|
return reader.Value switch{
|
||||||
null => DateTime.MinValue,
|
null => DateTime.MinValue,
|
||||||
DateTime dateTime when dateTime.Kind == DateTimeKind.Utc => dateTime.ToLocalTime(),
|
DateTime dateTime when dateTime.Kind == DateTimeKind.Utc => dateTime.ToLocalTime(),
|
||||||
DateTime dateTime => dateTime,
|
DateTime dateTime => dateTime,
|
||||||
_ => throw new JsonSerializationException($"Unexpected token parsing date. Expected DateTime, got {reader.Value.GetType()}.")
|
string dateString => TryParseDateTime(dateString),
|
||||||
|
_ => throw new JsonSerializationException($"Unexpected token parsing date. Expected DateTime or string, got {reader.Value?.GetType()}.")
|
||||||
};
|
};
|
||||||
|
} catch (Exception ex){
|
||||||
|
Console.Error.WriteLine("Error deserializing DateTime", ex);
|
||||||
|
}
|
||||||
|
return DateTime.UnixEpoch;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DateTime TryParseDateTime(string dateString){
|
||||||
|
if (DateTime.TryParse(dateString, out DateTime parsedDate)){
|
||||||
|
return parsedDate.Kind == DateTimeKind.Utc ? parsedDate.ToLocalTime() : parsedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new JsonSerializationException($"Invalid date string: {dateString}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer){
|
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer){
|
||||||
|
Loading…
Reference in New Issue
Block a user