Skip to main content

Karaoke is a lightweight Python library designed to facilitate interactions with song Lyrics.

Project description

Karaoke.py

Overview

Karaoke is a lightweight Python library designed to facilitate interactions with song LRC (Lyric) files. It allows for easy parsing, management, and retrieval of song lyrics along with their corresponding timestamps.

Installation

To use the Karaoke library, simply clone the repository or download the karaoke.py file and include it in your project.

git clone https://github.com/pascall-de-creator/karaoke.py

Features

  • Parsing LRC Files: Load and parse LRC formatted lyrics, extracting timestamps and lyrics.
  • Timestamp Management: Convert timestamps from LRC format to milliseconds for precise timing.
  • Current Lyric Tracking: Keep track of the current lyric based on a given timestamp.

Usage

Importing the Library

from karaoke import Karaoke

Creating an Instance

karaoke = Karaoke()

Parsing LRC Data

To parse LRC data, use the parse method:

lrc_data = """
[00:01.00]Line 1
[00:05.00]Line 2
[00:10.00]Line 3
"""

karaoke.parse(lrc_data)

Accessing Lyrics

You can access all the lyrics using the lyrics property:

all_lyrics = karaoke.lyrics
print(all_lyrics)  # Output: ['Line 1', 'Line 2', 'Line 3']

Getting Current Lyric

To get the currently active lyric based on the timestamp set, use the current_lyric property:

karaoke.set_current_lyric(6000)  # Set current time to 6 seconds
print(karaoke.current_lyric)  # Output: 'Line 2'

Clean and Validate LRC Data

The check method validates the LRC data:

karaoke.check(lrc_data)  # Raises ValueError if the data is invalid

The clean method can be used to clean up LRC data by removing blank lines:

cleaned_lrc = karaoke.clean(lrc_data, clean_blanklines=True)

Timestamp Conversion

Convert LRC timestamp to milliseconds with:

ms = karaoke.timestamp_to_ms("[00:01.00]")  # Output: 1000

Finding Lyric Index

To find the index of a lyric based on the target time:

index = karaoke.find_lyric_index(6000)  # Output: 1

Class Reference

Karaoke

Properties

  • lyrics: Returns a list of all lyrics.
  • lyric_index: Returns the index of the currently active lyric.
  • current_lyric: Returns the currently active lyric.

Methods

  • check(lrc: str): Validates the provided LRC data.
  • clean(lrc: str, clean_blanklines: bool): Cleans the LRC data by removing timestamps or blank lines.
  • timestamp_to_ms(timestamp: str) -> int: Converts LRC timestamp to milliseconds.
  • parse(lrc: str, clean_blanklines: bool = False): Parses the LRC data into an internal structure.
  • find_lyric_index(target_time: int) -> int: Finds the index of the lyric that corresponds to a given time.
  • set_current_lyric(target_time: int): Sets the current lyric based on a target time.

Example

Here's a complete example demonstrating the library's functionality:

from karaoke import Karaoke

karaoke = Karaoke()

lrc_data = """
[00:01.00]Line 1
[00:05.00]Line 2
[00:10.00]Line 3
"""

karaoke.parse(lrc_data)

karaoke.set_current_lyric(6000)  # Set current time to 6 seconds
print(karaoke.current_lyric)  # Output: 'Line 2'

Conclusion

The Karaoke library is a simple yet powerful tool for managing song lyrics and their timestamps. Its clean API and lightweight structure make it easy to integrate into various projects. Enjoy your karaoke sessions!

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

karaoke-0.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

karaoke-0.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file karaoke-0.0.2.tar.gz.

File metadata

  • Download URL: karaoke-0.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for karaoke-0.0.2.tar.gz
Algorithm Hash digest
SHA256 cf527e83c6425a2b34d950f143fec41da5ebbebd866a8fe540d9dbc88256dfcb
MD5 fc4e5a50fcb52d27ba5ac1b4d48944a3
BLAKE2b-256 84a2b1927eefeecb55bd04682c59fc0fef80234f44f91f0c8b6b3cdda8bf5f42

See more details on using hashes here.

File details

Details for the file karaoke-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: karaoke-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for karaoke-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f35978976b9542a42cad992329375606f185aa1250bdd55233ecfde5617d76a
MD5 a9718123f2cdd8cd3cc3c07590c83812
BLAKE2b-256 b587244fea3322d1b3266225ca31d5c144dbb660a1f815b2b4b354a829bb1d06

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