forked from auracaster/bumble_mirror
simplify command line
This commit is contained in:
+18
-16
@@ -35,6 +35,7 @@ import bumble
|
|||||||
from bumble.colors import color
|
from bumble.colors import color
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT
|
from bumble.core import BT_BR_EDR_TRANSPORT
|
||||||
from bumble.device import Connection, Device, DeviceConfiguration, Peer
|
from bumble.device import Connection, Device, DeviceConfiguration, Peer
|
||||||
|
from bumble.hci import HCI_StatusError
|
||||||
from bumble.sdp import ServiceAttribute
|
from bumble.sdp import ServiceAttribute
|
||||||
from bumble.transport import open_transport
|
from bumble.transport import open_transport
|
||||||
from bumble.avdtp import (
|
from bumble.avdtp import (
|
||||||
@@ -187,7 +188,10 @@ class WebSocketOutput(QueuedOutput):
|
|||||||
self.send_message = send_message
|
self.send_message = send_message
|
||||||
|
|
||||||
async def on_connection(self, connection: Connection) -> None:
|
async def on_connection(self, connection: Connection) -> None:
|
||||||
await connection.request_remote_name()
|
try:
|
||||||
|
await connection.request_remote_name()
|
||||||
|
except HCI_StatusError:
|
||||||
|
pass
|
||||||
peer_name = '' if connection.peer_name is None else connection.peer_name
|
peer_name = '' if connection.peer_name is None else connection.peer_name
|
||||||
peer_address = str(connection.peer_address).replace('/P', '')
|
peer_address = str(connection.peer_address).replace('/P', '')
|
||||||
await self.send_message(
|
await self.send_message(
|
||||||
@@ -551,7 +555,6 @@ class Speaker:
|
|||||||
print(f'=== Connecting to {address}...')
|
print(f'=== Connecting to {address}...')
|
||||||
connection = await self.device.connect(address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await self.device.connect(address, transport=BT_BR_EDR_TRANSPORT)
|
||||||
print(f'=== Connected to {connection.peer_address}')
|
print(f'=== Connected to {connection.peer_address}')
|
||||||
self.on_bluetooth_connection(connection)
|
|
||||||
|
|
||||||
# Request authentication
|
# Request authentication
|
||||||
print('*** Authenticating...')
|
print('*** Authenticating...')
|
||||||
@@ -638,24 +641,16 @@ class Speaker:
|
|||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@click.group()
|
@click.group()
|
||||||
@click.option('--device-config', metavar='FILENAME', help='Device configuration file')
|
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def speaker_cli(ctx, device_config):
|
def speaker_cli(ctx, device_config):
|
||||||
ctx.ensure_object(dict)
|
ctx.ensure_object(dict)
|
||||||
ctx.obj['device_config'] = device_config
|
ctx.obj['device_config'] = device_config
|
||||||
|
|
||||||
|
|
||||||
@speaker_cli.command()
|
@click.command()
|
||||||
@click.argument('transport')
|
|
||||||
@click.option(
|
@click.option(
|
||||||
'--codec', type=click.Choice(['sbc', 'aac']), default='aac', show_default=True
|
'--codec', type=click.Choice(['sbc', 'aac']), default='aac', show_default=True
|
||||||
)
|
)
|
||||||
@click.option(
|
|
||||||
'--connect',
|
|
||||||
'connect_address',
|
|
||||||
metavar='ADDRESS_OR_NAME',
|
|
||||||
help='Address or name to connect to',
|
|
||||||
)
|
|
||||||
@click.option(
|
@click.option(
|
||||||
'--discover', is_flag=True, help='Discover remote endpoints once connected'
|
'--discover', is_flag=True, help='Discover remote endpoints once connected'
|
||||||
)
|
)
|
||||||
@@ -676,9 +671,16 @@ def speaker_cli(ctx, device_config):
|
|||||||
show_default=True,
|
show_default=True,
|
||||||
help='HTTP port for the UI server',
|
help='HTTP port for the UI server',
|
||||||
)
|
)
|
||||||
@click.pass_context
|
@click.option(
|
||||||
def play(ctx, transport, codec, connect_address, discover, output, ui_port):
|
'--connect',
|
||||||
"""Run the speaker in playback mode."""
|
'connect_address',
|
||||||
|
metavar='ADDRESS_OR_NAME',
|
||||||
|
help='Address or name to connect to',
|
||||||
|
)
|
||||||
|
@click.option('--device-config', metavar='FILENAME', help='Device configuration file')
|
||||||
|
@click.argument('transport')
|
||||||
|
def speaker(transport, codec, connect_address, discover, output, ui_port, device_config):
|
||||||
|
"""Run the speaker."""
|
||||||
|
|
||||||
# ffplay only works with AAC for now
|
# ffplay only works with AAC for now
|
||||||
if codec != 'aac' and '@ffplay' in output:
|
if codec != 'aac' and '@ffplay' in output:
|
||||||
@@ -703,7 +705,7 @@ def play(ctx, transport, codec, connect_address, discover, output, ui_port):
|
|||||||
|
|
||||||
asyncio.run(
|
asyncio.run(
|
||||||
Speaker(
|
Speaker(
|
||||||
ctx.obj['device_config'], transport, codec, discover, output, ui_port
|
device_config, transport, codec, discover, output, ui_port
|
||||||
).run(connect_address)
|
).run(connect_address)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -711,7 +713,7 @@ def play(ctx, transport, codec, connect_address, discover, output, ui_port):
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper())
|
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper())
|
||||||
speaker_cli()
|
speaker()
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user