Skip to main content

PySerato API.

Project description

pyserato

Programmatically create and read/write Serato crates.

Example use using the DEFAULT_SERATO_FOLDER (~/Music/Serato). This can be overwritten to a non default location by passing the desired root in to the builder.save() API.

Writing Crates

The following shows two different methods for creating and writing the following Crate structure:

    #    -root
    #        -lvl1_1
    #             - lvl2_1
    #             - lvl2_2

Option 1 (Depth First):

from pyserato.model.crate import Crate
from pyserato.builder import Builder

builder = Builder()
lvl2_1 = Crate('lvl2_1')
lvl2_1.add_track("/Users/lukepurnell/nav_music/Russian Circles/Gnosis/01 Tupilak.wav")
lvl1_1 = Crate('lvl1_1', children=[lvl2_1])
lvl1_1.add_track("/Users/lukepurnell/nav_music/Laker/Noise From The Ruliad/00 Entropy Increasing.mp3")
root_crate = Crate('root', children=[lvl1_1])
builder.save(root_crate)

lvl2_2 = Crate('lvl2_2')
lvl2_2.add_track("/Users/lukepurnell/nav_music/Laker/Noise From The Ruliad/00 Cloud Formation.mp3")
lvl1_1 = Crate('lvl1_1', children=[lvl2_2])
lvl1_1.add_track("/Users/lukepurnell/nav_music/Laker/Noise From The Ruliad/00 Entropy Increasing.mp3")
root_crate = Crate('root', children=[lvl1_1])
builder.save(root_crate)

Option 2 (Breadth First):

from pyserato.model.crate import Crate
from pyserato.builder import Builder

builder = Builder()
lvl2_1 = Crate('lvl2_1')
lvl2_1.add_track("/Users/lukepurnell/nav_music/Russian Circles/Gnosis/01 Tupilak.wav")
lvl2_2 = Crate('lvl2_2')
lvl2_2.add_track("/Users/lukepurnell/nav_music/Laker/Noise From The Ruliad/00 Cloud Formation.mp3")
lvl1_1 = Crate('lvl1_1', children=[lvl2_1, lvl2_2])
lvl1_1.add_track("/Users/lukepurnell/nav_music/Laker/Noise From The Ruliad/00 Entropy Increasing.mp3")
root_crate = Crate('root', children=[lvl1_1])
builder.save(root_crate)

Songs added to crates must be unique. If not a DuplicateTrackError will be raised. For example:

from pyserato.model.crate import Crate

crate = Crate('foo')
crate.add_track('foo/bar/track.mp3')
crate.add_track('foo/bar/track.mp3')  # raises DuplicateTrackError

Reading Crates

Reading Crates from file in to the Crate datastructure provided by this library.

from pyserato.builder import Builder
builder = Builder()
subcrates_folder = DEFAULT_SERATO_FOLDER / "SubCrates"
crates = builder.parse_crates_from_root_path(subcrates_folder)

Writing Cues & Loops

from pyserato.encoders.v2.v2_mp3_encoder import V2Mp3Encoder
from pyserato.builder import Builder
from pyserato.model.track import Track
from pyserato.model.crate import Crate
from pyserato.model.hot_cue import HotCue
from pyserato.model.hot_cue_type import HotCueType

mp3_encoder = V2Mp3Encoder()
builder = Builder(encoder=mp3_encoder)
crate = Crate('foo')
track = Track.from_path('path/to/song.mp3')
crate.add_track(track)
track.add_hot_cue(HotCue(name='cue1', type=HotCueType.CUE, start=50, index=1))
track.add_hot_cue(HotCue(name='loop1', type=HotCueType.LOOP, start=50, end=52, index=1))
builder.save(crate)

Serato Database Format

See https://github.com/Holzhaus/serato-tags/ Serato stores its crate information in a directory called Serato/Subcrates in the root of the drive where the music is located (this is true when the music is on a removable drive, unclear what happens when it's on the primary drive of the computer). Each file in this directory corresponds to one crate and will be named CrateName.crate. The crate hierachy tree is encoded in the CrateName.

The format of these .crate files is a concatenated sequence of records. Each record starts with a 4-byte ASCII tag, followed by a 4-byte big-endian length (always at least one), followed by the bytes of the record. The way the bytes are interpreted depends on the tag and follows this table:

Tag pattern Data format o* Nested sequence of records t* UTF-16 big-endian text p* UTF-16 big-endian text, value is a path (relative to the root of the drive) u* Unsigned 32-bit big-endian value s* Signed 32-big big-endian value b* Byte value vrsn UTF-16 big-endian text, value is crate format version Here are the meanings of specific fields:

Tag name Meaning otrk Track ptrk Path to track file (nested inside otrk) Here's an example of the structure of the .crate file:

[ ('vrsn', '1.0/Serato ScratchLive Crate'), ('otrk', [ ('ptrk', 'Music/Daft Punk - 2001 - Discovery/06 Night Vision.mp3')]), ('otrk', [ ('ptrk', 'Music/Daft Punk - 2013 - Random Access Memories/05 Instant Crush.mp3')]), ] Note that the name of the crate is not encoded in the crate itself; it's only present in the filename. Also, some not-very-useful fields are omitted in this example; for example there appear to be fields that give the order that the title/artist/key/BPM columns should appear in the browser.

The encoding of the path of the file seems to change. Sometimes it is utf-8, other times it is latin-1. It is still not clear to me why this switch is made. The presence of a 'orvc' tag after a track path seems to indicate that latin-1 encoding is used. Else the default is utf-8.

TODO

  1. Parse additional Serato info.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyserato-0.1.0.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyserato-0.1.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file pyserato-0.1.0.tar.gz.

File metadata

  • Download URL: pyserato-0.1.0.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyserato-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ba70465a4728c1acd9e0ebc857e1bdb95375f7b31fd53028ba23a2ea82216025
MD5 eca718af599ada6649bb451b511c1491
BLAKE2b-256 adb75cc24bc439cfd6e580017541a64cc9dcd504974c5066d7a65769ea06adfe

See more details on using hashes here.

File details

Details for the file pyserato-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyserato-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyserato-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51dbb3d7e97ac5d13adbae757464dbc6179732d16971e2e885c35315d1b52885
MD5 723866f95781a9e4c7186101a67d66b5
BLAKE2b-256 118be3734d0f4984df5811965678f0e5f564a4262ae9ac1f7e1a98e961e5b49b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page