Skip to content

Latest commit

 

History

History
333 lines (227 loc) · 19 KB

File metadata and controls

333 lines (227 loc) · 19 KB

HA-NetMD - Control and listen to your MiniDisc everywhere!

HA-NetMD is a native Python Home Assistant integration for USB-connected NetMD players and recorders. It provides player controls, MiniDisc metadata and safe disc-management actions directly in Home Assistant.

Two optional companion setups are included in this repository:

  • NetMD Uploader converts and writes audio files to a MiniDisc. It runs in a separate Home Assistant add-on so that a long USB transfer cannot block Home Assistant Core. Its transfer engine is netmd-js/netmdcli, isolated inside that add-on.
  • MiniDisc audio stream takes the recorder's analogue line-in, publishes an MP3 stream at http://homeassistant.local:8888/live.mp3, and supplies ICY metadata for Music Assistant or another web-radio client.

The integration itself works without either optional setup.

Quick start

  1. Use a recorder/player that supports NetMD, connect it with a USB data cable, and insert a MiniDisc. A writable disc is required only for changing or uploading content.
  2. Install the integration through HACS or manually, then restart Home Assistant.
  3. Go to Settings → Devices & services → Add integration, select NetMD, and choose the connected player.
  4. Verify that the created media_player entity shows the disc title and track count. Playback controls and metadata work at this point; no extra add-on is required.
  5. Install the optional NetMD Uploader only when audio files should be written to a MiniDisc. Set up the optional streaming examples only when the recorder's analogue output should be listened to remotely.

The media-player entity exposes the original MiniDisc title in raw_track_title. Titles written as Artist - Title are additionally split into media_artist and media_title; titles in every other format remain intact.

Features

The integration provides playback, track selection, seeking, disc and track metadata, capacity sensors, and actions for renaming, moving, playing, deleting, formatting, and uploading tracks. A track named Artist - Title is exposed as separate artist and title metadata; all other titles remain unchanged. Track numbers in action data start at 1.

Actions

All actions are available in Developer tools → Actions and can also be used in automations. Select the NetMD media_player as target unless the action says otherwise.

Rename track

Rename a track on the inserted MiniDisc.

Target: Target NetMD Device or media_player entity.
Track Number: Track to be renamed. Track numbers start at 1.
Title: New Title of the Title.

Rename disc

Rename the inserted MiniDisc while preserving its group metadata.

Target: Target NetMD Device or media_player entity.
Title: New Title of the MiniDisc.

Move track

Move a track to another position.

Target: Target NetMD Device or media_player entity.
Source Track Number: Source Track number. Track numbers start at 1.
Destination Track Number: Destination Track number. Track numbers start at 1.

Delete track

Permanently delete a track from the inserted MiniDisc.

Target: Target NetMD Device or media_player entity.
Track Number: Track to be deleted. WARNING! This cannot be made undone! Track numbers start at 1.

Erase / format disc

Permanently delete every track on the inserted MiniDisc (the NetMD equivalent of formatting it). The service requires one explicit confirmation, so it remains straightforward in an automation:

action: netmd.erase_disc
target:
  entity_id: media_player.your_netmd
data:
  confirm: true

Upload audio track

Append an audio file stored below /media/netmd to a writable MiniDisc. This is a dedicated subfolder of Home Assistant's standard Media area, rather than the publicly served www directory. Create it once in the Media Browser or through Samba/file access. Install and start the local NetMD Uploader app from the Home Assistant app store first. It exclusively owns USB only while a transfer runs, so the potentially long NetMD bulk write cannot block Home Assistant Core. The app uses the same netmd-js transfer engine as Web MiniDisc, not a factory-mode exploit. By default, the source file is sent to atrac.minidisc.wiki for ATRAC conversion before it is transferred to the player.

action: netmd.upload_track
target:
  entity_id: media_player.your_netmd
data:
  source: /media/netmd/album.mp3
  title: Test track
  encoding: lp4
  encoder: local

title is optional and otherwise defaults to the source filename. encoding is lp2 by default; use lp4 to save disc space. Uploads can take several minutes and require a writable disc. For safety, files outside /media/netmd are rejected.

encoder defaults to remote, which sends the selected audio to atrac.minidisc.wiki for conversion. Set encoder: local to convert entirely inside the NetMD Uploader app, using its bundled atracdenc-rs encoder and FFmpeg; the audio file then never leaves Home Assistant. The local encoder is included in the add-on image and does not require a separate binary or an internet connection. The NetMD transfer itself uses netmd-js, the same stable protocol engine as Web MiniDisc. atracdenc-rs is distributed under LGPL-2.1; its source is vendored in addons/netmd_uploader/atracdenc-rs for reproducible add-on builds.

While the app writes, the media-player attributes upload_status, upload_written_bytes, upload_total_bytes, and upload_progress_percent report the transfer state. Progress is available when the NetMD command-line engine emits byte counters; encoding itself has no reliable percentage.

Groups

Existing group names are listed in the groups attribute of the NetMD media player. The services netmd.create_group, netmd.rename_group, and netmd.delete_group manage those groups; their group numbers start at 1. Deleting a group only removes its group metadata, never its tracks.

Play track

Select and play a track.

Target: Target NetMD Device or media_player entity.
Track Number: Track to be played. Track numbers start at 1.

Fast forward

Start fast-forwarding the current track on the inserted MiniDisc.

Target: Target NetMD Device or media_player entity.

Rewind

Start rewinding the current track on the inserted MiniDisc.

Target: Target NetMD Device or media_player entity.

HACS Install

  1. Open HACS → Integrations → ⋮ → Custom repositories.
  2. Add https://github.com/dreimer1986/HA-NetMD with category Integration.
  3. Find and install HA-NetMD, then restart Home Assistant.
  4. Add the integration under Settings → Devices & services.

HACS installs and updates only custom_components/netmd. It does not install or update the optional NetMD Uploader add-on; see the next section for that separate step.

Manual Install

Copy the complete netmd directory to /config/custom_components/netmd, restart Home Assistant, connect the NetMD device over USB, and add NetMD under Settings → Devices & services.

  • Home Assistant OS normally exposes the USB bus to Core automatically.
  • Container installations must pass /dev/bus/usb through to the Home Assistant container.

When updating manually, replace the complete netmd directory and restart Home Assistant. Do not copy Python __pycache__ directories.

NetMD Uploader add-on

The uploader is optional and is needed only for netmd.upload_track. It must be installed separately from the HACS integration.

Automatic installation

  1. Open Settings → Add-ons in Home Assistant and click on Install App.
  2. Click on the ... Menu on the Top right and in there Repositories.
  3. Click on Add and insert https://github.com/dreimer1986/netmd_uploader as URL.
  4. Select NetMD Uploader, and install/start it.
  5. Create /media/netmd through Samba, File Editor, or a terminal, then put audio files there.
  6. Use netmd.upload_track from Developer tools → Actions or from an automation. The player must be connected and the disc writable.

Manual installation

  1. Copy the complete repository folder addons/netmd_uploader to Home Assistant's local add-on directory as netmd_uploader (for example /addons/netmd_uploader). Keep the bundled atracdenc-rs folder; it is the reproducible local encoder source.
  2. In Settings → Add-ons, refresh local add-ons, select NetMD Uploader, and install/start it.
  3. Create /media/netmd through Samba, File Editor, or a terminal, then put audio files there.
  4. Use netmd.upload_track from Developer tools → Actions or from an automation. The player must be connected and the disc writable.

After a Git update, update the HACS integration and the local add-on independently. The add-on version is shown in its Home Assistant details page.

The uploader accepts only files below /media/netmd; this prevents accidental access to configuration files and avoids using the public /config/www directory. encoder: remote is the default and sends the audio file to atrac.minidisc.wiki for conversion. Choose encoder: local when the file must remain inside Home Assistant; that encoder needs no internet connection but can take a little longer.

Optional audio stream setup

This setup is independent of USB/NetMD control: connect the MiniDisc recorder's analogue output to a line-in on the Home Assistant host. The supplied script reads that line-in and publishes an MP3/ICY web-radio stream. It is useful for listening in Music Assistant, but is not needed for controlling the recorder or uploading tracks.

Automations.yaml

The files configuration.yaml, automations.yaml, and scripts/minidisc_stream.py are optional examples for the audio-stream setup, not a requirement for the NetMD integration or uploader. Read and adapt them before copying anything:

  • Replace media_player.sony_mz_n505 with your own NetMD player entity.
  • Replace the PulseAudio line-in source with your own USB sound device.
  • The examples require FFmpeg and use TCP port 8888; make sure the port is not already occupied.
  • Import the individual automations in the Home Assistant automation editor, or convert them into your own existing automation include format. Do not blindly replace an existing automations.yaml.

MiniDisc Start

This automation waits for the NetMD media_player entity to start playback or come online. If this happens it starts the FFmpeg stream.

MiniDisc Stop

This automation waits for the NetMD media_player entity to stop playback or become offline. If this happens it stops the FFmpeg stream.

MiniDisc Stream Metadata Update

This automation feeds the recent metadata back into the Python Script where these are integrated into the ICY metadata of the stream.

Configuration.yaml

shell_command

set_minidisc_linein_port

Only needed if your pulse audio sink switches back to microphone port as default after reboot.

set_minidisc_linein_vol

Only needed if your line-in volume needs to be set back to 70% after reboot.

The last two are only there for reference. I don't need them anymore after I used both once.

command_line

FFmpeg Stream

This switch controls the running as background process FFmpeg with the sound card's line-in as input and the URL on port 8888 as stream in MP3 format as output. To allow more than one connection and stay alive when the stream is stopped for a short while a Python script is now creating a asynchronous web server that hosts the FFmpeg conversion via pipe.

FFmpeg Status

This sensor outputs the last line of the debug log the stream service creates. Thus you can follow problems showing up by checking this sensor.

MiniDisc Streamer Status

This sensor outputs if the FFmpeg process is running or not. It verifies this by checking if the PID that was logged when FFmpeg was started is still active or not.

rest_command

update_minidisc_stream

This command is meant as way back into the Python script and allows to send the metatadata of the currently running tracks into the stream.

Finding the line-in source

alsa_input.usb-0d8c_USB_Sound_Device-00.analog-stereo is the line-in source on the author's host. You must find and replace it with your own source before using the examples. pactl list | less lists the available PulseAudio sources.

SSH

The two optional shell_command examples use the SSH add-on to run pactl on the host audio service. This is an advanced, host-specific configuration; skip it unless the line-in source or volume is reset after a reboot.

mkdir -p /config/.ssh
cd /config/.ssh
ssh-keygen -t rsa -b 4096 -f /config/.ssh/id_rsa -N ""
chmod 700 /config/.ssh
chmod 600 /config/.ssh/id_rsa
chmod 644 /config/.ssh/id_rsa.pub

Now you can use the shell commands I made for that.

Playback with Music Assistant

Music Assistant is one option for playing the optional MP3/ICY stream. Complete the optional stream setup first and confirm that http://<home-assistant-host>:8888/live.mp3 plays in a browser on your network.

  1. Install the Music Assistant add-on from the Home Assistant add-on store and configure one or more playback providers.

  2. Optionally copy custom_components/netmd/brand/icon.png to /config/www/icon.png to give the radio station a custom image. This public web asset is unrelated to the protected /media/netmd upload folder.

  3. In Music Assistant, open Radios, select the menu in the upper-right corner, and choose Add by URL.

Music Assistant Radio Stream Setup

  1. Enter the stream URL using your Home Assistant hostname or IP address, for example http://homeassistant.local:8888/live.mp3.

Music Assistant Radio Stream Setup 2

  1. The radio can now be selected as a source for any Music Assistant player. It has been tested with the Music Assistant mobile app, Android Auto, and CarPlay.

Music Assistant Radio Stream Setup 3

Troubleshooting

Symptom Check
No NetMD device appears Use a USB data cable, wake the recorder from standby, reconnect it, and verify that the Home Assistant container has access to /dev/bus/usb.
Player is unavailable during an upload This is expected. The uploader temporarily owns USB exclusively; wait for upload_status to become completed or failed.
Upload is rejected before it starts Confirm that the file exists below /media/netmd, the disc is inserted and writable, and the NetMD Uploader add-on is started.
Upload appears to pause near 100% Some recorders, including the Sony MZ-N505, do not return a final protocol reply. The add-on verifies completion through the increased track count.
Artist is missing Only titles written exactly as Artist - Title can be split automatically. The complete, unmodified value is always available as raw_track_title.
Stream has no audio The streaming example needs an analogue line-in path from the MiniDisc player to the Home Assistant host; NetMD USB itself does not carry the playback audio.

Pictures

My Home Assistant Server based on a NUC7I7BNB, a CC2652 Dev board for Zigbee, a USB Sound Card and a Sonoff Zigbee USB Dongle for Matter/Thread

Host Hardware

The Add-On running inside Home Assistant.

Home Assistant Entities

Metadata sent to the media players over ICY protocol.

Currently playing track

Pics from usage on my Pixel 7 Pro:

Listening to the Add-On's stream inside Music Assistant.

Playback in Music Assistant

Splitscreen: Controlling the current track being played back via Home Assistant app (below) and listening to the Add-On's stream inside Music Assistant (above)

Splitscreen controlling and listening