Skip to main content

rustybook_extractor/
video.rs

1use jsonpath_rust::JsonPath;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use rustybook_errors::ExtractionError;
5
6pub fn extract_video_info(payload: &Value) -> Result<Vec<Video>, ExtractionError> {
7    let video_data = payload.query("$..result.data.video")?;
8
9    let videos = video_data
10        .into_iter()
11        .map(|v| serde_json::from_value::<Video>(v.clone()))
12        .collect::<Result<Vec<_>, _>>()?;
13
14    Ok(videos)
15}
16
17#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
18pub struct Video {
19    pub id: String,
20    pub story: Story,
21}
22
23#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
24pub struct Story {
25    pub attachments: Vec<Attachment>,
26}
27
28#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
29pub struct Attachment {
30    pub media: Media,
31}
32
33#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
34pub struct Media {
35    #[serde(rename = "__typename")]
36    pub typename: String,
37    pub audio_availability: String,
38    pub autoplay_gating_result: String,
39    #[serde(rename = "breakingStatus")]
40    pub breaking_status: bool,
41    pub can_autoplay: bool,
42    pub can_use_oz: bool,
43    pub height: i64,
44    pub id: String,
45    #[serde(rename = "isPremiere")]
46    pub is_premiere: bool,
47    pub is_clipping_enabled: bool,
48    pub is_gaming_video: bool,
49    pub is_huddle: bool,
50    pub is_latency_menu_enabled: bool,
51    pub is_latency_sensitive_broadcast: bool,
52    pub is_live_streaming: bool,
53    pub is_live_trace_enabled: bool,
54    pub is_looping: bool,
55    pub is_ncsr: bool,
56    pub is_podcast_video: bool,
57    pub is_spherical: bool,
58    pub is_spherical_enabled: bool,
59    pub is_video_broadcast: bool,
60    #[serde(rename = "liveViewerCount")]
61    pub live_viewer_count: i64,
62    pub live_rewind_enabled: bool,
63    pub loop_count: i64,
64    pub owner: Owner,
65    pub permalink_url: String,
66    pub playable_duration_in_ms: i64,
67    pub preferred_thumbnail: PreferredThumbnail,
68    pub publish_time: i64,
69    pub url: String,
70    #[serde(rename = "videoDeliveryLegacyFields")]
71    pub video_delivery_legacy_fields: VideoDeliveryLegacyFields,
72}
73
74#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
75pub struct Owner {
76    #[serde(rename = "__isVideoOwner")]
77    pub is_video_owner: String,
78    #[serde(rename = "__typename")]
79    pub typename: String,
80    pub id: String,
81}
82
83#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
84pub struct PreferredThumbnail {
85    pub id: String,
86    pub image: Image,
87    pub image_preview_payload: Value,
88}
89
90#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
91pub struct Image {
92    pub uri: String,
93}
94
95#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
96pub struct VideoDeliveryLegacyFields {
97    pub browser_native_hd_url: String,
98    pub browser_native_sd_url: String,
99    pub dash_manifest_url: String,
100    pub dash_manifest_xml_string: String,
101    pub id: String,
102}