Skip to main content

tango_core/entities/
video.rs

1use sea_orm::entity::prelude::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
5#[sea_orm(table_name = "videos")]
6pub struct Model {
7    #[sea_orm(primary_key, auto_increment = false)]
8    pub id: String,
9    pub channel_id: String,
10    pub title: String,
11    #[sea_orm(column_type = "Text")]
12    pub description: String,
13    pub published_at: DateTimeWithTimeZone,
14    pub thumbnail_url: String,
15    #[sea_orm(column_type = "JsonBinary", nullable)]
16    pub thumbnails: Option<serde_json::Value>,
17    /// Whole seconds. Both backends report duration differently on the wire;
18    /// the harvester normalizes them before writing.
19    pub duration_seconds: Option<i32>,
20    #[sea_orm(column_type = "JsonBinary", nullable)]
21    pub tags: Option<serde_json::Value>,
22    pub category_id: Option<String>,
23    pub view_count: Option<i64>,
24    pub like_count: Option<i64>,
25    pub comment_count: Option<i64>,
26    pub default_language: Option<String>,
27    pub live_broadcast_content: Option<String>,
28    /// Which channel tab this video was harvested from. See ChannelAbout for
29    /// why the remaining channel statistics are nullable.
30    pub source_tab: Option<String>,
31    pub stats_refreshed_at: Option<DateTimeWithTimeZone>,
32    /// Caption tracks the yt-dlp backend reported, as `{"manual": [...],
33    /// "auto": [...]}`.
34    ///
35    /// `None` means *unknown*, not *none*. The v3 backend cannot see caption
36    /// tracks - it would need a separate quota-costing `captions.list` call per
37    /// video - so a v3-only harvest leaves this NULL. A source policy reading
38    /// NULL as "this video has no captions" would skip videos that have them,
39    /// which is why this is nullable and never defaulted to an empty object.
40    #[sea_orm(column_type = "JsonBinary", nullable)]
41    pub subtitle_availability: Option<serde_json::Value>,
42    /// Whether the video has captions at all, as a yes/no both backends can
43    /// answer.
44    ///
45    /// `Some(false)` is the only value that lets a transcript fetch be skipped.
46    /// `None` is unknown - the v3 backend has not asked - and a planner reading
47    /// it as "no captions" would skip videos that have them.
48    pub captions_available: Option<bool>,
49    pub created_at: DateTimeWithTimeZone,
50    pub updated_at: DateTimeWithTimeZone,
51    pub transcript_status: String,
52    /// Outcome of a chapter fetch: `pending`, `fetched`, `no_chapters`, or
53    /// `failed`. Free text with no CHECK, exactly like `transcript_status`.
54    ///
55    /// `pending` is the insert default and means *unknown*; the v3 backend
56    /// cannot see chapters, so a v3-only harvest leaves this pending until
57    /// `tango-rs chapters` (or a later yt-dlp harvest) fills it.
58    pub chapters_status: String,
59}
60
61#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
62pub enum Relation {
63    #[sea_orm(
64        belongs_to = "super::channel::Entity",
65        from = "Column::ChannelId",
66        to = "super::channel::Column::Id"
67    )]
68    Channel,
69}
70
71impl Related<super::channel::Entity> for Entity {
72    fn to() -> RelationDef {
73        Relation::Channel.def() // Changed from .into_ref() to .def()
74    }
75}
76
77impl ActiveModelBehavior for ActiveModel {}