main.rs (2427B)
1 use odysee_dl::config::Config; 2 use odysee_dl::event::Event; 3 use odysee_dl::run; 4 5 use regex::Regex; 6 7 fn main() { 8 // Get actual channel urls 9 let re = Regex::new(r#"https?://odysee\.com/@[^:]+:[0-9a-f]+[^\s"'<>]*"#).unwrap(); 10 let page = ureq::get("https://thegatalog.com/") 11 .call() 12 .unwrap() 13 .body_mut() 14 .read_to_string() 15 .unwrap(); 16 let urls = re 17 .find_iter(&page) 18 .map(|m| m.as_str().to_string()) 19 .collect::<Vec<String>>(); 20 println!("Found {} channel URLs", urls.len()); 21 22 for url in urls { 23 let dirname = url 24 .split("/@") 25 .nth(1) 26 .unwrap() 27 .split(":") 28 .nth(0) 29 .unwrap(); 30 std::fs::create_dir_all(dirname).unwrap(); 31 let output_dir = std::path::PathBuf::from(dirname); 32 let config = Config { 33 url: url, 34 output_dir: output_dir, 35 resume: true, 36 }; 37 38 let (tx, rx) = std::sync::mpsc::channel(); 39 let handle = std::thread::spawn(move || { 40 run(config, tx.clone()).unwrap(); 41 }); 42 for msg in rx.iter() { 43 render_event(&msg); 44 } 45 handle.join().unwrap(); 46 } 47 } 48 49 fn render_event(event: &Event) { 50 use std::io::Write; 51 match event { 52 Event::GetChannelStarted(url) => { 53 print!("Fetching channel: {}...", url); 54 std::io::stdout().flush().ok(); 55 } 56 Event::GetChannelFailed(url, err) => eprintln!("\nFailed to fetch channel {}: {}", url, err), 57 Event::GetChannelFinished(_) => println!(" Done"), 58 Event::GetPostsStarted(url) => { 59 print!("Fetching posts from: {}...", url); 60 std::io::stdout().flush().ok(); 61 } 62 Event::GetPostsFailed(url, err) => eprintln!("\nFailed to fetch posts from {}: {}", url, err), 63 Event::GetPostsFinished(_) => println!(" Done"), 64 Event::DownloadPostStarted(name) => { 65 print!("Downloading: {}...", name); 66 std::io::stdout().flush().ok(); 67 } 68 Event::DownloadPostFailed(_, err) => println!(" Failed: {}", err), 69 Event::DownloadPostSkipped(_) => println!(" Skipped"), 70 Event::DownloadPostFinished(_) => println!(" Done"), 71 Event::RateLimited(ctx) => println!("\nRate limited ({}), waiting 60s...", ctx), 72 Event::Done => println!("Done."), 73 } 74 }