-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownload_sub.rs
More file actions
42 lines (35 loc) · 1.23 KB
/
download_sub.rs
File metadata and controls
42 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::process::Command;
use opensubs::{Filters, Language, OrderBy, Response, SearchBy};
#[tokio::main]
async fn main() -> opensubs::Result {
// blocking search movie "pulp fiction", norwegian and swedish subs, order by date
let results = opensubs::search(SearchBy::MovieAndFilter(
"pulp fiction",
Filters::default()
.languages(&[Language::Norwegian, Language::Swedish])
.order_by(OrderBy::Uploaded)
.build(),
))
.await?;
if let Response::Subtitle(_, subtitles) = results {
// Example filtering by uploader and getting the download link
let link = subtitles
.iter()
.find(|&sub| sub.uploader.as_ref().is_some_and(|s| s.contains("larza83")))
.map(|sub| sub.download_link.as_str());
println!("Link to download {link:#?}");
// Download using wget
let output = Command::new("wget")
.arg("-O")
.arg("subtitle.zip")
.arg(link.unwrap())
.output()
.expect("Failed to execute wget");
if output.status.success() {
println!("Download successful!");
} else {
println!("Download failed.");
}
}
Ok(())
}