bencode_torrent_to_json/
bencode_torrent_to_json.rs1use babbel_bencode::{FileDestination, FileSource, parse, to_json};
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("json")
18 .to_string_lossy()
19 .as_ref(),
20 )
21 .map_err(|e| e.to_string())?;
22 to_json(&node, &mut destination).map_err(|e| e.to_string())?;
23 Ok(())
24}
25
26fn main() {
28 let torrent_files = get_torrent_file_list("files");
29 for file_path in torrent_files {
30 match process_torrent_file(&file_path) {
31 Ok(()) => println!("Successfully converted {}", file_path),
32 Err(e) => eprintln!("Failed to convert {}: {}", file_path, e),
33 }
34 }
35}