From e43dc75e3cfb950ac0d0308900c20fa292de0c46 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 3 Feb 2025 22:42:13 +0100 Subject: some jellyfin api endpoints --- server/src/routes/compat/youtube.rs | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 server/src/routes/compat/youtube.rs (limited to 'server/src/routes/compat/youtube.rs') diff --git a/server/src/routes/compat/youtube.rs b/server/src/routes/compat/youtube.rs new file mode 100644 index 0000000..732431e --- /dev/null +++ b/server/src/routes/compat/youtube.rs @@ -0,0 +1,44 @@ +/* + This file is part of jellything (https://codeberg.org/metamuffin/jellything) + which is licensed under the GNU Affero General Public License (version 3); see /COPYING. + Copyright (C) 2025 metamuffin +*/ +use crate::routes::ui::{ + account::session::Session, + error::MyResult, + node::rocket_uri_macro_r_library_node, + player::{rocket_uri_macro_r_player, PlayerConfig}, +}; +use anyhow::anyhow; +use jellybase::database::Database; +use rocket::{get, response::Redirect, State}; + +#[get("/watch?")] +pub fn r_youtube_watch(_session: Session, db: &State, v: &str) -> MyResult { + if v.len() != 11 { + Err(anyhow!("video id length incorrect"))? + } + let Some(id) = db.get_node_external_id("youtube:video", v)? else { + Err(anyhow!("element not found"))? + }; + let node = db.get_node(id)?.ok_or(anyhow!("node missing"))?; + Ok(Redirect::to(rocket::uri!(r_player( + &node.slug, + PlayerConfig::default() + )))) +} + +#[get("/channel/")] +pub fn r_youtube_channel(_session: Session, db: &State, id: &str) -> MyResult { + let Some(id) = (if id.starts_with("UC") { + db.get_node_external_id("youtube:channel", id)? + } else if id.starts_with("@") { + db.get_node_external_id("youtube:channel-name", id)? + } else { + Err(anyhow!("unknown channel id format"))? + }) else { + Err(anyhow!("channel not found"))? + }; + let node = db.get_node(id)?.ok_or(anyhow!("node missing"))?; + Ok(Redirect::to(rocket::uri!(r_library_node(&node.slug)))) +} -- cgit v1.2.3-70-g09d2