[CHANGE] Check for video id else throw exception.
This commit is contained in:
parent
97f7f5dcf6
commit
ed9cb7eff1
1 changed files with 8 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System.Runtime.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using DotBased.Logging;
|
||||
|
|
@ -22,12 +23,18 @@ public class YouTubeVideoJsonConverter : JsonConverter<YouTubeVideo>
|
|||
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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue