[CHANGE] Json video parser && video model
This commit is contained in:
@@ -1,34 +1,61 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
using Manager.YouTube.Models.Innertube;
|
using Manager.YouTube.Models.Innertube;
|
||||||
|
|
||||||
namespace Manager.YouTube.Models;
|
namespace Manager.YouTube.Models;
|
||||||
|
|
||||||
public class YouTubeVideo
|
public class YouTubeVideo
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("videoId")]
|
||||||
public required string VideoId { get; set; }
|
public required string VideoId { get; set; }
|
||||||
|
[JsonPropertyName("title")]
|
||||||
public string Title { get; set; } = "";
|
public string Title { get; set; } = "";
|
||||||
|
[JsonPropertyName("description")]
|
||||||
public string Description { get; set; } = "";
|
public string Description { get; set; } = "";
|
||||||
|
[JsonPropertyName("hashTags")]
|
||||||
public string[] HashTags { get; set; } = [];
|
public string[] HashTags { get; set; } = [];
|
||||||
|
[JsonPropertyName("viewCount")]
|
||||||
public long ViewCount { get; set; }
|
public long ViewCount { get; set; }
|
||||||
|
[JsonPropertyName("likeCount")]
|
||||||
public long LikeCount { get; set; }
|
public long LikeCount { get; set; }
|
||||||
|
[JsonPropertyName("channelId")]
|
||||||
public string ChannelId { get; set; } = "";
|
public string ChannelId { get; set; } = "";
|
||||||
|
[JsonPropertyName("author")]
|
||||||
public string Author { get; set; } = "";
|
public string Author { get; set; } = "";
|
||||||
|
[JsonPropertyName("playabilityStatus")]
|
||||||
public string PlayabilityStatus { get; set; } = "";
|
public string PlayabilityStatus { get; set; } = "";
|
||||||
|
[JsonPropertyName("lengthSeconds")]
|
||||||
public long LengthSeconds { get; set; }
|
public long LengthSeconds { get; set; }
|
||||||
|
[JsonPropertyName("isOwnerViewing")]
|
||||||
|
public bool IsOwnerViewing { get; set; }
|
||||||
|
[JsonPropertyName("allowRating")]
|
||||||
public bool AllowRating { get; set; }
|
public bool AllowRating { get; set; }
|
||||||
|
[JsonPropertyName("isCrawlable")]
|
||||||
public bool IsCrawlable { get; set; }
|
public bool IsCrawlable { get; set; }
|
||||||
|
[JsonPropertyName("isPrivate")]
|
||||||
public bool IsPrivate { get; set; }
|
public bool IsPrivate { get; set; }
|
||||||
|
[JsonPropertyName("isUnpluggedCorpus")]
|
||||||
public bool IsUnpluggedCorpus { get; set; }
|
public bool IsUnpluggedCorpus { get; set; }
|
||||||
|
[JsonPropertyName("isLive")]
|
||||||
public bool IsLive { get; set; }
|
public bool IsLive { get; set; }
|
||||||
public bool IsFamiliySave { get; set; }
|
[JsonPropertyName("isFamilySafe")]
|
||||||
|
public bool IsFamilySave { get; set; }
|
||||||
|
[JsonPropertyName("availableCountries")]
|
||||||
public string[] AvailableCountries { get; set; } = [];
|
public string[] AvailableCountries { get; set; } = [];
|
||||||
|
[JsonPropertyName("isUnlisted")]
|
||||||
public bool IsUnlisted { get; set; }
|
public bool IsUnlisted { get; set; }
|
||||||
|
[JsonPropertyName("hasYpcMetadata")]
|
||||||
public bool HasYpcMetadata { get; set; }
|
public bool HasYpcMetadata { get; set; }
|
||||||
|
[JsonPropertyName("publishDate")]
|
||||||
public DateTime PublishDate { get; set; }
|
public DateTime PublishDate { get; set; }
|
||||||
|
[JsonPropertyName("uploadDate")]
|
||||||
public DateTime UploadDate { get; set; }
|
public DateTime UploadDate { get; set; }
|
||||||
|
[JsonPropertyName("isShortsEligible")]
|
||||||
public bool IsShortsEligible { get; set; }
|
public bool IsShortsEligible { get; set; }
|
||||||
|
[JsonPropertyName("category")]
|
||||||
public string Category { get; set; } = "";
|
public string Category { get; set; } = "";
|
||||||
|
|
||||||
public StreamingData StreamingData { get; set; } = new();
|
public StreamingData StreamingData { get; set; } = new();
|
||||||
|
[JsonPropertyName("thumbnail")]
|
||||||
public List<WebImage> Thumbnails { get; set; } = [];
|
public List<WebImage> Thumbnails { get; set; } = [];
|
||||||
|
|
||||||
public PlayerConfig? PlayerConfig { get; set; }
|
public PlayerConfig? PlayerConfig { get; set; }
|
||||||
|
|||||||
51
Manager.YouTube/Parsers/Json/VideoJsonParser.cs
Normal file
51
Manager.YouTube/Parsers/Json/VideoJsonParser.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using DotBased.Monads;
|
||||||
|
using Manager.YouTube.Models;
|
||||||
|
using Manager.YouTube.Models.Parser;
|
||||||
|
|
||||||
|
namespace Manager.YouTube.Parsers.Json;
|
||||||
|
|
||||||
|
public static class VideoJsonParser
|
||||||
|
{
|
||||||
|
public static Result<YouTubeVideo> ParseVideoData(YouTubeVideoData videoData)
|
||||||
|
{
|
||||||
|
if (videoData.YouTubeInitialData == null || videoData.YouTubeInitialData.Count == 0)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("No initial video data found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var videoDetails = videoData.YouTubeInitialData["videoDetails"];
|
||||||
|
var microformat = videoData.YouTubeInitialData["microformat"]?["playerMicroformatRenderer"];
|
||||||
|
if (videoDetails == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("No video details found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (microformat == null)
|
||||||
|
{
|
||||||
|
return ResultError.Fail("No microformat found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
FlattenThumbnailArray(videoDetails);
|
||||||
|
FlattenThumbnailArray(microformat);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var video = videoDetails.Deserialize<YouTubeVideo>();
|
||||||
|
|
||||||
|
|
||||||
|
return ResultError.Fail("Not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FlattenThumbnailArray(JsonNode node)
|
||||||
|
{
|
||||||
|
var thumbnailsArray = node["thumbnail"]?["thumbnails"];
|
||||||
|
if (thumbnailsArray != null)
|
||||||
|
{
|
||||||
|
node["thumbnail"]?.ReplaceWith(thumbnailsArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user