[![PyPI pyversions](https://img.shields.io/pypi/pyversions/traktor-nowplaying.svg)](https://pypi.python.org/pypi/traktor-nowplaying/)
[![PyPI version fury.io](https://img.shields.io/pypi/v/traktor-nowplaying.svg)](https://pypi.python.org/pypi/traktor-nowplaying/)
[![GitHub release](https://img.shields.io/github/release/radusuciu/traktor_nowplaying.svg)](https://github.com/radusuciu/traktor_nowplaying/releases/)
# Traktor Now Playing
This project for Python 3 (tested on 3.6+) uses Traktor's broadcast functionality to extract metadata about the currently playing song. This is really a very thin wrapper around some [tinytag](https://github.com/devsnd/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](https://github.com/Sonnenstrahl/traktor-now-playing) 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](https://www.disconova.com/utu/traktor-metadata/) which is not open-source and likely will never be, and [traktor-now-playing](https://github.com/Sonnenstrahl/traktor-now-playing), which uses the MIDI approach mentioned above.
## Installation
The preferred installation method is via [pip](https://pip.pypa.io/en/stable/):
```bash
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](https://github.com/radusuciu/traktor_nowplaying/releases).
## 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](https://radusuciu.com/posts/broadcasting-from-traktor-an-alternative-to-the-built-in-broadcasting-function/)), 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.
## 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:
```bash
traktor_nowplaying
```
Listen on port `8000`, output to `nowplaying.txt` in the current directory and do not output to `stdout`:
```bash
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.12/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](https://github.com/radusuciu/traktor_nowplaying/releases), 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.
```python
from traktor_nowplaying import Listener
listener = Listener(port=8000, quiet=True, outfile='nowplaying.txt')
listener.start()
```
For a more elaborate example with a custom callback, see this project: https://github.com/radusuciu/traktor_ice, and [this bit](https://github.com/radusuciu/traktor_ice/blob/b0873cb5e36dbcb87a260900f44a2f1768d5d5c9/traktor_ice/core.py#L60-L74) 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](https://bottlepy.org/docs/0.12/stpl.html) included with [Bottle 0.12](https://bottlepy.org/docs/0.12/), 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:
```html
<!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.
### Releasing
Binary releases are created using [pysinstaller](https://www.pyinstaller.org/) and the following command:
```bash
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/radusuciu/traktor_nowplaying",
"name": "traktor-nowplaying",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6.2",
"maintainer_email": "",
"keywords": "",
"author": "Radu Suciu",
"author_email": "radusuciu@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ae/68/8ec3063a7c5b4fb994098ca944aaa37475416dd1ec63050d6d1cb295c47b/traktor_nowplaying-0.3.5.tar.gz",
"platform": "any",
"description": "[![PyPI pyversions](https://img.shields.io/pypi/pyversions/traktor-nowplaying.svg)](https://pypi.python.org/pypi/traktor-nowplaying/)\n[![PyPI version fury.io](https://img.shields.io/pypi/v/traktor-nowplaying.svg)](https://pypi.python.org/pypi/traktor-nowplaying/)\n[![GitHub release](https://img.shields.io/github/release/radusuciu/traktor_nowplaying.svg)](https://github.com/radusuciu/traktor_nowplaying/releases/)\n\n# Traktor Now Playing\n\nThis project for Python 3 (tested on 3.6+) uses Traktor's broadcast functionality to extract metadata about the currently playing song. This is really a very thin wrapper around some [tinytag](https://github.com/devsnd/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.\n\nThe reason this exists is because it's rather difficult to get this information through other means. You can [use MIDI](https://github.com/Sonnenstrahl/traktor-now-playing) for this as well, but that requires that you add a fake controller.\n\nLastly, there are several other projects that do something similar such as [Traktor Metadata Listener](https://www.disconova.com/utu/traktor-metadata/) which is not open-source and likely will never be, and [traktor-now-playing](https://github.com/Sonnenstrahl/traktor-now-playing), which uses the MIDI approach mentioned above.\n\n## Installation\n\nThe preferred installation method is via [pip](https://pip.pypa.io/en/stable/):\n\n```bash\npip install traktor_nowplaying\n```\n\nThere 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](https://github.com/radusuciu/traktor_nowplaying/releases).\n\n## General use\n\nIn 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](https://radusuciu.com/posts/broadcasting-from-traktor-an-alternative-to-the-built-in-broadcasting-function/)), you cannot broadcast from Traktor itself.\n\nYou 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.\n\nNote that there is a delay between when you change a song in Traktor and when the change is picked up.\n\n## Use from command line\n\nIf 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:\n```bash\ntraktor_nowplaying\n```\n\nListen on port `8000`, output to `nowplaying.txt` in the current directory and do not output to `stdout`:\n```bash\ntraktor_nowplaying --port 8000 --outfile='nowplaying.txt' --quiet\n```\n\nThe help text:\n```\n$ traktor_nowplaying --help\nusage: traktor_nowplaying [-h] [-p PORT] [-q] [-f FORMAT] [-o OUTFILE]\n [-t TEMPLATE] [-a] [-m MAX_TRACKS] [-i] [-v]\n\nUse Traktor's broadcast functionality to extract metadata about the currently\nplaying song\n\noptional arguments:\n -h, --help show this help message and exit\n -p PORT, --port PORT Port to listen on for broadcasts from Traktor\n -q, --quiet Suppress console output of currently playing song\n -f FORMAT, --format FORMAT\n Custom format to use when outputting tracks\n -o OUTFILE, --outfile OUTFILE\n Provide a file path to which the currently playing song\n should be written\n -t TEMPLATE, --template TEMPLATE\n Template file to use for output. Templating is\n implemented using Bottle SimpleTemplate\n (https://bottlepy.org/docs/0.12/stpl.html). See README\n for more details on use. Note: the --format options is\n ignored when using a custom template file. Take care\n when using templates provided by others on the internet\n as they can contain malicious code.\n -a, --append If writing to file, appends newest track to end of file\n instead of overwriting the file\n -m MAX_TRACKS, --max-tracks MAX_TRACKS\n If appending to a file, the maximum number of tracks to\n keep in file (by default there is no limit)\n -i, --interactive Interactive mode allows for settings to be specified at\n runtime. These override command line options.\n -v, --version show program's version number and exit\n\nNote that you must configure Traktor to broadcast to localhost and the port\nspecified with the -p, or --port option (defaults to 8000). For the format\nsetting you can use anything, but I recommend choosing the lowest bitrate for\nthe sample rate of your system, so most commonly the best choice is 44100 Hz,\n64 Kbps.\n```\n\nTo stop the process `Ctrl + C` should suffice.\n\n## Using binary releases\n\nIf you've downloded a platform specific release from [the Releases page](https://github.com/radusuciu/traktor_nowplaying/releases), the use instructions are the same as described above for the command-line.\n\n## Use as a library\n\n`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.\n\n```python\nfrom traktor_nowplaying import Listener\n\nlistener = Listener(port=8000, quiet=True, outfile='nowplaying.txt')\nlistener.start()\n```\n\nFor a more elaborate example with a custom callback, see this project: https://github.com/radusuciu/traktor_ice, and [this bit](https://github.com/radusuciu/traktor_ice/blob/b0873cb5e36dbcb87a260900f44a2f1768d5d5c9/traktor_ice/core.py#L60-L74) in particular.\n\n## Customizing output\n\nThe output of `traktor_nowplaying` can be customized using the `--format` and `--template` options. Both of these functions make use of the [`SimpleTemplate` Engine](https://bottlepy.org/docs/0.12/stpl.html) included with [Bottle 0.12](https://bottlepy.org/docs/0.12/), so anything you can use with Bottle's templates, you can use here.\n\n**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.\n\n### `--format`\n\nThis 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}}`.\n\n### `--template`\n\nWhile `--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:\n\n```html\n<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"UTF-8\">\n </head>\n <body>\n % for track in tracks:\n <p><strong>{{track.get('artist', '')}}</strong> - {{track.get('title', '')}}</p>\n % end\n </body>\n</html>\n```\n\nIf 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.\n\n**Note**: Templates don't have to be HTML\n\n**Note**: `--template` overrides `--format`.\n\n## Development\n\nSome notes, mostly for myself about developing traktor_nowplaying.\n\n### Releasing\n\nBinary releases are created using [pysinstaller](https://www.pyinstaller.org/) and the following command:\n\n```bash\npyinstaller traktor_nowplaying/cli.py -n traktor_nowplaying --onefile --icon=assets/icon.ico\n```\n\nThese are automatically handled by GitHub actions, which are triggered when a new tag is pushed.\n\n\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "traktor_nowplaying uses Traktor's broadcast functionality to extract metadata about the currently playing song.",
"version": "0.3.5",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "eb914b0ff5c7fe4e5307c02b3fdc599ebf2389ef72f0713f6243a3afd2f0c22d",
"md5": "a8f12037ac623f7d154271e1ba5c0fba",
"sha256": "ab24ea07491787e4bfb0754a6674500d4a89542be074f7a61d4185bab31c4e67"
},
"downloads": -1,
"filename": "traktor_nowplaying-0.3.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a8f12037ac623f7d154271e1ba5c0fba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.2",
"size": 56159,
"upload_time": "2023-03-16T15:50:22",
"upload_time_iso_8601": "2023-03-16T15:50:22.611478Z",
"url": "https://files.pythonhosted.org/packages/eb/91/4b0ff5c7fe4e5307c02b3fdc599ebf2389ef72f0713f6243a3afd2f0c22d/traktor_nowplaying-0.3.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ae688ec3063a7c5b4fb994098ca944aaa37475416dd1ec63050d6d1cb295c47b",
"md5": "2316e1a899f43e6fcb2ebd136fba91a5",
"sha256": "3455ea1c6593262c205b9a5bab7dd031a7c412290ee7e7beeb5f62f26964561b"
},
"downloads": -1,
"filename": "traktor_nowplaying-0.3.5.tar.gz",
"has_sig": false,
"md5_digest": "2316e1a899f43e6fcb2ebd136fba91a5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.2",
"size": 56716,
"upload_time": "2023-03-16T15:50:24",
"upload_time_iso_8601": "2023-03-16T15:50:24.309004Z",
"url": "https://files.pythonhosted.org/packages/ae/68/8ec3063a7c5b4fb994098ca944aaa37475416dd1ec63050d6d1cb295c47b/traktor_nowplaying-0.3.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-16 15:50:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "radusuciu",
"github_project": "traktor_nowplaying",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "traktor-nowplaying"
}