use FileHandle in Track
This commit is contained in:
parent
0448b3eced
commit
cfd8429188
5 changed files with 16 additions and 11 deletions
|
|
@ -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<Track, DownloadError> {
|
|||
.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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ struct Worker {
|
|||
}
|
||||
|
||||
fn get_source(track: Track) -> Decoder<BufReader<File>> {
|
||||
let file = BufReader::new(File::open(track.path).unwrap());
|
||||
let file = BufReader::new(File::open(track.file.get_path()).unwrap());
|
||||
Decoder::new(file).unwrap()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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::<Vec<&str>>()
|
||||
.join("\n");
|
||||
}
|
||||
|
|
|
|||
11
src/track.rs
11
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 }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue