Created
June 27, 2025 18:44
-
-
Save Vocaned/e953b5744daef95c1f76669cb4868017 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
#!/bin/python | |
from mutagen.flac import FLAC | |
from pathlib import Path | |
import re | |
for p in Path('..').glob('**/*'): | |
if not p.is_file() or p.suffix != '.flac': | |
continue | |
lrcp = p.with_suffix('.lrc') | |
if not lrcp.exists(): | |
continue | |
with open(lrcp, 'r') as f: | |
lrc = f.read() | |
tags = FLAC(p) | |
artist = tags['artist'][0] | |
track = tags['title'][0] | |
album = tags['album'][0] | |
duration = tags.info.length | |
if not artist or not track or not album or not duration: | |
print('Broken metadata for file', p) | |
continue | |
if '[al:' in lrc or '[ti:' in lrc or '[ar:' in lrc: | |
print(p, 'already tagged') | |
continue | |
# TODO: Should there be support for tracks longer than 60 minutes | |
minutes = duration // 60 | |
seconds = duration % 60 | |
lrc = f'''[ti:{track}] | |
[ar:{artist}] | |
[al:{album}] | |
[length:{int(minutes):0>2}:{int(seconds):0>2}] | |
[tool:voc-mpd-tools] | |
{lrc}''' | |
print('Tagged', lrcp.name) | |
with open(lrcp, 'w') as f: | |
f.write(lrc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment