"null",
"-",
]
- async with AsyncProcess(proc_args, True, use_stderr=True) as ffmpeg_proc:
+ async with AsyncProcess(
+ proc_args, True, enable_stdout=False, enable_stderr=True
+ ) as ffmpeg_proc:
async def writer():
"""Task that grabs the source audio and feeds it to ffmpeg."""
streamdetails, pcm_fmt, pcm_sample_rate=sample_rate, pcm_channels=channels
)
async with AsyncProcess(
- args, enable_write=True, chunk_size=chunk_size
+ args, enable_stdin=True, chunk_size=chunk_size
) as ffmpeg_proc:
LOGGER.debug(
def __init__(
self,
args: Union[List, str],
- enable_write: bool = False,
+ enable_stdin: bool = False,
chunk_size: int = DEFAULT_CHUNKSIZE,
- use_stderr: bool = False,
+ enable_stdout: bool = True,
+ enable_stderr: bool = False,
):
"""Initialize."""
self._proc = None
self._args = args
- self._use_stderr = use_stderr
- self._enable_write = enable_write
+ self._enable_stdin = enable_stdin
+ self.chunk_size = chunk_size or DEFAULT_CHUNKSIZE
+ self._enable_stdout = enable_stdout
+ self._enable_stderr = enable_stderr
self._attached_task: asyncio.Task = None
self.closed = False
- self.chunk_size = chunk_size or DEFAULT_CHUNKSIZE
async def __aenter__(self) -> "AsyncProcess":
"""Enter context manager."""
if isinstance(args, str):
self._proc = await asyncio.create_subprocess_shell(
args,
- stdin=asyncio.subprocess.PIPE if self._enable_write else None,
- stdout=asyncio.subprocess.PIPE if not self._use_stderr else None,
- stderr=asyncio.subprocess.PIPE if self._use_stderr else None,
+ stdin=asyncio.subprocess.PIPE if self._enable_stdin else None,
+ stdout=asyncio.subprocess.PIPE if self._enable_stdout else None,
+ stderr=asyncio.subprocess.PIPE if self._enable_stderr else None,
limit=self.chunk_size * 5,
close_fds=True,
)
else:
self._proc = await asyncio.create_subprocess_exec(
*args,
- stdin=asyncio.subprocess.PIPE if self._enable_write else None,
- stdout=asyncio.subprocess.PIPE if not self._use_stderr else None,
- stderr=asyncio.subprocess.PIPE if self._use_stderr else None,
+ stdin=asyncio.subprocess.PIPE if self._enable_stdin else None,
+ stdout=asyncio.subprocess.PIPE if self._enable_stdout else None,
+ stderr=asyncio.subprocess.PIPE if self._enable_stderr else None,
limit=self.chunk_size * 5,
close_fds=True,
)
pass
if self._proc.returncode is None:
# prevent subprocess deadlocking, read remaining bytes
- await self._proc.communicate(b"" if self._enable_write else None)
+ await self._proc.communicate(b"" if self._enable_stdin else None)
if self._proc.returncode is None:
# just in case?
self._proc.kill()
bytes_sent += len(chunk)
# TEMP: diagnose issues with librespot dump details
if bytes_sent < 100:
- async with AsyncProcess(args, use_stderr=True) as librespot_proc:
- _, stderr = await librespot_proc.communicate()
- raise AudioError(f"Error getting stream from librespot: {stderr.decode()}")
+ async with AsyncProcess(args, enable_stderr=True) as librespot_proc:
+ stdout, stderr = await librespot_proc.communicate()
+ if len(stdout) > 512000:
+ yield stdout
+ return
+ raise AudioError(
+ "Error getting stream from librespot: "
+ f"err: {stderr.decode()} - "
+ f"out: {stdout.decode()} - "
+ f"binary: {librespot}"
+ )
async def _parse_artist(self, artist_obj):
"""Parse spotify artist object to generic layout."""