1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-03-07 11:39:55 +01:00

feat: add shorthand schemes for X/Twitter media

This commit is contained in:
TheGeneralist 2026-01-21 20:42:00 +01:00
parent 76fce7f91e
commit 20d8514696
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4

View file

@ -82,13 +82,10 @@ fn determine_source(path: &str) -> Source {
// TEST: X posts can have multiple videos.
// Shorthand schemes: yt: or youtube:
if path.starts_with("yt:") || path.starts_with("youtube:") {
let after_scheme = if path.starts_with("yt:") {
&path[3..]
} else {
&path[8..]
};
if let Some(after_scheme) = path
.strip_prefix("yt:")
.or_else(|| path.strip_prefix("youtube:"))
{
// video/ID, short/ID, shorts/ID
if after_scheme.starts_with("video/")
|| after_scheme.starts_with("short/")
@ -112,6 +109,11 @@ fn determine_source(path: &str) -> Source {
}
}
// Shorthand schemes: x: or twitter:
if path.starts_with("x:") || path.starts_with("twitter:") {
return Source::X;
}
if path.starts_with("file://") {
return Source::Local;
} else if path.starts_with("http://") || path.starts_with("https://") {
@ -498,6 +500,33 @@ mod tests {
}
}
#[test]
fn test_x_sources() {
let x_cases = [
TestCase {
url: "https://x.com/some_post",
expected: Source::X,
},
TestCase {
url: "x:1234567890",
expected: Source::X,
},
TestCase {
url: "twitter:1234567890",
expected: Source::X,
},
];
for case in &x_cases {
assert_eq!(
determine_source(case.url),
case.expected,
"Failed for URL: {}",
case.url
);
}
}
#[test]
fn test_non_youtube_sources() {
let other_cases = [
@ -505,10 +534,6 @@ mod tests {
url: "file:///local/path/file.mp4",
expected: Source::Local,
},
TestCase {
url: "https://x.com/some_post",
expected: Source::X,
},
TestCase {
url: "https://example.com/",
expected: Source::Other,