From f46a50a85caa2696d108135a9d12650714e62861 Mon Sep 17 00:00:00 2001 From: euzu Date: Tue, 4 Feb 2025 10:25:40 +0100 Subject: [PATCH] adding `&type=m3u_plus` at the end of an `m3u` url wil trigger a download. Without it will only stream the result. --- CHANGELOG.md | 1 + src/api/m3u_api.rs | 9 ++++++--- src/api/model/request.rs | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca5aeb23..96e49b9b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ web_ui_enabled: true - added `hlsr` handling. - refactored strm generation, does not delete root directory, avoids unchanged file creations. - fixed mapper counter not incrementing. +- adding `&type=m3u_plus` at the end of an `m3u` url wil trigger a download. Without it will only stream the result. # 2.1.3 (2025-01-26) - Hotfix 2.1.2, forgot to update the stream api code. diff --git a/src/api/m3u_api.rs b/src/api/m3u_api.rs index 0719761ed..545da41b4 100644 --- a/src/api/m3u_api.rs +++ b/src/api/m3u_api.rs @@ -26,9 +26,12 @@ async fn m3u_api( Ok(m3u_iter) => { // Convert the iterator into a stream of `Bytes` let content_stream = stream::iter(m3u_iter.map(|line| Ok::(Bytes::from([line.as_bytes(), b"\n"].concat())))); - HttpResponse::Ok() - .content_type(mime::TEXT_PLAIN_UTF_8) - .streaming(content_stream) + let mut builder = HttpResponse::Ok(); + builder.content_type(mime::TEXT_PLAIN_UTF_8); + if api_req.content_type == "m3u_plus" { + builder.insert_header(("Content-Disposition", "attachment; filename=\"playlist.m3u\"")); + } + builder.streaming(content_stream) } Err(err) => { error!("{}", sanitize_sensitive_info(err.to_string().as_str())); diff --git a/src/api/model/request.rs b/src/api/model/request.rs index c001a8481..101d8f3f9 100644 --- a/src/api/model/request.rs +++ b/src/api/model/request.rs @@ -41,4 +41,6 @@ pub struct UserApiRequest { pub stream: String, #[serde(default)] pub duration: String, + #[serde(default, alias = "type")] + pub content_type: String, } \ No newline at end of file