[CHANGE] Check for video id else throw exception.

This commit is contained in:
max
2025-10-23 18:06:26 +02:00
parent 97f7f5dcf6
commit ed9cb7eff1

View File

@@ -1,3 +1,4 @@
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
using DotBased.Logging;
@@ -21,13 +22,19 @@ public class YouTubeVideoJsonConverter : JsonConverter<YouTubeVideo>
var videoDetails = root.GetProperty("videoDetails");
var playerConfigJson = root.GetProperty("playerConfig");
var microformat = root.GetProperty("microformat").GetProperty("playerMicroformatRenderer");
var videoId = videoDetails.GetProperty("videoId").GetString() ?? microformat.GetProperty("externalVideoId").GetString();
if (string.IsNullOrEmpty(videoId))
{
throw new SerializationException("Failed to get videoId");
}
var thumbnails = JsonParser.ExtractWebImages(videoDetails.GetProperty("thumbnail"));
thumbnails.AddRange(JsonParser.ExtractWebImages(microformat.GetProperty("thumbnail")));
var video = new YouTubeVideo
{
VideoId = videoDetails.GetProperty("videoId").GetString() ?? "",
VideoId = videoId,
Title = JsonParser.ExtractTextOrHtml(microformat.GetProperty("title")),
Description = JsonParser.ExtractTextOrHtml(microformat.GetProperty("description")),
ViewCount = videoDetails.GetProperty("viewCount").GetInt32(),