User Tools

Site Tools


netmdpython

NetMDPython

NetMDPython is a collection of Python scripts which allow to control NetMD devices on Linux, Unix and MacOS X (Windows is unfortunately not yet supported since libusb is too old on Windows). With NetMD Python, you can upload tracks from standard MDs with the help of the MZ-RH1 Walkman to your PC, list the contents of any standard MD with any NetMD device and control and record tracks over analog input with any NetMD device. A recently added and therefore still very hacky script called "downloadhack.py" allows to download tracks to a NetMD.

Requirements

Before the Python code for NetMD can be used, git, libusb-1 and python 2.4+ with ctypes need to be installed. A development version of ffmpeg is required to convert uploaded ATRAC tracks to other formats. In order to be able to obtain this version of ffmpeg, subversion must be installed (which is the case on MacOS X by default but not on Ubuntu for example). Depending on your operating system, the installation is slightly different:

MacOS

Download and install Macports: http://www.macports.org.

After installing macports, you'll need to modify your .bashrc in your home-directory by adding "/opt/local/bin" to the PATH-environment. In a terminal (Applications→Utilities→Terminal), as normal user, type:

echo "PATH=$PATH:/opt/local/bin" >> ~/.bashrc

Then install the ports git-core and libusb from Macports:

sudo port install libusb git-core py26-crypto sox

Debian and Ubuntu

sudo apt-get install python2.6 libusb-dev git-core subversion python-crypto sox

Windows

Download and install Python2.6, PyCrypto and sox.

Download zadig.exe (WinUSB device driver installer), connect your NetMD device and run zadig.exe.

Click Options→List all devices, choose your NetMD device an choose Install Driver. NOTE: SonicStage will not be able to communicate with your NetMD device anymore. If you want to use SonicStage again, you will have to uninstall WinUSB device driver first. (To uninstall the driver, run Windows "Device Manager", choose your device and uninstall it, you can find it at "libusb (WinUSB) devices". Then unplug and reconnect your device).

Download latest version of python-libusb1 and replace usb1.py and libusb1.py in the netmd subdirectory of your linux-minidisc folder with the python-libusb1 versions. These versions can find and open libusb Windows DLL which has not been implemented in usb1.py and libusb1.py of current main source repository yet.

Download and extract libusb windows backend and copy libusb1.0.dll to your windows/system32 folder (usually C:\WINDOWS\system32). Use the version according to your version of Windows, the mingw32 version should work on Windows XP 32-bit.

Open a command prompt (Click Start→Run, type cmd and press enter) and type

set PATH=<sox install dir>;%PATH%

to add the path of sox directory temporarily. (<sox install dir> means the path to your sox installation directory, usually C:\sox-14-3-1). To use it permanently you can add the path to your system variables.

If you want to use ffmpeg to convert uploaded files, you can download Windows binaries of ffmpeg. Extract it to a place of your choice and add the path of bin subdirectory to your PATH environment variable as described above.

set PATH=<ffmpeg install dir>\bin;%PATH%

To use the tools, change into netmd subdirectory of your linux-minidisc folder and run the scripts by their name (just type "dump_md.py", "upload.py", …) with parameters if required. See how_to_use_the_tools below.

Getting the code

To get the code, clone it with git as shown on the homepage.

The Python libnetmd can be found in the netmd subdirectory:

cd linux-minidisc/netmd

How to use the tools

lsmd.py - list the content of a standard MD on a NetMD Walkman

Usage

$ ./lsmd.py -h
Usage: lsmd.py [options]

Options:
  -h, --help            show this help message and exit
  -b BUS, --bus=BUS
  -d DEVICE, --device=DEVICE

Sample output

$ sudo ./lsmd.py
Disk (writable media, write-protected) 'Disc title ascii' DISC title wchar
Time used: 01:10:26+026 (94.55%)
20 tracks
000: 00:03:06+017 sp stereo unprotected 'Track title ascii' Track title wchar
[...]

dump_md.py - transfer tracks from a NetMD Walkman over remotely controlled analog audio extraction

Automated extraction of tracks from a MD. It does analog extraction, as there is no known way to extract tracks digitally (except for MZ-RH1 player). It encodes tracks into ogg in a subfolder of working directory named after disc title. Tracks are named as "%n - %t.ogg", %n being 2-digit track number starting at 01 and %t being the track title.

Note on wchar: If there is wchar version of a title set, it will take precedence over ascii title. This works for both disc and track titles.

Requirements

  • Audio card with analog input
  • Audio cable

Usage

$ ./dump_md.py -h
Usage: dump_md.py [options]

Options:
  -h, --help            show this help message and exit
  -b BUS, --bus=BUS
  -d DEVICE, --device=DEVICE
  -t TRACK_RANGE, --track-range=TRACK_RANGE

Sample output

$ sudo ./dump_md.py -t 1-3
Storing in DISC title wchar
Recording 01 - Track title wchar.ogg ( 00:03:06.033 )
Waiting for MD...

Input File     : 'default' (alsa)
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Sample Encoding: 16-bit Signed Integer PCM

In:0.00% 00:00:01.49 [00:00:00.00] Out:0     [      |      ]        Clip:0
[...]

upload.py - upload tracks from standard MDs using Sony's MZ-RH1/M200

This tool is used for digital upload of non-protected tracks (lsmd lists them as "unprotected"). It works with the MZ-RH1 HiMD Walkman only. Invocation has the same syntax as the dump_md utility, but the output format will be ".aea" for SP tracks (a format implemented by very recent versions of ffmpeg) and ".wav" for LP2/LP4 tracks. NOTE: While the files are really Windows-compatible WAV files, they still do contain the ATRAC3 encoded audio. To play them you need an ATRAC3 decoder. For Windows, that means you have to install the ATRAC3 decoder (acm file) in order for it work with Windows Media Player. Alternatively, you can install a recent version of VLC. On Linux, the ffmpeg project (and everything based on it) supports ATRAC3 encoded audio as well as ATRAC SP (version 0.6 or later).

This tool will silently skip protected tracks, so if you don't get the files you expect, check their protection status. There is no known way to unprotect a track using NetMD or HiMD players. All tracks uploaded by Sonic Stage are protected. Surprisingly, tracks uploaded by MD Simple Burner are not. To transfer tracks to the NetMD as unprotected, our "downloadhack.py" may be used as well.

Using upload.py and ffmpeg to upload tracks on MacOS X

  • install ffmpeg-devel (or ffmpeg, version 0.6 or later) for SP support:
  sudo port install ffmpeg-devel
  
  • OR alternatively install ffmpeg from svn:
  svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
  cd ffmpeg
  ./configure --prefix=/opt/local
  make
  sudo make install
  
  • install the dependencies as shown here
  • insert the MD to be uploaded into your MZ-RH1, connect it to your Mac and invoke upload.py:
  cd linux-minidisc/netmd
  ./upload.py
  
  • convert a track into WAV format:
  ffmpeg -i <filename of MD track to be converted> <name of WAV output file>
  
  • batch convert several tracks into AAC/MPEG4 audio:
  find . -type f | while read filename; do ffmpeg -i "$filename" -ab 256k "${filename%aea}mp4" ; done
  

Using upload.py and ffmpeg to upload tracks on Ubuntu

  • install the dependencies as shown here
  • install ffmpeg from the official repositories (you will need ffmpeg version 0.6 or later for ATRAC SP) to check, whether ffmpeg 0.6 or later is available, type:
  apt-cache show ffmpeg |grep Version
  Version: 5:0.6~svn20100603-0.0
  Version: 4:0.5.2-1
  
  • if the version listed corresponds to 0.6 or later, install ffmpeg directly:
  sudo apt-get install ffmpeg
  
  • if you cannot install 0.6 or later this way, install the build dependencies for ffmpeg and install it from svn:
  sudo apt-get build-dep ffmpeg
  cd /usr/src
  svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
  cd ffmpeg
  ./configure
  make
  sudo make install
  
  • insert the MD to be uploaded into your MZ-RH1, connect it to your Linux box and invoke upload.py:
  cd ~/linux-minidisc/netmd
  ./upload.py
  
  • convert a track into WAV format:
  ffmpeg -i <filename of MD track to be converted> <name of WAV output file>
  
  • batch convert several tracks into AAC/MPEG4 audio:
  find . -type f | while read filename; do ffmpeg -i "$filename" -ab 256k "${filename%aea}mp4" ; done
  

downloadhack.py - download tracks to NetMD (buggy)

Use this script download tracks to your NetMD Walkman. Note: This requires the NetMD root key from Sony which is not (yet) part of the official repository due to legal reasons.

mdctl.py - test libnetmd functionality (DEBUG use only)

This is in a more-than-primitive state. It is supposed to export all functions of libnetmd.py for easy command-line use. Currently, it's a brain-dead wrapper around a pdb shell. Use only if you know Python.

lsusb.py - list USB devices connected to the PC

This is just a toy to test usb1.py and libusb1.py. It looks a bit like regular lsusb, but fetches all its data from the USB device itself ("real" lsusb maintains a device/manufacturer list asides), which is much less readable (many devices are not correctly defined internally). Useful (…maybe not even) as a sample code using usb1.py.

Important notes regarding all tools:

  • Write access to usb device required (even for listing, as it requires sending usb commands). One way to obtain the rights on modern Linux distributions that use PolicyKit ist to add the portable_audio_player capability to the Net MD device using the provided fdi file (look in netmd/etc of the linux-minidisc tree). Another way is to run them with root permissions (not recommended) or make sure the device raw USB device (the file /dev/bus/usb/<bus>/<device>) gets read/write access by the user you want to use the tools with.
  • wchar encoding assumed to be always SHIFT-JIS. It is the case on my test MDs, which are rewritable medium recorded in japan.
  • This library was tested on a MZ-N910, YMMV with different hardware
  • No warranty. You get to keep the pieces if it breaks your MD player, r00ts y0ur b0x or eats your cat.

Most (all ?) those tools will iterate over all connected MD devices. They (should) offer -b and -d parameters to allow you to specify the usb bus and the device number you want to affect independently of others.

Library

Library documentation (…once written ;-) ) can be accessed by python regular documentation system:

pydoc libnetmd
netmdpython.txt · Last modified: 2013/05/16 11:39 by glaubitz

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki