Skip to main content

No project description provided

Project description

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.

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

lptrack-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

lptrack-1.0.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file lptrack-1.0.0.tar.gz.

File metadata

  • Download URL: lptrack-1.0.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for lptrack-1.0.0.tar.gz
Algorithm Hash digest
SHA256 522faee875c0d7be2ba2fa3716202b7ced8f74bb58d11c77bc4c4d46ef889ac6
MD5 dbe2396156e6bc512591efa2bdeb70f6
BLAKE2b-256 a095197db8bf4678ca808295c7c9ece6cddb07e354f42a1e1a30ed7043cb34f4

See more details on using hashes here.

File details

Details for the file lptrack-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lptrack-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for lptrack-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f67a12fc8707b04e7a6069ee74a7ea8fe30eec77b8ae977a37ddd179b4f1b894
MD5 ffb2c555ba6b7a3dfece6797b8bd2f28
BLAKE2b-256 b8574b707609805bef63d26fdc49920094ce7e77e1126202e7ae5e5708152aca

See more details on using hashes here.

Supported by

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