Added lyrics to scores
This commit is contained in:
@@ -1,7 +1,26 @@
|
||||
import dataclasses
|
||||
import re
|
||||
from collections.abc import Iterable, Iterator
|
||||
from typing import Callable
|
||||
|
||||
from folkugat_web.dal.sql.temes import lyrics as lyrics_dal
|
||||
from folkugat_web.model import temes as model
|
||||
from folkugat_web.utils import FnChain
|
||||
|
||||
|
||||
def _sub(pattern: str, sub: str) -> Callable[[str], str]:
|
||||
def _inner_sub(text: str) -> str:
|
||||
return re.sub(pattern, sub, text)
|
||||
return _inner_sub
|
||||
|
||||
|
||||
def _clean_string(lyrics_str: str) -> str:
|
||||
return (
|
||||
FnChain.transform(lyrics_str) |
|
||||
_sub(r" *", " ") |
|
||||
_sub(r"\s*\n\s*", "\n") |
|
||||
_sub(r"\n*", "\n")
|
||||
).result()
|
||||
|
||||
|
||||
def add_lyrics_to_tema(tema: model.Tema) -> model.Tema:
|
||||
@@ -19,6 +38,7 @@ def get_lyric_by_id(lyric_id: int, tema_id: int | None = None) -> model.Lyrics |
|
||||
|
||||
|
||||
def update_lyric(lyric: model.Lyrics):
|
||||
lyric = dataclasses.replace(lyric, content=_clean_string(lyric.content))
|
||||
lyrics_dal.update_lyric(lyric=lyric)
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from fastapi import HTTPException
|
||||
from folkugat_web.dal.sql.temes import scores as scores_dal
|
||||
from folkugat_web.model import temes as model
|
||||
from folkugat_web.services import lilypond
|
||||
from folkugat_web.services.temes import lyrics as lyrics_service
|
||||
from folkugat_web.services.temes import properties as properties_service
|
||||
from folkugat_web.services.temes import query as temes_q
|
||||
from folkugat_web.utils import FnChain
|
||||
@@ -51,6 +52,7 @@ def build_single_tune_full_source(tema_id: int, source: str) -> str:
|
||||
raise HTTPException(status_code=404, detail="Could not find tema!")
|
||||
tema = (
|
||||
FnChain.transform(tema) |
|
||||
properties_service.add_properties_to_tema
|
||||
properties_service.add_properties_to_tema |
|
||||
lyrics_service.add_lyrics_to_tema
|
||||
).result()
|
||||
return lilypond.source_to_single_score(source=source, tema=tema)
|
||||
|
||||
Reference in New Issue
Block a user