feat: 保存视频标签,设置 video 和 page 的关系
This commit is contained in:
@@ -19,6 +19,19 @@ pub struct Model {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::video::Entity",
|
||||
from = "Column::VideoId",
|
||||
to = "super::video::Column::Id"
|
||||
)]
|
||||
Video,
|
||||
}
|
||||
|
||||
impl Related<super::video::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Video.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
@@ -22,12 +22,21 @@ pub struct Model {
|
||||
pub favtime: DateTime,
|
||||
pub handled: bool,
|
||||
pub valid: bool,
|
||||
pub tags: Option<String>,
|
||||
pub tags: Option<serde_json::Value>,
|
||||
pub single_page: Option<bool>,
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::page::Entity")]
|
||||
Page,
|
||||
}
|
||||
|
||||
impl Related<super::page::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Page.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
@@ -27,6 +27,15 @@ pub struct Tag {
|
||||
pub tag_name: String,
|
||||
}
|
||||
|
||||
impl serde::Serialize for Tag {
|
||||
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.tag_name)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct PageInfo {
|
||||
pub cid: i32,
|
||||
|
||||
@@ -34,6 +34,7 @@ pub async fn refresh_favorite(
|
||||
let video_stream = bili_favorite_list.into_video_stream().chunks(10);
|
||||
pin_mut!(video_stream);
|
||||
while let Some(videos_info) = video_stream.next().await {
|
||||
info!("handle videos: {}", videos_info.len());
|
||||
let exist_labels = exist_labels(&videos_info, &favorite_model, connection.as_ref()).await?;
|
||||
let should_break = videos_info
|
||||
.iter()
|
||||
@@ -50,10 +51,12 @@ pub async fn refresh_favorite(
|
||||
if !unrefreshed_video_models.is_empty() {
|
||||
for video_model in unrefreshed_video_models {
|
||||
let bili_video = Video::new(bili_client.clone(), video_model.bvid.clone());
|
||||
let tags = bili_video.get_tags().await?;
|
||||
let pages_info = bili_video.get_pages().await?;
|
||||
create_video_pages(&pages_info, &video_model, connection.as_ref()).await?;
|
||||
let mut video_active_model: video::ActiveModel = video_model.into();
|
||||
video_active_model.single_page = Set(Some(pages_info.len() == 1));
|
||||
video_active_model.tags = Set(Some(serde_json::to_value(tags).unwrap()));
|
||||
video_active_model.save(connection.as_ref()).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user