Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用ruamel.yaml库解析OpenUtau ustx文件 #183

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 4 additions & 9 deletions libresvip/plugins/ustx/ustx_converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pathlib

import yaml
from ruamel.yaml import YAML

from libresvip.extension import base as plugin_base
from libresvip.model.base import Project
Expand All @@ -11,23 +11,18 @@
from .ustx_generator import UstxGenerator
from .ustx_parser import UstxParser

y=YAML(typ='safe')

class OpenUtauConverter(plugin_base.SVSConverterBase):
def load(self, path: pathlib.Path, options: InputOptions) -> Project:
proj_text = to_unicode(path.read_bytes())
ustx_project = USTXProject.model_validate(
yaml.load(proj_text, getattr(yaml, "CSafeLoader", yaml.SafeLoader))
y.load(proj_text)
)
return UstxParser(options).parse_project(ustx_project)

def dump(self, path: pathlib.Path, project: Project, options: OutputOptions) -> None:
ustx_project = UstxGenerator(options).generate_project(project)
proj_dict = ustx_project.model_dump(by_alias=True, exclude_none=True)
proj_text = yaml.dump(
proj_dict,
None,
getattr(yaml, "CSafeDumper", yaml.SafeDumper),
allow_unicode=True,
sort_keys=False,
)
proj_text = y.dump(proj_dict)
path.write_bytes(proj_text.encode("utf-8"))