Skip to main content

No project description provided

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.1.tar.gz (4.4 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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: karaoke-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 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.1.tar.gz
Algorithm Hash digest
SHA256 2d4f3902efef97993de60ed26cbc954225bf84f6a548cfd6ff77d7802e48d902
MD5 47f6e689c5bf5f4f8872d2656c26d7a3
BLAKE2b-256 07332761949fadbb86f5afe4292bae6bf2985b5a8fe0aaeced8159c93ffc3107

See more details on using hashes here.

File details

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

File metadata

  • Download URL: karaoke-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad01254de939e1e6411e7e8a76f9f71195b59c7a91ab096d96ee67e71bf17eb2
MD5 f71b6371c45640c4ac125dea2893f4fe
BLAKE2b-256 abd00d1c8e391c0b241fc4a0b77300a01ce3e768560d85497c716e054d7cefc9

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