[CHANGE] Check for video id else throw exception.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using DotBased.Logging;
|
using DotBased.Logging;
|
||||||
@@ -22,12 +23,18 @@ public class YouTubeVideoJsonConverter : JsonConverter<YouTubeVideo>
|
|||||||
var playerConfigJson = root.GetProperty("playerConfig");
|
var playerConfigJson = root.GetProperty("playerConfig");
|
||||||
var microformat = root.GetProperty("microformat").GetProperty("playerMicroformatRenderer");
|
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"));
|
var thumbnails = JsonParser.ExtractWebImages(videoDetails.GetProperty("thumbnail"));
|
||||||
thumbnails.AddRange(JsonParser.ExtractWebImages(microformat.GetProperty("thumbnail")));
|
thumbnails.AddRange(JsonParser.ExtractWebImages(microformat.GetProperty("thumbnail")));
|
||||||
|
|
||||||
var video = new YouTubeVideo
|
var video = new YouTubeVideo
|
||||||
{
|
{
|
||||||
VideoId = videoDetails.GetProperty("videoId").GetString() ?? "",
|
VideoId = videoId,
|
||||||
Title = JsonParser.ExtractTextOrHtml(microformat.GetProperty("title")),
|
Title = JsonParser.ExtractTextOrHtml(microformat.GetProperty("title")),
|
||||||
Description = JsonParser.ExtractTextOrHtml(microformat.GetProperty("description")),
|
Description = JsonParser.ExtractTextOrHtml(microformat.GetProperty("description")),
|
||||||
ViewCount = videoDetails.GetProperty("viewCount").GetInt32(),
|
ViewCount = videoDetails.GetProperty("viewCount").GetInt32(),
|
||||||
|
|||||||
Reference in New Issue
Block a user