Skip to content

Instantly share code, notes, and snippets.

@felix-d
Created April 2, 2018 22:46
Show Gist options
  • Select an option

  • Save felix-d/037d7c53aa84fc72f0ca4bfe031a4674 to your computer and use it in GitHub Desktop.

Select an option

Save felix-d/037d7c53aa84fc72f0ca4bfe031a4674 to your computer and use it in GitHub Desktop.

Revisions

  1. felix-d created this gist Apr 2, 2018.
    17 changes: 17 additions & 0 deletions downloader.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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);