parent
4d32422bd6
commit
ce9351d9a6
4 changed files with 574 additions and 271 deletions
811
Cargo.lock
generated
811
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -12,6 +12,7 @@ use std::path::PathBuf;
|
||||||
pub struct YouTubeMeta {
|
pub struct YouTubeMeta {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
pub description: String,
|
||||||
pub uploader_name: String,
|
pub uploader_name: String,
|
||||||
pub uploader_id: String,
|
pub uploader_id: String,
|
||||||
pub views: i64,
|
pub views: i64,
|
||||||
|
@ -70,6 +71,13 @@ impl Video {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn youtube_meta(&self) -> Option<YouTubeMeta> {
|
||||||
|
if let Some(meta) = self.youtube_id.as_ref().map(|id| YouTubeMeta::get(id)) {
|
||||||
|
return meta.await;
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn has_path(path: &str) -> bool {
|
pub async fn has_path(path: &str) -> bool {
|
||||||
sqlx::query("SELECT id FROM videos WHERE path = $1")
|
sqlx::query("SELECT id FROM videos WHERE path = $1")
|
||||||
.bind(path)
|
.bind(path)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use maud::{html, PreEscaped};
|
use maud::{html, PreEscaped};
|
||||||
|
|
||||||
|
use crate::library::Video;
|
||||||
|
|
||||||
pub fn shell(content: PreEscaped<String>, title: &str) -> PreEscaped<String> {
|
pub fn shell(content: PreEscaped<String>, title: &str) -> PreEscaped<String> {
|
||||||
html! {
|
html! {
|
||||||
html {
|
html {
|
||||||
head {
|
head {
|
||||||
title=(title)
|
title { (title) };
|
||||||
};
|
};
|
||||||
body {
|
body {
|
||||||
(content)
|
(content)
|
||||||
|
@ -34,17 +36,17 @@ pub fn search_bar(query: &str) -> PreEscaped<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn video_element(video: &mut Video) -> PreEscaped<String> {
|
pub async fn video_element(video: &mut Video) -> PreEscaped<String> {
|
||||||
html!(
|
html!(
|
||||||
@let desc = video.description().unwrap_or_default().to_owned();
|
@let desc = video.youtube_meta().await.map(|x| x.description);
|
||||||
@let video_hash = video.hash();
|
@let video_id = video.id;
|
||||||
article class="container-fluid" style="margin: 50px; cursor: pointer;" {
|
article class="container-fluid" style="margin: 50px; cursor: pointer;" {
|
||||||
a href=(format!("/watch?v={video_hash}")) style="text-decoration:none !important;" {
|
a href=(format!("/watch?v={video_id}")) style="text-decoration:none !important;" {
|
||||||
img style="width: 350px;" width="480" src=(format!("/video/thumbnail?v={video_hash}"));
|
img style="width: 350px;" width="480" src=(format!("/video/thumbnail?v={video_id}"));
|
||||||
div style="padding: 10px;" {
|
div style="padding: 10px;" {
|
||||||
h2 style="margin: 0; font-size: 18px;" { (video.title().unwrap()) };
|
h2 style="margin: 0; font-size: 18px;" { (video.title) };
|
||||||
@if !desc.is_empty() {
|
@if !desc.as_ref().map(|x| x.is_empty()).unwrap_or(true) {
|
||||||
p style="margin: 0; color: grey; font-size: 14px;margin-top: 10px;" { (desc.chars().take(200).chain("...".to_string().chars()).take(203).collect::<String>()) };
|
p style="margin: 0; color: grey; font-size: 14px;margin-top: 10px;" { (desc.unwrap().chars().take(200).chain("...".to_string().chars()).take(203).collect::<String>()) };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use maud::html;
|
||||||
use rocket::{get, State};
|
use rocket::{get, State};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
@ -27,3 +28,8 @@ pub async fn channel_page(dir: &str, library: &State<Library>) -> Option<serde_j
|
||||||
|
|
||||||
Some(json!(vec_to_api(&mut dir_videos).await))
|
Some(json!(vec_to_api(&mut dir_videos).await))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
pub async fn index_page(library: &State<Library>) -> String {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue