mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-04 10:19:27 +02:00
Fix --device
argument to various backends (#938)
Fix `--device` argument to various backends
This commit is contained in:
parent
a605444d18
commit
1e54913523
5 changed files with 42 additions and 57 deletions
|
@ -4,19 +4,27 @@ use crate::convert::Converter;
|
|||
use crate::decoder::AudioPacket;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::{self, Write};
|
||||
use std::process::exit;
|
||||
|
||||
pub struct StdoutSink {
|
||||
output: Option<Box<dyn Write>>,
|
||||
path: Option<String>,
|
||||
file: Option<String>,
|
||||
format: AudioFormat,
|
||||
}
|
||||
|
||||
impl Open for StdoutSink {
|
||||
fn open(path: Option<String>, format: AudioFormat) -> Self {
|
||||
fn open(file: Option<String>, format: AudioFormat) -> Self {
|
||||
if let Some("?") = file.as_deref() {
|
||||
info!("Usage:");
|
||||
println!(" Output to stdout: --backend pipe");
|
||||
println!(" Output to file: --backend pipe --device {{filename}}");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
info!("Using pipe sink with format: {:?}", format);
|
||||
Self {
|
||||
output: None,
|
||||
path,
|
||||
file,
|
||||
format,
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +33,12 @@ impl Open for StdoutSink {
|
|||
impl Sink for StdoutSink {
|
||||
fn start(&mut self) -> SinkResult<()> {
|
||||
if self.output.is_none() {
|
||||
let output: Box<dyn Write> = match self.path.as_deref() {
|
||||
Some(path) => {
|
||||
let output: Box<dyn Write> = match self.file.as_deref() {
|
||||
Some(file) => {
|
||||
let open_op = OpenOptions::new()
|
||||
.write(true)
|
||||
.open(path)
|
||||
.create(true)
|
||||
.open(file)
|
||||
.map_err(|e| SinkError::ConnectionRefused(e.to_string()))?;
|
||||
Box::new(open_op)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue