From e90eebcbd7c0f1afe2d261913b1b64d6db92190c Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 14 Dec 2023 05:03:55 +0000 Subject: [PATCH] Don't include /range/ in hash See https://github.com/TeamPiped/Piped/issues/3211 --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1eef9f5..44ba06a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use once_cell::sync::Lazy; use qstring::QString; use regex::Regex; use reqwest::{Body, Client, Request, Url}; +use std::borrow::Cow; use std::collections::BTreeMap; use std::error::Error; use std::io::ErrorKind; @@ -184,7 +185,20 @@ async fn index(req: HttpRequest) -> Result> { hasher.update(&value); } - hasher.update(&path); + let range_marker = b"/range/"; + + // Find the slice before "/range/" + if let Some(position) = path + .windows(range_marker.len()) + .position(|window| window == range_marker) + { + // Update the hasher with the part of the path before "/range/" + // We add +1 to include the "/" in the hash + // This is done for DASH streams for the manifests provided by YouTube + hasher.update(&path[..(position + 1)]); + } else { + hasher.update(&path); + } hasher.update(secret.as_bytes());