mirror of
https://github.com/thegeneralist01/archivr
synced 2026-03-10 02:30:29 +01:00
feat: add shorthand schemes for X/Twitter media
This commit is contained in:
parent
76fce7f91e
commit
20d8514696
1 changed files with 36 additions and 11 deletions
47
src/main.rs
47
src/main.rs
|
|
@ -82,13 +82,10 @@ fn determine_source(path: &str) -> Source {
|
||||||
// TEST: X posts can have multiple videos.
|
// TEST: X posts can have multiple videos.
|
||||||
|
|
||||||
// Shorthand schemes: yt: or youtube:
|
// Shorthand schemes: yt: or youtube:
|
||||||
if path.starts_with("yt:") || path.starts_with("youtube:") {
|
if let Some(after_scheme) = path
|
||||||
let after_scheme = if path.starts_with("yt:") {
|
.strip_prefix("yt:")
|
||||||
&path[3..]
|
.or_else(|| path.strip_prefix("youtube:"))
|
||||||
} else {
|
{
|
||||||
&path[8..]
|
|
||||||
};
|
|
||||||
|
|
||||||
// video/ID, short/ID, shorts/ID
|
// video/ID, short/ID, shorts/ID
|
||||||
if after_scheme.starts_with("video/")
|
if after_scheme.starts_with("video/")
|
||||||
|| after_scheme.starts_with("short/")
|
|| 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://") {
|
if path.starts_with("file://") {
|
||||||
return Source::Local;
|
return Source::Local;
|
||||||
} else if path.starts_with("http://") || path.starts_with("https://") {
|
} 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]
|
#[test]
|
||||||
fn test_non_youtube_sources() {
|
fn test_non_youtube_sources() {
|
||||||
let other_cases = [
|
let other_cases = [
|
||||||
|
|
@ -505,10 +534,6 @@ mod tests {
|
||||||
url: "file:///local/path/file.mp4",
|
url: "file:///local/path/file.mp4",
|
||||||
expected: Source::Local,
|
expected: Source::Local,
|
||||||
},
|
},
|
||||||
TestCase {
|
|
||||||
url: "https://x.com/some_post",
|
|
||||||
expected: Source::X,
|
|
||||||
},
|
|
||||||
TestCase {
|
TestCase {
|
||||||
url: "https://example.com/",
|
url: "https://example.com/",
|
||||||
expected: Source::Other,
|
expected: Source::Other,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue