Hey everyone!
I'm trying to parse information about YouTube playlists as they are given by yt-dlp with the command yt-dlp -j url
(these examples are simplified)
The json it gives out regarding a playlist's format information looks something like this:
{
"id": "...",
"title": "Testing",
"entries": [
{
"id": "...",
"title": "First Video Title",
"formats": [
{
format1_for_video1: "!!!"
},
{
format2_for_video1: "!!!"
}
]
},
{
"id": "...",
"title": "Second Video Title",
"formats": [
{
format1_for_video2: "!!!"
},
{
format2_for_video2: "!!!"
}
]
}
]
}
What I need is a structure which can hold all the Videos in a playlist, each one having its own list of formats
In this example that would look something like this
all_videos {
video_1: [
format_1: [...]
format_2: [...]
]
video_2: [
format_1: [...]
format_2: [...]
]
}
I've tried implementing it like this:
A structure which holds all the information I need about a particular format:
#[derive(Deserialize, Serialize, Debug, PartialOrd, PartialEq)]
struct VideoFormat {
title: String,
fps: f64
....
}
Something which represent a Video, which can support multiple formats:
#[derive(Deserialize, Serialize, Debug)]
struct VideoSpecs {
formats: Vec<VideoFormat>,
}
My problem is that I can't parse the "entries" array properly because none of the videos have a name, since they are just elements of an array in the JSON.
For example I've tried doing something like this:
#[derive(Deserialize, Serialize, Debug)]
struct dummy {
entries: Vec<VideoSpecs>,
}
but I get errors like this:
invalid type: null, expected struct VideoSpecs at line 1 column 1573533
(the full json is very long and only on 1 line)
Does anyone know how I could do this? Maybe some way of ignoring variable names (?)
Thank you for reading : )