/* 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 anyhow::{anyhow, Result}; use jellybase::{permission::PermissionSetExt, CONF}; use jellycommon::{ jhls::JhlsTrackIndex, stream::StreamSpec, user::{PermissionSet, UserPermission}, LocalTrack, Node, }; use tokio::io::{AsyncWriteExt, DuplexStream}; pub async fn jhls_index( node: Node, local_tracks: &[LocalTrack], spec: StreamSpec, mut b: DuplexStream, perms: &PermissionSet, ) -> Result<()> { let local_track = local_tracks .first() .ok_or(anyhow!("track missing"))? .to_owned(); let segments = tokio::task::spawn_blocking(move || { jellyremuxer::fragment::fragment_index(&CONF.media_path, &node, &local_track, spec.track[0]) }) .await??; let out = serde_json::to_string(&JhlsTrackIndex { extra_profiles: if perms.check(&UserPermission::Transcode) { CONF.transcoding_profiles.clone() } else { vec![] }, segments, })?; tokio::spawn(async move { b.write_all(out.as_bytes()).await }); Ok(()) }