aboutsummaryrefslogtreecommitdiff
path: root/stream/src/fragment_index.rs
diff options
context:
space:
mode:
Diffstat (limited to 'stream/src/fragment_index.rs')
-rw-r--r--stream/src/fragment_index.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/stream/src/fragment_index.rs b/stream/src/fragment_index.rs
new file mode 100644
index 0000000..6fbddc6
--- /dev/null
+++ b/stream/src/fragment_index.rs
@@ -0,0 +1,32 @@
+/*
+ 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 <metamuffin.org>
+*/
+use crate::{stream_info, SMediaInfo};
+use anyhow::{anyhow, Result};
+use jellybase::common::stream::{SegmentNum, TrackNum};
+use std::sync::Arc;
+use tokio::io::{AsyncWriteExt, DuplexStream};
+
+pub async fn fragment_index_stream(
+ mut b: DuplexStream,
+ info: Arc<SMediaInfo>,
+ _segment: SegmentNum,
+ track: TrackNum,
+) -> Result<()> {
+ let (iinfo, _info) = stream_info(info).await?;
+ let (file_index, track_num) = *iinfo
+ .track_to_file
+ .get(track)
+ .ok_or(anyhow!("track not found"))?;
+
+ let fragments = tokio::task::spawn_blocking(move || {
+ jellyremuxer::fragment::fragment_index(&iinfo.paths[file_index], track_num)
+ })
+ .await??;
+
+ let out = serde_json::to_string(&fragments)?;
+ tokio::spawn(async move { b.write_all(out.as_bytes()).await });
+ Ok(())
+}