download episodes
This commit is contained in:
parent
fee0288105
commit
2c51df93cc
@ -46,7 +46,7 @@ impl DualWriter {
|
||||
}
|
||||
})
|
||||
}
|
||||
pub fn new(file_name: Option<String>) -> Result<Self, io::Error> {
|
||||
pub fn new(file_name: Option<&str>) -> Result<Self, io::Error> {
|
||||
Ok(if let Some(file_name) = file_name {
|
||||
Self::File(File::create(&file_name)?)
|
||||
} else {
|
||||
@ -57,7 +57,7 @@ impl DualWriter {
|
||||
|
||||
pub async fn download_with_progress(
|
||||
link: &str,
|
||||
file_name: Option<String>,
|
||||
file_name: Option<&str>,
|
||||
) -> Result<DualWriter, String> {
|
||||
let mut dw = DualWriter::new(file_name).or(Err("Failed to create file".to_owned()))?;
|
||||
|
||||
|
@ -11,6 +11,7 @@ pub use parser::Parser;
|
||||
mod config;
|
||||
mod downloader;
|
||||
use directories::ProjectDirs;
|
||||
pub use downloader::download_with_progress;
|
||||
|
||||
pub fn setup() -> String {
|
||||
let project_dirs = ProjectDirs::from("com", "billenius", "iptvnator_rs").unwrap();
|
||||
|
67
src/main.rs
67
src/main.rs
@ -1,8 +1,10 @@
|
||||
use std::io::{self, stdout, Write};
|
||||
use std::num::ParseIntError;
|
||||
use std::process::Command;
|
||||
use std::rc::Rc;
|
||||
|
||||
use iptvnator_rs::{setup, M3u8, Parser};
|
||||
use iptvnator_rs::{download_with_progress, setup, M3u8, Parser};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
println!("Welcome to iptvnator_rs, the port of my iptvprogram written in python, now in rust BLAZINGLY FAST\n");
|
||||
@ -40,7 +42,7 @@ async fn main() {
|
||||
for (idx, m3u8_item) in search_result.as_ref().unwrap().iter().enumerate().rev() {
|
||||
println!(" {}: {}", idx + 1, m3u8_item);
|
||||
}
|
||||
print!("Which one do you wish to stream? [q | s | r]: ");
|
||||
print!("Which one do you wish to stream? [ q/s/r/d ]: ");
|
||||
stdout.flush().unwrap();
|
||||
buf = String::new();
|
||||
stdin.read_line(&mut buf).unwrap();
|
||||
@ -64,6 +66,40 @@ async fn main() {
|
||||
p.forcefully_update().await;
|
||||
}
|
||||
continue;
|
||||
} else if user_wish == "d" {
|
||||
print!("Download all or select in comma separated [A]: ");
|
||||
stdout.flush().unwrap();
|
||||
|
||||
let mut selection = String::new();
|
||||
stdin.read_line(&mut selection).unwrap();
|
||||
|
||||
let selection = selection.trim();
|
||||
let to_download = loop {
|
||||
break if selection.to_lowercase() == "a" {
|
||||
println!("Downloading all");
|
||||
search_result.as_ref().unwrap().clone()
|
||||
} else {
|
||||
let selections = selection
|
||||
.split(",")
|
||||
.map(|x| x.trim().parse::<usize>())
|
||||
.collect::<Vec<Result<usize, ParseIntError>>>();
|
||||
|
||||
for selection in selections.iter() {
|
||||
if selection.is_err() {
|
||||
println!("Not a valid number");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let selections = selections.into_iter().map(|x| x.unwrap() - 1);
|
||||
let mut final_selections = Vec::new();
|
||||
for selection in selections {
|
||||
final_selections.push((search_result.as_ref().unwrap())[selection]);
|
||||
}
|
||||
|
||||
Rc::new(final_selections)
|
||||
};
|
||||
};
|
||||
download_m3u8(to_download).await;
|
||||
}
|
||||
|
||||
let choosen = user_wish.parse::<usize>();
|
||||
@ -79,6 +115,33 @@ async fn main() {
|
||||
parser.save_watched();
|
||||
}
|
||||
|
||||
async fn download_m3u8(files_to_download: Rc<Vec<&M3u8>>) {
|
||||
for m3u8 in files_to_download.iter() {
|
||||
let file_ending_place = m3u8.link.rfind(".").unwrap();
|
||||
let potential_file_ending = &m3u8.link[file_ending_place..];
|
||||
let file_ending = if potential_file_ending.len() > 6 {
|
||||
".mkv"
|
||||
} else {
|
||||
potential_file_ending
|
||||
};
|
||||
let file_name = format!("{}{}", m3u8.name, file_ending);
|
||||
println!("Downloading {}", &file_name);
|
||||
if let Err(e) = download_with_progress(&m3u8.link, Some(&file_name)).await {
|
||||
eprintln!("Failed to download {}, {:?}", &file_name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn t() {
|
||||
let link = "http://clientsportals.com:2095/series/fW6Mue7z/aTGX3xaM/21179.mkv";
|
||||
let dot = link.rfind(".").unwrap();
|
||||
let last = &link[dot..link.len()];
|
||||
|
||||
println!("{}", last);
|
||||
println!("{}", last.len());
|
||||
}
|
||||
|
||||
fn stream(m3u8item: &M3u8) {
|
||||
// Well I know that this is frowned upon, but it's honestly the most efficient way of doing this
|
||||
let ptr = m3u8item as *const M3u8;
|
||||
|
Loading…
x
Reference in New Issue
Block a user