Skip to main content

LPTrack

LavaPlayer encoded track encoder and decoder.

Introduction

LPTrack is a small library which allows you to interpret the encoded track data used by LavaPlayer.

This is useful when you're dealing with standalone LavaLink instances like Lavalink and Andesite, because it allows you to interpret the track data directly.

Installation

From PyPI

pip install lptrack

Usage

import lptrack

track = lptrack.Track(
    version = 2,
    source = lptrack.Youtube(),

    info = lptrack.TrackInfo(
        title="A song",
        author="Some random artist",
        duration=120,                   # duration is in seconds!
        identifier="dQw4w9WgXcQ",
        is_stream=False,
    ),
)

encoded = lptrack.encode(track)
print(encoded)
# b'QAAARQIABkEgc29uZwASU29tZSByYW5kb20gYXJ0aXN0AAAAAAAB1MAAC2RRdzR3OVdnWGNRAAAAB3lvdXR1YmUAAAAAAAAAAA=='

decoded = lptrack.decode(encoded)

assert decoded == encoded

Obligatory rant about CESU-8

Without going into too much detail, LavaPlayer (or Java, to be more specific) uses a special encoding for strings called MUTF-8 which in turn is based on CESU-8. Characters from the BMP (which contains pretty much all characters from modern languages) are encoded like normal UTF-8. But special characters like emojis will be encoded in an incompatible manner.

While lptrack doesn't force you to use it, it's strongly recommended to have ftfy installed. It allows lptrack to properly decode MUTF-8 encoded strings. If ftfy isn't installed lptrack will treat the strings as UTF-8, but allows surrogates. Note that it doesn't parse the surrogates properly (i.e. it will look like a mess), but it will include them in the re-encoded track data.

ftfy is listed as a dependency of lptrack, so unless you really don't want it, you'll enjoy its benefits.

lptrack itself doesn't produce CESU-8 strings, so it's possible that the re-encoded track data differs from the original track data.

It's possible to manually set the desired codec using the keyword-argument string_codec which accepts a lptrack.strcodec.Codec instance. The following values are pre-defined:

  • lptrack.strcodec.UTF8: Allows surrogates but doesn't parse them properly. Should be used if re-encoded track data needs to be equal to the input.

  • lptrack.strcodec.MUTF8: Codec handling CESU-8. Requires ftfy to work.

  • lptrack.strcodec.DEFAULT: MUTF8 if ftfy is installed, UTF8 otherwise. This codec is used by default.

  • lptrack.strcodec.UTF8STRICT: Same as UTF8 but rejects surrogates outright.

Metadata

Release files for lptrack 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lptrack 1.0.0
File Size Uploaded
lptrack-1.0.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lptrack 1.0.0
File Interpreter ABI Platform
lptrack-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / lptrack-1.0.0.tar.gz

Download URL lptrack-1.0.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
522faee875c0d7be2ba2fa3716202b7ced8f74bb58d11c77bc4c4d46ef889ac6
BLAKE2b-256 checksum
How to use checksums
a095197db8bf4678ca808295c7c9ece6cddb07e354f42a1e1a30ed7043cb34f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / lptrack-1.0.0-py3-none-any.whl

Download URL lptrack-1.0.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f67a12fc8707b04e7a6069ee74a7ea8fe30eec77b8ae977a37ddd179b4f1b894
BLAKE2b-256 checksum
How to use checksums
b8574b707609805bef63d26fdc49920094ce7e77e1126202e7ae5e5708152aca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page