Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lrcput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import argparse
from mutagen.flac import FLAC
from mutagen.mp4 import MP4
from mutagen.oggopus import OggOpus
from mutagen.oggvorbis import OggVorbis
import eyed3
from tqdm import tqdm

def has_embedded_lyrics(audio):
if isinstance(audio, FLAC):
if isinstance(audio, (FLAC, OggOpus, OggVorbis)):
return 'LYRICS' in audio
elif isinstance(audio, MP4):
return '\xa9lyr' in audio.tags
Expand All @@ -23,7 +25,9 @@ def embed_lrc(directory, skip_existing, reduce_lrc, recursive):
audio_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.flac') or file.endswith('.mp3') or file.endswith('.m4a'):
if (file.endswith('.flac') or file.endswith('.mp3') or
file.endswith('.m4a') or file.endswith('.ogg') or
file.endswith('.opus')):
audio_files.append(os.path.join(root, file))

with tqdm(total=len(audio_files), desc='Embedding LRC files', unit='file') as pbar:
Expand All @@ -37,6 +41,13 @@ def embed_lrc(directory, skip_existing, reduce_lrc, recursive):
audio = None
if file.endswith('.flac'):
audio = FLAC(audio_path)
elif file.endswith('.opus'):
audio = OggOpus(audio_path)
elif file.endswith('.ogg'):
try:
audio = OggVorbis(audio_path)
except Exception:
audio = OggOpus(audio_path)
elif file.endswith('.mp3'):
audio = eyed3.load(audio_path)
elif file.endswith('.m4a'):
Expand All @@ -51,6 +62,17 @@ def embed_lrc(directory, skip_existing, reduce_lrc, recursive):
audio = FLAC(audio_path)
audio['LYRICS'] = open(lrc_path, 'r', encoding='utf-8').read()
audio.save()
elif file.endswith('.opus'):
audio = OggOpus(audio_path)
audio['LYRICS'] = open(lrc_path, 'r', encoding='utf-8').read()
audio.save()
elif file.endswith('.ogg'):
try:
audio = OggVorbis(audio_path)
except Exception:
audio = OggOpus(audio_path)
audio['LYRICS'] = open(lrc_path, 'r', encoding='utf-8').read()
audio.save()
elif file.endswith('.mp3'):
audio = eyed3.load(audio_path)
tag = audio.tag
Expand Down