1
0
Fork 0
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:
Roderick van Domburg 2022-01-14 08:20:29 +01:00 committed by GitHub
parent a605444d18
commit 1e54913523
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 57 deletions

View file

@ -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)
}