Skip to content

Instantly share code, notes, and snippets.

@felix-d
Created April 2, 2018 22:46
Show Gist options
  • Save felix-d/037d7c53aa84fc72f0ca4bfe031a4674 to your computer and use it in GitHub Desktop.
Save felix-d/037d7c53aa84fc72f0ca4bfe031a4674 to your computer and use it in GitHub Desktop.
Downloader
let video_file_regex = Regex::new(r"https://.*\.ts").unwrap();
let mut result_video_file = File::create("result.ts")?;
let futures: Vec<_> = video_file_regex.find_iter(&hd_playlist_content).map(|capture| {
let video_file_link = capture.as_str();
let response = client.get(video_file_link.parse().unwrap());
response.unwrap().body().concat2()
}).collect();
let all = futures::stream::futures_ordered(futures);
let all = all.and_then(|bytes: hyper::Chunk| {
result_video_file.write_all(&bytes).unwrap();
Ok(())
}).for_each(|_| Ok(()));
core.run(all);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment