Skip to content

Commit

Permalink
Release v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ritiek committed Jul 8, 2017
1 parent 2f9cfa9 commit bc18c48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
name = "rafy"
version = "0.1.0"
authors = ["Ritiek <[email protected]>"]
description = "Rust library to download YouTube content and retrieve metadata"
repository = "https://github.com/ritiek/rafy-rs"
readme = "README.md"
keywords = ["YouTube", "metadata", "rust", "content", "downloader"]
categories = ["Value formatting", "Data structures"]
license = "MIT"

[dependencies]
hyper = "0.10"
Expand Down
34 changes: 28 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use std::io::prelude::*;
use std::fs::File;
use regex::Regex;

/// TEST struct Rafy {}

pub struct Rafy {
pub videoid: String,
pub title: String,
Expand Down Expand Up @@ -51,20 +53,31 @@ pub struct Stream {

impl Stream {

/// Downloads a stream.
///
/// # Examples
///
/// ```
/// extern crate rafy;
///
/// use rafy:Rafy;
///
/// let content = Rafy::new("https://www.youtube.com/watch?v=DjMkfARvGE8");
/// let stream = contents.stream[0];
/// stream.download();
/// ```

pub fn download(&self) {
//download self.url
let response = Rafy::send_request(&self.url);
let file_size = Rafy::get_file_size(&response);
let file_name = format!("{}.{}", &self.title, &self.extension);
Self::write_file(response, &file_name, file_size);
}

fn write_file(mut response: Response, title: &str, file_size: u64) {
// initialize progressbar
let mut pb = ProgressBar::new(file_size);
pb.format("╢▌▌░╟");

// Download and write to file
let mut buf = [0; 128 * 1024];
let mut file = File::create(title).unwrap();
loop {
Expand All @@ -87,6 +100,18 @@ impl Stream {

impl Rafy {

/// Create a Rafy object using the `Rafy::new()` function, giving YouTube URL as the argument.
///
/// # Examples
///
/// ```
/// extern crate rafy;
///
/// use rafy::Rafy;
///
/// let content = Rafy::new("https://www.youtube.com/watch?v=DjMkfARvGE8");
/// ```

pub fn new(url: &str) -> Rafy {
// API key to fetch content
let key = "AIzaSyDHTKjtUchUxUOzCtYW4V_h1zzcyd0P6c0";
Expand Down Expand Up @@ -130,7 +155,6 @@ impl Rafy {
let author = &basic["author"];
let length = &basic["length_seconds"];
let thumbdefault = &basic["thumbnail_url"];

let likes = &parsed_json["items"][0]["statistics"]["likeCount"];
let dislikes = &parsed_json["items"][0]["statistics"]["dislikeCount"];
let commentcount = &parsed_json["items"][0]["statistics"]["commentCount"];
Expand All @@ -151,7 +175,6 @@ impl Rafy {
author: author.to_string(),
length: length.parse::<u32>().unwrap(),
thumbdefault: thumbdefault.to_string(),

likes: likes.to_string().parse::<u32>().unwrap(),
dislikes: dislikes.to_string().parse::<u32>().unwrap(),
commentcount: commentcount.to_string().parse::<u32>().unwrap(),
Expand All @@ -162,7 +185,6 @@ impl Rafy {
thumbmaxres: thumbmaxres.to_string(),
published: published.to_string(),
category: category.to_string().parse::<u32>().unwrap(),

streams: streams,
}
}
Expand Down

0 comments on commit bc18c48

Please sign in to comment.