Coder Social home page Coder Social logo

singleway / rusty_ytdl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mithronn/rusty_ytdl

0.0 0.0 0.0 279 KB

A Rust library for Youtube video searcher and downloader

Home Page: https://docs.rs/rusty_ytdl

License: MIT License

Rust 100.00%

rusty_ytdl's Introduction

rusty_ytdl

crates.io Released API docs

Youtube searching and downloading module written with pure Rust. Download videos blazing-fast without getting stuck on Youtube download speed (Downloads 20MB video files in just 10 seconds!)

Overview

Roadmap

  • benchmarks

Features

  • Download live and non-live videos
  • Search with query (Video, Playlist, Channel)
  • Blocking and asynchronous API
  • Proxy, IPv6, and cookie support on request
  • Built-in FFmpeg audio and video filter apply support (Non-live videos only) Example
  • CLI

Usage

use rusty_ytdl::Video;

#[tokio::main]
async fn main() {
  let video_url = "https://www.youtube.com/watch?v=FZ8BxMU3BYc"; // FZ8BxMU3BYc works too!
  let video = Video::new(url).unwrap();

  let stream = video.stream().await.unwrap();

  while let Some(chunk) = stream.chunk().await.unwrap() {
    // Do what you want with chunks
    println!("{:#?}", chunk);
  }

  // Or direct download to path
  let path = std::path::Path::new(r"test.mp3");

  video.download(path).await.unwrap();

  //
  // Or with options
  //

  let video_options = VideoOptions {
    quality: VideoQuality::Lowest,
    filter: VideoSearchOptions::Audio,
    ..Default::default()
  };

  let video = Video::new_with_options(url, video_options).unwrap();

  let stream = video.stream().await.unwrap();

  while let Some(chunk) = stream.chunk().await.unwrap() {
    // Do what you want with chunks
    println!("{:#?}", chunk);
  }

  // Or direct download to path
  let path = std::path::Path::new(r"test.mp3");

  video.download(path).await.unwrap();
}

or get only video informations

use rusty_ytdl::Video;
use rusty_ytdl::{choose_format,VideoOptions};

#[tokio::main]
async fn main() {
  let video_url = "https://www.youtube.com/watch?v=FZ8BxMU3BYc"; // FZ8BxMU3BYc works too!
  // Also works with live videos!!
  let video = Video::new(url).unwrap();

  let video_info = video.get_info().await.unwrap();
  println!("{:#?}",video_info);

  /*
  VideoInfo {
    dash_manifest_url: Option<String>,
    hls_manifest_url: Option<String>,
    video_details: VideoDetails,
    formats: Vec<VideoFormat>,
    related_videos: Vec<RelatedVideo>
  }
  */

  let video_options = VideoOptions {
    quality: VideoQuality::Lowest,
    filter: VideoSearchOptions::Audio,
      ..Default::default()
  };

  let format = choose_format(&video_info.unwrap().formats,&video_options);

  println!("{:#?}",format);

  // Or with options
  let video = Video::new_with_options(url, video_options.clone()).unwrap();

  let format = choose_format(&video_info.formats, &video_options);

  let video_info = video.get_info().await.unwrap();

  println!("{:#?}",video_info);
}

For more examples, check examples

Limitations

rusty_ytdl cannot download videos that fall into the following

  • Regionally restricted (requires a proxy)
  • Private (if you have access, requires cookies)
  • Rentals (if you have access, requires cookies)
  • YouTube Premium content (if you have access, requires cookies)
  • Only HLS Livestreams are currently supported. Other formats not will be fetch

Generated download links are valid for 6 hours, and may only be downloadable from the same IP address.

Ratelimits

When doing to many requests YouTube might block. This will result in your requests getting denied with HTTP Status Code 429. The following steps might help you:

  • Use proxies (you can find an example proxy)
  • Extend on the Proxy Idea by rotating (IPv6)Addresses (you can find an example IPv6)
  • Use cookies (you can find an example cookies)
    • for this to take effect you have to first wait for the current ratelimit to expire!
  • Wait it out

Installation

cargo add rusty_ytdl

Or add the following to your Cargo.toml file:

[dependencies]
rusty_ytdl = "0.7.2"

rusty_ytdl's People

Contributors

mithronn avatar ccgauche avatar brqnko avatar bksalman avatar singleway avatar dcnick3 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.