diff --git a/src/download.rs b/src/download.rs index 3c6bb96..e67172c 100644 --- a/src/download.rs +++ b/src/download.rs @@ -1,6 +1,6 @@ use std::{path::Path, process::Command}; -use crate::track::Track; +use crate::{file::FileHandle, track::Track}; #[derive(Debug, Clone, Copy)] pub struct DownloadError; @@ -32,5 +32,7 @@ pub fn download_from_youtube(url: &str) -> Result { .replace('\n', "") + ".mp3"; - Ok(Track::new(Path::new(filename.as_str()))) + let file_handle = FileHandle::new(Path::new(filename.as_str())); + + Ok(Track::new(file_handle)) } diff --git a/src/file.rs b/src/file.rs index 37375a7..1ccf365 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,5 +1,5 @@ -use std::path::{Path, PathBuf}; use std::fs; +use std::path::{Path, PathBuf}; #[derive(Debug, Clone)] pub struct FileHandle { @@ -12,6 +12,10 @@ impl FileHandle { path: PathBuf::from(path), } } + + pub fn get_path(&self) -> &Path { + &self.path + } } impl Drop for FileHandle { diff --git a/src/player.rs b/src/player.rs index 3e2adac..f2edbbc 100644 --- a/src/player.rs +++ b/src/player.rs @@ -37,7 +37,7 @@ struct Worker { } fn get_source(track: Track) -> Decoder> { - let file = BufReader::new(File::open(track.path).unwrap()); + let file = BufReader::new(File::open(track.file.get_path()).unwrap()); Decoder::new(file).unwrap() } diff --git a/src/telegram.rs b/src/telegram.rs index b3a39b1..cd82a21 100644 --- a/src/telegram.rs +++ b/src/telegram.rs @@ -74,7 +74,7 @@ impl TelegramBot { } else { message = tracks .iter() - .map(|t| t.path.to_str().unwrap()) + .map(|t| t.file.get_path().to_str().unwrap()) .collect::>() .join("\n"); } diff --git a/src/track.rs b/src/track.rs index 62af41c..df1d0e5 100644 --- a/src/track.rs +++ b/src/track.rs @@ -1,13 +1,12 @@ -use std::path::{Path, PathBuf}; +use crate::file::FileHandle; + #[derive(Debug, Clone)] pub struct Track { - pub path: PathBuf, + pub file: FileHandle, } impl Track { - pub fn new(path: &Path) -> Track { - Track { - path: PathBuf::from(path), - } + pub fn new(file: FileHandle) -> Track { + Track { file } } }