+11
-12
@@ -125,18 +125,17 @@ def generate_titles(root: pathlib.Path, font_root: pathlib.Path = DEFAULT_FONT_R
|
||||
destination = root / 'pico' / 'titles'
|
||||
destination.mkdir(parents=True, exist_ok=True)
|
||||
titles = {}
|
||||
for category in ('songs', 'practice'):
|
||||
for source in sorted((root / category).rglob('*.json')):
|
||||
document = json.loads(source.read_text(encoding='utf-8'))
|
||||
title = document['music']['metadata']['title']
|
||||
if title not in titles:
|
||||
if len(titles) >= MAX_TITLES:
|
||||
raise ValueError('Too many Pico titles')
|
||||
image = renderer.title(title)
|
||||
titles[title] = hashlib.sha256(image).hexdigest()
|
||||
(destination / f'{titles[title]}.mask').write_bytes(image)
|
||||
document['presentation']['title_image'] = titles[title]
|
||||
source.write_text(json.dumps(document, ensure_ascii=False, separators=(',', ':')) + '\n', encoding='utf-8')
|
||||
for source in sorted((root / 'songs').rglob('*.json')):
|
||||
document = json.loads(source.read_text(encoding='utf-8'))
|
||||
title = document['music']['metadata']['title']
|
||||
if title not in titles:
|
||||
if len(titles) >= MAX_TITLES:
|
||||
raise ValueError('Too many Pico titles')
|
||||
image = renderer.title(title)
|
||||
titles[title] = hashlib.sha256(image).hexdigest()
|
||||
(destination / f'{titles[title]}.mask').write_bytes(image)
|
||||
document['presentation']['title_image'] = titles[title]
|
||||
source.write_text(json.dumps(document, ensure_ascii=False, separators=(',', ':')) + '\n', encoding='utf-8')
|
||||
|
||||
def validate_title(root: pathlib.Path, identifier: str) -> None:
|
||||
if not isinstance(identifier, str) or len(identifier) != 64 or any(character not in '0123456789abcdef' for character in identifier):
|
||||
|
||||
Reference in New Issue
Block a user