watchdogs/src/pages/watch.rs

66 lines
1.9 KiB
Rust
Raw Normal View History

2024-12-14 00:24:10 +01:00
use maud::html;
use rocket::{
get,
http::{ContentType, Status},
State,
};
use serde_json::json;
use crate::{
library::{self, Library},
2024-12-14 23:33:47 +01:00
pages::components::{format_date, video_element},
2024-12-14 00:24:10 +01:00
};
use super::{
components::{render_page, HTMX},
vec_to_api,
};
#[get("/watch?<v>")]
pub async fn watch_page(
htmx: HTMX,
library: &State<Library>,
v: String,
) -> (Status, (ContentType, String)) {
let video = if let Some(video) = library.get_video_by_id(&v).await {
video
} else {
// TODO : Error handling
library.get_video_by_youtube_id(&v).await.unwrap()
};
let content = html!(
main class="container mx-auto mt-6 flex flex-col lg:flex-row gap-6" {
div class="lg:w-2/3 mt-10" {
div class="bg-black aspect-video rounded-lg overflow-hidden" {
video
controls
autoplay
class="w-full h-full" {
source src=(format!("/video/raw?v={}", video.id)) {
"Your browser does not support the video"
};
};
};
div class="p-4 bg-stone-900 rounded-lg shadow-lg mt-8" {
h2 class="text-2xl font-semibold" { (video.title) };
2024-12-14 23:33:47 +01:00
@if let Some(meta) = video.youtube_meta().await {
div class="flex justify-between mt-2" {
p class="mb-4 text-gray-300" { (meta.uploader_name) };
p class="mb-4 text-gray-300" { (format!("{} Views ﹣ {}", meta.views, format_date(&meta.upload_date))) };
};
a href=(format!("https://www.youtube.com/watch?v={}", meta.id)) class="text-blue-400" {"Watch on YouTube" };
p class="mb-2 text-gray-300 text-bold mt-2" { "Description: " } span { (meta.description) };
};
2024-12-14 00:24:10 +01:00
};
};
};
);
render_page(htmx, content, &format!("{} - WatchDogs", video.title))
}