DRY up the routes

patch bump
This commit is contained in:
onyx-and-iris 2026-04-05 04:34:40 +01:00
parent 9760bc8338
commit 6476be53c5
10 changed files with 52 additions and 52 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "vmr-http" name = "vmr-http"
version = "0.4.0" version = "0.4.1"
description = "HTTP API for controlling Voicemeeter" description = "HTTP API for controlling Voicemeeter"
readme = "README.md" readme = "README.md"
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }] authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]

View File

@ -27,8 +27,8 @@ app = FastAPI(
{'name': 'bus', 'description': 'Endpoints for controlling bus parameters.'}, {'name': 'bus', 'description': 'Endpoints for controlling bus parameters.'},
], ],
) )
app.include_router(strip.router, prefix='/strip') app.include_router(strip.router, prefix='/strip/{index}')
app.include_router(bus.router, prefix='/bus') app.include_router(bus.router, prefix='/bus/{index}')
@app.get('/health') @app.get('/health')

View File

@ -8,12 +8,12 @@ from vmr_http.models.bus import BusParams
from . import busmode, eq from . import busmode, eq
router = APIRouter() router = APIRouter()
router.include_router(busmode.router, tags=['bus mode']) router.include_router(busmode.router, prefix='/mode', tags=['bus mode'])
router.include_router(eq.router, tags=['bus eq']) router.include_router(eq.router, prefix='/eq', tags=['bus eq'])
@router.patch('/{index}', tags=['bus']) @router.patch('', tags=['bus'])
@router.put('/{index}', tags=['bus']) @router.put('', tags=['bus'])
async def update_bus_params(index: int, params: BusParams, voicemeeter=Depends(get_voicemeeter_client)): async def update_bus_params(index: int, params: BusParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more parameters for the specified bus index.""" """Update one or more parameters for the specified bus index."""
bus = voicemeeter.bus[index] bus = voicemeeter.bus[index]
@ -24,19 +24,19 @@ async def update_bus_params(index: int, params: BusParams, voicemeeter=Depends(g
return updated return updated
@router.get('/{index}/gain', tags=['bus']) @router.get('/gain', tags=['bus'])
async def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gain value for the specified bus index.""" """Get the current gain value for the specified bus index."""
return {'gain': voicemeeter.bus[index].gain} return {'gain': voicemeeter.bus[index].gain}
@router.get('/{index}/mute', tags=['bus']) @router.get('/mute', tags=['bus'])
async def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mute status for the specified bus index.""" """Get the current mute status for the specified bus index."""
return {'mute': voicemeeter.bus[index].mute} return {'mute': voicemeeter.bus[index].mute}
@router.get('/{index}/mono', tags=['bus']) @router.get('/mono', tags=['bus'])
async def get_mono(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_mono(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mono status for the specified bus index.""" """Get the current mono status for the specified bus index."""
opts = ['Off', 'On', 'Stereo Reverse'] opts = ['Off', 'On', 'Stereo Reverse']

View File

@ -23,8 +23,8 @@ _readable_busmodes = {
_reversed_busmodes = {v: k for k, v in _readable_busmodes.items()} _reversed_busmodes = {v: k for k, v in _readable_busmodes.items()}
@router.patch('/{index}/mode') @router.patch('')
@router.put('/{index}/mode') @router.put('')
async def update_bus_mode(index: int, mode: str = Body(..., embed=True), voicemeeter=Depends(get_voicemeeter_client)): async def update_bus_mode(index: int, mode: str = Body(..., embed=True), voicemeeter=Depends(get_voicemeeter_client)):
"""Update the bus mode for the specified bus index.""" """Update the bus mode for the specified bus index."""
if mode not in _reversed_busmodes: if mode not in _reversed_busmodes:
@ -35,7 +35,7 @@ async def update_bus_mode(index: int, mode: str = Body(..., embed=True), voiceme
return {'mode': _readable_busmodes[_reversed_busmodes[mode]]} return {'mode': _readable_busmodes[_reversed_busmodes[mode]]}
@router.get('/{index}/mode') @router.get('')
async def get_bus_mode(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_bus_mode(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current bus mode for the specified bus index.""" """Get the current bus mode for the specified bus index."""
return {'mode': _readable_busmodes.get(voicemeeter.bus[index].mode.get(), 'Unknown')} return {'mode': _readable_busmodes.get(voicemeeter.bus[index].mode.get(), 'Unknown')}

View File

@ -8,8 +8,8 @@ from vmr_http.models.eq import EQChannelCellParams
cell_router = APIRouter() cell_router = APIRouter()
@cell_router.patch('/{cell_index}') @cell_router.patch('')
@cell_router.put('/{cell_index}') @cell_router.put('')
async def update_strip_eq_channel_cell_params( async def update_strip_eq_channel_cell_params(
index: int, index: int,
channel_index: int, channel_index: int,
@ -26,7 +26,7 @@ async def update_strip_eq_channel_cell_params(
return updated return updated
@cell_router.get('/{cell_index}/on') @cell_router.get('/on')
async def get_strip_eq_channel_cell_on( async def get_strip_eq_channel_cell_on(
index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client)
): ):
@ -34,7 +34,7 @@ async def get_strip_eq_channel_cell_on(
return {'on': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].on} return {'on': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].on}
@cell_router.get('/{cell_index}/type') @cell_router.get('/type')
async def get_strip_eq_channel_cell_type( async def get_strip_eq_channel_cell_type(
index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client)
): ):
@ -42,7 +42,7 @@ async def get_strip_eq_channel_cell_type(
return {'type': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].type} return {'type': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].type}
@cell_router.get('/{cell_index}/f') @cell_router.get('/f')
async def get_strip_eq_channel_cell_f( async def get_strip_eq_channel_cell_f(
index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client)
): ):
@ -50,7 +50,7 @@ async def get_strip_eq_channel_cell_f(
return {'f': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].f} return {'f': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].f}
@cell_router.get('/{cell_index}/gain') @cell_router.get('/gain')
async def get_strip_eq_channel_cell_gain( async def get_strip_eq_channel_cell_gain(
index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client)
): ):
@ -58,7 +58,7 @@ async def get_strip_eq_channel_cell_gain(
return {'gain': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].gain} return {'gain': voicemeeter.strip[index].eq.channel[channel_index].cell[cell_index].gain}
@cell_router.get('/{cell_index}/q') @cell_router.get('/q')
async def get_strip_eq_channel_cell_q( async def get_strip_eq_channel_cell_q(
index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client) index: int, channel_index: int, cell_index: int, voicemeeter=Depends(get_voicemeeter_client)
): ):
@ -67,11 +67,11 @@ async def get_strip_eq_channel_cell_q(
router = APIRouter() router = APIRouter()
router.include_router(cell_router, prefix='/{index}/eq/channel/{channel_index}/cell') router.include_router(cell_router, prefix='/channel/{channel_index}/cell/{cell_index}')
@router.patch('/{index}/eq') @router.patch('')
@router.put('/{index}/eq') @router.put('')
async def update_strip_eq_params( async def update_strip_eq_params(
index: int, on: bool = Body(..., embed=True), voicemeeter=Depends(get_voicemeeter_client) index: int, on: bool = Body(..., embed=True), voicemeeter=Depends(get_voicemeeter_client)
): ):
@ -81,7 +81,7 @@ async def update_strip_eq_params(
return {'on': strip_eq.on} return {'on': strip_eq.on}
@router.get('/{index}/eq/on') @router.get('/on')
async def get_strip_eq_on(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_strip_eq_on(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current equalizer on status for the specified strip index.""" """Get the current equalizer on status for the specified strip index."""
return {'on': voicemeeter.strip[index].eq.on} return {'on': voicemeeter.strip[index].eq.on}

View File

@ -8,14 +8,14 @@ from vmr_http.models.strip import StripParams
from . import eq, stripcomp, stripdenoiser, stripgate from . import eq, stripcomp, stripdenoiser, stripgate
router = APIRouter() router = APIRouter()
router.include_router(stripcomp.router, tags=['strip comp']) router.include_router(stripcomp.router, prefix='/comp', tags=['strip comp'])
router.include_router(stripgate.router, tags=['strip gate']) router.include_router(stripgate.router, prefix='/gate', tags=['strip gate'])
router.include_router(stripdenoiser.router, tags=['strip denoiser']) router.include_router(stripdenoiser.router, prefix='/denoiser', tags=['strip denoiser'])
router.include_router(eq.router, tags=['strip eq']) router.include_router(eq.router, prefix='/eq', tags=['strip eq'])
@router.patch('/{index}', tags=['strip']) @router.patch('', tags=['strip'])
@router.put('/{index}', tags=['strip']) @router.put('', tags=['strip'])
async def update_strip_params(index: int, params: StripParams, voicemeeter=Depends(get_voicemeeter_client)): async def update_strip_params(index: int, params: StripParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more parameters for the specified strip index.""" """Update one or more parameters for the specified strip index."""
strip = voicemeeter.strip[index] strip = voicemeeter.strip[index]
@ -26,73 +26,73 @@ async def update_strip_params(index: int, params: StripParams, voicemeeter=Depen
return updated return updated
@router.get('/{index}/gain', tags=['strip']) @router.get('/gain', tags=['strip'])
async def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_gain(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gain value for the specified strip index.""" """Get the current gain value for the specified strip index."""
return {'gain': voicemeeter.strip[index].gain} return {'gain': voicemeeter.strip[index].gain}
@router.get('/{index}/mute', tags=['strip']) @router.get('/mute', tags=['strip'])
async def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_mute(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mute status for the specified strip index.""" """Get the current mute status for the specified strip index."""
return {'mute': voicemeeter.strip[index].mute} return {'mute': voicemeeter.strip[index].mute}
@router.get('/{index}/mono', tags=['strip']) @router.get('/mono', tags=['strip'])
async def get_mono(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_mono(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current mono status for the specified strip index.""" """Get the current mono status for the specified strip index."""
return {'mono': voicemeeter.strip[index].mono} return {'mono': voicemeeter.strip[index].mono}
@router.get('/{index}/solo', tags=['strip']) @router.get('/solo', tags=['strip'])
async def get_solo(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_solo(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current solo status for the specified strip index.""" """Get the current solo status for the specified strip index."""
return {'solo': voicemeeter.strip[index].solo} return {'solo': voicemeeter.strip[index].solo}
@router.get('/{index}/A1', tags=['strip']) @router.get('/A1', tags=['strip'])
async def get_A1(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_A1(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A1 output status for the specified strip index.""" """Get the current A1 output status for the specified strip index."""
return {'A1': voicemeeter.strip[index].A1} return {'A1': voicemeeter.strip[index].A1}
@router.get('/{index}/A2', tags=['strip']) @router.get('/A2', tags=['strip'])
async def get_A2(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_A2(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A2 output status for the specified strip index.""" """Get the current A2 output status for the specified strip index."""
return {'A2': voicemeeter.strip[index].A2} return {'A2': voicemeeter.strip[index].A2}
@router.get('/{index}/A3', tags=['strip']) @router.get('/A3', tags=['strip'])
async def get_A3(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_A3(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A3 output status for the specified strip index.""" """Get the current A3 output status for the specified strip index."""
return {'A3': voicemeeter.strip[index].A3} return {'A3': voicemeeter.strip[index].A3}
@router.get('/{index}/A4', tags=['strip']) @router.get('/A4', tags=['strip'])
async def get_A4(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_A4(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A4 output status for the specified strip index.""" """Get the current A4 output status for the specified strip index."""
return {'A4': voicemeeter.strip[index].A4} return {'A4': voicemeeter.strip[index].A4}
@router.get('/{index}/A5', tags=['strip']) @router.get('/A5', tags=['strip'])
async def get_A5(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_A5(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current A5 output status for the specified strip index.""" """Get the current A5 output status for the specified strip index."""
return {'A5': voicemeeter.strip[index].A5} return {'A5': voicemeeter.strip[index].A5}
@router.get('/{index}/B1', tags=['strip']) @router.get('/B1', tags=['strip'])
async def get_B1(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_B1(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B1 output status for the specified strip index.""" """Get the current B1 output status for the specified strip index."""
return {'B1': voicemeeter.strip[index].B1} return {'B1': voicemeeter.strip[index].B1}
@router.get('/{index}/B2', tags=['strip']) @router.get('/B2', tags=['strip'])
async def get_B2(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_B2(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B2 output status for the specified strip index.""" """Get the current B2 output status for the specified strip index."""
return {'B2': voicemeeter.strip[index].B2} return {'B2': voicemeeter.strip[index].B2}
@router.get('/{index}/B3', tags=['strip']) @router.get('/B3', tags=['strip'])
async def get_B3(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_B3(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current B3 output status for the specified strip index.""" """Get the current B3 output status for the specified strip index."""
return {'B3': voicemeeter.strip[index].B3} return {'B3': voicemeeter.strip[index].B3}

View File

@ -8,8 +8,8 @@ from vmr_http.models.strip import StripCompParams
router = APIRouter() router = APIRouter()
@router.patch('/{index}/comp') @router.patch('')
@router.put('/{index}/comp') @router.put('')
async def update_strip_comp_params(index: int, params: StripCompParams, voicemeeter=Depends(get_voicemeeter_client)): async def update_strip_comp_params(index: int, params: StripCompParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more compressor parameters for the specified strip index.""" """Update one or more compressor parameters for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp strip_comp = voicemeeter.strip[index].comp
@ -20,7 +20,7 @@ async def update_strip_comp_params(index: int, params: StripCompParams, voicemee
return updated return updated
@router.get('/{index}/comp/knob') @router.get('/knob')
async def get_strip_comp_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_strip_comp_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current compressor knob value for the specified strip index.""" """Get the current compressor knob value for the specified strip index."""
strip_comp = voicemeeter.strip[index].comp strip_comp = voicemeeter.strip[index].comp

View File

@ -8,8 +8,8 @@ from vmr_http.models.strip import StripDenoiserParams
router = APIRouter() router = APIRouter()
@router.patch('/{index}/denoiser') @router.patch('')
@router.put('/{index}/denoiser') @router.put('')
async def update_strip_denoiser_params( async def update_strip_denoiser_params(
index: int, params: StripDenoiserParams, voicemeeter=Depends(get_voicemeeter_client) index: int, params: StripDenoiserParams, voicemeeter=Depends(get_voicemeeter_client)
): ):
@ -22,7 +22,7 @@ async def update_strip_denoiser_params(
return updated return updated
@router.get('/{index}/denoiser/knob') @router.get('/knob')
async def get_strip_denoiser_knob( async def get_strip_denoiser_knob(
index: int, index: int,
voicemeeter=Depends(get_voicemeeter_client), voicemeeter=Depends(get_voicemeeter_client),

View File

@ -8,8 +8,8 @@ from vmr_http.models.strip import StripGateParams
router = APIRouter() router = APIRouter()
@router.patch('/{index}/gate') @router.patch('')
@router.put('/{index}/gate') @router.put('')
async def update_strip_gate_params(index: int, params: StripGateParams, voicemeeter=Depends(get_voicemeeter_client)): async def update_strip_gate_params(index: int, params: StripGateParams, voicemeeter=Depends(get_voicemeeter_client)):
"""Update one or more gate parameters for the specified strip index.""" """Update one or more gate parameters for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate strip_gate = voicemeeter.strip[index].gate
@ -20,7 +20,7 @@ async def update_strip_gate_params(index: int, params: StripGateParams, voicemee
return updated return updated
@router.get('/{index}/gate/knob') @router.get('/knob')
async def get_strip_gate_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)): async def get_strip_gate_knob(index: int, voicemeeter=Depends(get_voicemeeter_client)):
"""Get the current gate knob value for the specified strip index.""" """Get the current gate knob value for the specified strip index."""
strip_gate = voicemeeter.strip[index].gate strip_gate = voicemeeter.strip[index].gate

2
uv.lock generated
View File

@ -1151,7 +1151,7 @@ wheels = [
[[package]] [[package]]
name = "vmr-http" name = "vmr-http"
version = "0.4.0" version = "0.4.1"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "fastapi" }, { name = "fastapi" },