Skip to content

Commit

Permalink
Add dubz replacer
Browse files Browse the repository at this point in the history
  • Loading branch information
evanc577 committed Sep 7, 2024
1 parent 5179b1f commit 7330825
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/link_embed/dubz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use once_cell::sync::Lazy;
use regex::Regex;
use url::Url;

use super::UrlReplacer;

impl UrlReplacer {
pub async fn replace_dubz(url: &url::Url) -> Vec<Url> {
static PATH_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^/c/(?P<id>\w+)").unwrap());
let url = PATH_RE
.captures(url.path())
.map(|cap| cap.name("id").unwrap())
.and_then(|id| {
Url::parse(&format!(
"https://dubzalt.com/storage/videos/{}.mp4",
id.as_str()
))
.ok()
});
if let Some(url) = url {
vec![url]
} else {
Vec::new()
}
}
}

0 comments on commit 7330825

Please sign in to comment.