Created
October 2, 2024 14:41
-
-
Save ViktorVoloshko/f62d8bdf0c4fac845ee5337af59f101e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Originally was there: https://github.com/TheRedSpy15/lrcput | |
# Reuploaded by u/creepurr101 to https://pastebin.com/v0Srx5rW | |
import os | |
import mutagen.flac | |
import pylrc | |
def embed_lyrics_in_flac(flac_file, lrc_file): | |
try: | |
# Load FLAC file | |
audio = mutagen.flac.FLAC(flac_file) | |
print(f"Processing FLAC file: {flac_file}") | |
# Read LRC file | |
with open(lrc_file, 'r', encoding='utf-8') as f: | |
lrc_content = f.read() | |
print(f"Read LRC file: {lrc_file}") | |
print(f"LRC content:\n{lrc_content}") | |
# Embed lyrics in FLAC metadata | |
audio["LYRICS"] = lrc_content.strip() # Embed the raw LRC content as-is | |
audio.save() | |
print(f"Successfully embedded lyrics into {flac_file}") | |
except mutagen.MutagenError as e: | |
print(f"Mutagen error for {flac_file}: {e}") | |
except FileNotFoundError as e: | |
print(f"File not found error: {e}") | |
except Exception as e: | |
print(f"Failed to embed lyrics in {flac_file}: {e}") | |
def main(): | |
# Directory containing FLAC and LRC files | |
directory = input("Enter the didrectory to scan for FLAC files: ") | |
# Iterate over all files in the directory | |
for filename in os.listdir(directory): | |
if filename.endswith(".flac"): | |
flac_file = os.path.join(directory, filename) | |
lrc_file = os.path.join(directory, filename.replace(".flac", ".lrc")) | |
if os.path.exists(lrc_file): | |
embed_lyrics_in_flac(flac_file, lrc_file) | |
else: | |
print(f"No LRC file found for {flac_file}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment