log_line.save()
async def player_process(self, item, timeout=None):
+ if app_settings.PLAYER_IPC_PATH:
+ return await self.player_process_ipc(item, timeout=timeout)
cmd = [app_settings.PLAYER_COMMAND] + app_settings.PLAYER_ARGS
if hasattr(item, 'is_stream') and item.is_stream():
cmd.append(item.stream.url)
self.player.kill()
self.player = None
+ async def player_process_ipc(self, item, timeout=None):
+ starting = False
+ while True:
+ try:
+ reader, writer = await asyncio.open_unix_connection(
+ app_settings.PLAYER_IPC_PATH)
+ break
+ except (FileNotFoundError, ConnectionRefusedError):
+ if not starting:
+ cmd = [app_settings.PLAYER_COMMAND] + app_settings.PLAYER_ARGS
+ cmd += ['--input-ipc-server=%s' % app_settings.PLAYER_IPC_PATH, '--idle']
+ self.player = await asyncio.create_subprocess_exec(
+ *cmd,
+ stdout=asyncio.subprocess.DEVNULL,
+ stderr=asyncio.subprocess.DEVNULL)
+ starting = True
+ await asyncio.sleep(0.1)
+
+ if hasattr(item, 'is_stream') and item.is_stream():
+ file_path = item.stream.url
+ logger.info('Play stream: %s', item.stream.url)
+ else:
+ file_path = item.file_path()
+ logger.info('Play file: %s', item.file_path())
+
+ writer.write(json.dumps({'command': ['loadfile', file_path]}).encode() + b'\n')
+ try:
+ await writer.drain()
+ except ConnectionResetError: # connection lost
+ return
+ try:
+ await asyncio.wait_for(self.player_ipc_idle(reader, writer), timeout=timeout)
+ except asyncio.TimeoutError:
+ pass
+ writer.close()
+ await writer.wait_closed()
+
+ async def player_ipc_idle(self, reader, writer):
+ while True:
+ data = await reader.readline()
+ if not data:
+ break
+ if json.loads(data) == {'event': 'idle'}:
+ break
+
async def play(self, slot):
now = datetime.datetime.now()
if isinstance(slot, Nonstop):