bencode_torrent_to_yaml/
bencode_torrent_to_yaml.rs1use babbel_bencode::{FileDestination, FileSource, parse, to_yaml};
5use std::path::Path;
6
7#[path = "common/utility.rs"]
8mod bencode_utility_lib;
9use bencode_utility_lib::get_torrent_file_list;
10
11fn process_torrent_file(file_path: &str) -> Result<(), String> {
13 let mut source = FileSource::new(file_path).map_err(|e| e.to_string())?;
14 let node = parse(&mut source).map_err(|e| e.to_string())?;
15 let mut destination = FileDestination::new(
16 Path::new(file_path)
17 .with_extension("yaml")
18 .to_string_lossy()
19 .as_ref(),
20 )
21 .map_err(|e| e.to_string())?;
22 to_yaml(&node, &mut destination)?;
23 Ok(())
24}
25
26fn main() {
27 let torrent_files = get_torrent_file_list("files");
28 for file_path in torrent_files {
29 match process_torrent_file(&file_path) {
30 Ok(()) => println!("Successfully converted {}", file_path),
31 Err(e) => eprintln!("Failed to convert {}: {}", file_path, e),
32 }
33 }
34}