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 std::{path::Path, process::Command};
|
||||||
|
|
||||||
use crate::track::Track;
|
use crate::{file::FileHandle, track::Track};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct DownloadError;
|
pub struct DownloadError;
|
||||||
|
|
@ -32,5 +32,7 @@ pub fn download_from_youtube(url: &str) -> Result<Track, DownloadError> {
|
||||||
.replace('\n', "")
|
.replace('\n', "")
|
||||||
+ ".mp3";
|
+ ".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::fs;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FileHandle {
|
pub struct FileHandle {
|
||||||
|
|
@ -12,6 +12,10 @@ impl FileHandle {
|
||||||
path: PathBuf::from(path),
|
path: PathBuf::from(path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_path(&self) -> &Path {
|
||||||
|
&self.path
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for FileHandle {
|
impl Drop for FileHandle {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ struct Worker {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_source(track: Track) -> Decoder<BufReader<File>> {
|
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()
|
Decoder::new(file).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ impl TelegramBot {
|
||||||
} else {
|
} else {
|
||||||
message = tracks
|
message = tracks
|
||||||
.iter()
|
.iter()
|
||||||
.map(|t| t.path.to_str().unwrap())
|
.map(|t| t.file.get_path().to_str().unwrap())
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("\n");
|
.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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Track {
|
pub struct Track {
|
||||||
pub path: PathBuf,
|
pub file: FileHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Track {
|
impl Track {
|
||||||
pub fn new(path: &Path) -> Track {
|
pub fn new(file: FileHandle) -> Track {
|
||||||
Track {
|
Track { file }
|
||||||
path: PathBuf::from(path),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue