Traktor Now Playing
This project requires Python 3.8 or newer (tested on 3.8 through 3.14) and uses Traktor's broadcast functionality to extract metadata about the currently playing song. This is really a very thin wrapper around some tinytag methods that can be found in ogg.py, where the original license is also included. There are no dependencies. Tested with Traktor 3.3, but this will likely work with older versions as well.
The reason this exists is because it's rather difficult to get this information through other means. You can use MIDI for this as well, but that requires that you add a fake controller.
Lastly, there are several other projects that do something similar such as Traktor Metadata Listener which is not open-source and likely will never be, and traktor-now-playing, which uses the MIDI approach mentioned above.
Installation
The preferred installation method is via pip:
pip install traktor_nowplaying
There are also binary releases available for Windows, Linux, and MacOS. These are created using pyInstaller and GitHub actions and can be downloaded from the project Releases page.
General use
In order for this program to work, you of course have to setup the broadcasting feature of Traktor - note that this completely hijacks that functinality, so while you can still record and broadcast through some other means (eg. using a splitter or other outputs on your controller/mixer, or from the recording itself), you cannot broadcast from Traktor itself.
You must configure Traktor to broadcast to localhost and the port specified with the -p, or --port option (defaults to 8000), or the port that is passed to the constructor if you're using this as a library instead. For the format setting you can use anything, but I recommend choosing the lowest bitrate for the sample rate of your system, so most commonly the best choice is 44100 Hz, 64 Kbps.
Note that there is a delay between when you change a song in Traktor and when the change is picked up. This delay comes from Traktor itself: it buffers the audio before sending it, and it only sends the new track information once it has decided that the track has changed. traktor_nowplaying reports the change as soon as it arrives.
Also note that Traktor only sends the artist and title of the current track. Other information like BPM or key is not part of the broadcast, so traktor_nowplaying cannot provide it.
Use from command line
If you run the program without specifying any options you'll be asked if you want to set the options interactively, or you can hit enter which uses all default options, which are to listen on port 8000, and output the currently playing song to the console:
traktor_nowplaying
Listen on port 8000, output to nowplaying.txt in the current directory and do not output to stdout:
traktor_nowplaying --port 8000 --outfile='nowplaying.txt' --quiet
The help text:
$ traktor_nowplaying --help
usage: traktor_nowplaying [-h] [-p PORT] [-q] [-f FORMAT] [-o OUTFILE]
[-t TEMPLATE] [-a] [-m MAX_TRACKS] [-i] [-v]
Use Traktor's broadcast functionality to extract metadata about the currently
playing song
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT Port to listen on for broadcasts from Traktor
-q, --quiet Suppress console output of currently playing song
-f FORMAT, --format FORMAT
Custom format to use when outputting tracks
-o OUTFILE, --outfile OUTFILE
Provide a file path to which the currently playing song
should be written
-t TEMPLATE, --template TEMPLATE
Template file to use for output. Templating is
implemented using Bottle SimpleTemplate
(https://bottlepy.org/docs/0.13/stpl.html). See README
for more details on use. Note: the --format options is
ignored when using a custom template file. Take care
when using templates provided by others on the internet
as they can contain malicious code.
-a, --append If writing to file, appends newest track to end of file
instead of overwriting the file
-m MAX_TRACKS, --max-tracks MAX_TRACKS
If appending to a file, the maximum number of tracks to
keep in file (by default there is no limit)
-i, --interactive Interactive mode allows for settings to be specified at
runtime. These override command line options.
-v, --version show program's version number and exit
Note that you must configure Traktor to broadcast to localhost and the port
specified with the -p, or --port option (defaults to 8000). For the format
setting you can use anything, but I recommend choosing the lowest bitrate for
the sample rate of your system, so most commonly the best choice is 44100 Hz,
64 Kbps.
To stop the process Ctrl + C should suffice.
Using binary releases
If you've downloded a platform specific release from the Releases page, the use instructions are the same as described above for the command-line.
Use as a library
traktor_nowplaying can also be used as a library. This can be useful if you'd like to leverage this rather simple functionality in other code.
from traktor_nowplaying import Listener
listener = Listener(port=8000, quiet=True, outfile='nowplaying.txt')
listener.start()
Custom callbacks
If you'd like to do something with the track information yourself, pass a function as custom_callback. It will be called every time Traktor sends new track information, with a list of (field, value) tuples containing everything Traktor sent:
from traktor_nowplaying import Listener
def on_track_change(data):
info = dict(data)
print(f"{info.get('artist')} - {info.get('title')}")
print(data) # see everything that Traktor sent
listener = Listener(port=8000, quiet=True, custom_callback=on_track_change)
listener.start()
Note that listener.start() blocks, so there is no need for a loop to keep the program running.
For a more elaborate example with a custom callback, see this project: https://github.com/radusuciu/traktor_ice, and this bit in particular.
Customizing output
The output of traktor_nowplaying can be customized using the --format and --template options. Both of these functions make use of the SimpleTemplate Engine included with Bottle 0.13, so anything you can use with Bottle's templates, you can use here.
Note: Please take care when using format strings or templates provided by others on the internet. These can contain malicious code. I doubt this will be the case since this is such an obscure project and I can't imagine templates being complex enough to hide malware, but you never know.
--format
This option allows for the specification of alternate ways to display tracks. By default, tracks are formatted using a simple template: {{artist}} - {{title}}. You can change the order: {{title}} - {{artist}}, only display the title {{title}}, or sprinkle in some HTML: <p><strong>{{artist}}</strong> - {{title}}.
--template
While --format allows you to control the display of each individual track, --template allows you to specify a template file. This template file will be passed a tracks variable that contains a list of tracks to display. Each individual track is a Python dict with artist and title keys. Here's an example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
% for track in tracks:
<p><strong>{{track.get('artist', '')}}</strong> - {{track.get('title', '')}}</p>
% end
</body>
</html>
If you save the above as template.html you can use it like so: traktor_nowplaying --template template.html --append. Note that without setting --append, you will only have the latest track being output.
Note: Templates don't have to be HTML
Note: --template overrides --format.
Development
Some notes, mostly for myself about developing traktor_nowplaying.
Testing
Tests use the standard library unittest module and have no extra dependencies:
python -m unittest discover -v
These run automatically via GitHub Actions on every push to master and on pull requests, across all supported Python versions.
Releasing
Binary releases are created using pysinstaller and the following command:
pyinstaller traktor_nowplaying/cli.py -n traktor_nowplaying --onefile --icon=assets/icon.ico
These are automatically handled by GitHub actions, which are triggered when a new tag is pushed.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file traktor_nowplaying-1.0.0.tar.gz.
File metadata
- Download URL: traktor_nowplaying-1.0.0.tar.gz
- Upload date:
- Size: 227.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35e84ef3d040ffebe7b9d311978e4a44e9962496355d1cbb3be91048a6a14bef
|
|
| MD5 |
83e6454a3d1dbbc43424f76fe2333614
|
|
| BLAKE2b-256 |
40269d30920e86f2bc091171e8c716fe9316fff58ac68cbda983a34ed6f016ba
|
Provenance
The following attestation bundles were made for traktor_nowplaying-1.0.0.tar.gz:
Publisher:
release.yml on radusuciu/traktor_nowplaying
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
traktor_nowplaying-1.0.0.tar.gz -
Subject digest:
35e84ef3d040ffebe7b9d311978e4a44e9962496355d1cbb3be91048a6a14bef - Sigstore transparency entry: 2747212882
- Sigstore integration time:
-
Permalink:
radusuciu/traktor_nowplaying@2500e97ae189489d6d6ce51df2c6182b7ac092dc -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/radusuciu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2500e97ae189489d6d6ce51df2c6182b7ac092dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file traktor_nowplaying-1.0.0-py3-none-any.whl.
File metadata
- Download URL: traktor_nowplaying-1.0.0-py3-none-any.whl
- Upload date:
- Size: 63.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3764c808b689782eec66fff1cc6750e7b9edcf6866852047b4214f9e5d212eba
|
|
| MD5 |
b0e66de2a3589d1aced3e0d0bb44c821
|
|
| BLAKE2b-256 |
789e4de66371cb22d0d051ab79fd5422aa84011accdea2dcd40b0dcb8c8d794e
|
Provenance
The following attestation bundles were made for traktor_nowplaying-1.0.0-py3-none-any.whl:
Publisher:
release.yml on radusuciu/traktor_nowplaying
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
traktor_nowplaying-1.0.0-py3-none-any.whl -
Subject digest:
3764c808b689782eec66fff1cc6750e7b9edcf6866852047b4214f9e5d212eba - Sigstore transparency entry: 2747212984
- Sigstore integration time:
-
Permalink:
radusuciu/traktor_nowplaying@2500e97ae189489d6d6ce51df2c6182b7ac092dc -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/radusuciu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2500e97ae189489d6d6ce51df2c6182b7ac092dc -
Trigger Event:
push
-
Statement type: