fix
This commit is contained in:
parent
31a5271e6e
commit
b62fb0e719
8 changed files with 160 additions and 10 deletions
|
@ -42,7 +42,7 @@ impl Library {
|
|||
}
|
||||
|
||||
pub async fn get_directory_videos(&self, dir: &str) -> Vec<Video> {
|
||||
sqlx::query_as("SELECT * FROM videos WHERE directory = ?1")
|
||||
sqlx::query_as("SELECT * FROM videos WHERE directory = $1")
|
||||
.bind(dir)
|
||||
.fetch_all(&self.conn)
|
||||
.await
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use crate::{get_pg, pages::ToAPI, yt_meta};
|
||||
use crate::{
|
||||
get_pg,
|
||||
pages::ToAPI,
|
||||
yt_meta::{self, get_vid_duration},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::prelude::FromRow;
|
||||
|
@ -10,7 +14,6 @@ pub struct YouTubeMeta {
|
|||
pub title: String,
|
||||
pub uploader_name: String,
|
||||
pub uploader_id: String,
|
||||
pub duration: i64,
|
||||
pub views: i64,
|
||||
pub upload_date: chrono::NaiveDate,
|
||||
}
|
||||
|
@ -52,7 +55,7 @@ pub struct Video {
|
|||
pub id: uuid::Uuid,
|
||||
pub directory: String,
|
||||
pub path: String,
|
||||
pub duration: i64,
|
||||
pub duration: f64,
|
||||
pub title: String,
|
||||
youtube_id: Option<String>,
|
||||
}
|
||||
|
@ -92,6 +95,8 @@ impl Video {
|
|||
|
||||
let mut tx = db.begin().await.unwrap();
|
||||
|
||||
let vid_duration = get_vid_duration(v).unwrap();
|
||||
|
||||
if let Some(meta) = yt_meta::get_youtube_metadata(v) {
|
||||
sqlx::query("INSERT INTO youtube_meta (id, title, description, uploader_name, uploader_id, duration, views, upload_date) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)")
|
||||
.bind(&meta.youtube_id().unwrap())
|
||||
|
@ -104,9 +109,10 @@ impl Video {
|
|||
.bind(&meta.upload_date())
|
||||
.execute(&mut *tx).await.unwrap();
|
||||
|
||||
let vid = sqlx::query_as("INSERT INTO videos (directory, path, title, youtube_id) VALUES ($1, $2, $3, $4, $5)")
|
||||
let vid = sqlx::query_as("INSERT INTO videos (directory, path, duration, title, youtube_id) VALUES ($1, $2, $3, $4, $5)")
|
||||
.bind(&dir)
|
||||
.bind(v.to_str().unwrap())
|
||||
.bind(vid_duration)
|
||||
.bind(meta.title())
|
||||
.bind(meta.youtube_id().unwrap())
|
||||
.fetch_one(&mut *tx).await.unwrap();
|
||||
|
@ -139,10 +145,11 @@ impl Video {
|
|||
}
|
||||
|
||||
let vid = sqlx::query_as(
|
||||
"INSERT INTO videos (directory, path, title) VALUES ($1, $2, $3, $4) RETURNING *",
|
||||
"INSERT INTO videos (directory, path, duration, title) VALUES ($1, $2, $3, $4) RETURNING *",
|
||||
)
|
||||
.bind(dir)
|
||||
.bind(v.to_str().unwrap())
|
||||
.bind(vid_duration)
|
||||
.bind(file_name)
|
||||
.fetch_one(&mut *tx)
|
||||
.await
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue