Skip to content

Commit

Permalink
Clean up meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 27, 2024
1 parent ec45ff7 commit c29c35d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 775 deletions.
74 changes: 3 additions & 71 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ CLI Usage
[-l <log-file> <format-string>] [-y]
[-S DESTINATION_FIELD FORMAT_STRING]
[--metatag <field> <value>] [--vbox <field> <value>]
[--combined <field> <value>] [-x LYRICS_EXTRACT]
[-r LYRICS_REMAP] [-F] [--rename] [-f RENAME_FORMAT]
[-A] [-a] [-n] [-K FIELDS] [-t RENAME_TARGET] [-L]
[-x LYRICS_EXTRACT] [-r LYRICS_REMAP] [-F] [--rename]
[-f RENAME_FORMAT] [-A] [-a] [-n] [-K FIELDS]
[-t RENAME_TARGET] [-L]
[-g <glob-pattern> | --mscz | --mscx]
[-s <style-name> <value>] [--clean] [-Y <file>] [--s3]
[--s4] [--list-fonts] [--text-font <font-face>]
Expand Down Expand Up @@ -419,34 +419,6 @@ CLI Usage
- composer (1. vbox_composer 2. metatag_composer)
- lyricist (1. vbox_lyricist 2. metatag_lyricist)

You have access to all this metadata fields through following fields:

- combined_composer
- combined_lyricist
- combined_subtitle
- combined_title
- metatag_arranger
- metatag_audio_com_url
- metatag_composer
- metatag_copyright
- metatag_creation_date
- metatag_lyricist
- metatag_movement_number
- metatag_movement_title
- metatag_msc_version
- metatag_platform
- metatag_poet
- metatag_source
- metatag_source_revision_id
- metatag_subtitle
- metatag_translator
- metatag_work_number
- metatag_work_title
- vbox_composer
- vbox_lyricist
- vbox_subtitle
- vbox_title

-c META_CLEAN, --clean-meta META_CLEAN
Clean the meta data fields. Possible values: „all“ or a
comma separated list of fields, for example:
Expand Down Expand Up @@ -484,10 +456,6 @@ CLI Usage
--vbox <field> <value>, --vbox-meta <field> <value>
Define the metadata in VBox elements. Available fields:
composer, lyricist, subtitle, title.
--combined <field> <value>, --combined-meta <field> <value>
Define the metadata combined in one step for MetaTag and
VBox elements. Available fields: composer, lyricist,
subtitle, title.

lyrics:
-x LYRICS_EXTRACT, --extract LYRICS_EXTRACT, --extract-lyrics LYRICS_EXTRACT
Expand All @@ -508,42 +476,6 @@ CLI Usage
rename:
Rename the “*.msc[zx]” files.Fields and functions you can use in the format string (-f, --format):
Fields
======

- combined_composer
- combined_lyricist
- combined_subtitle
- combined_title
- metatag_arranger
- metatag_audio_com_url
- metatag_composer
- metatag_copyright
- metatag_creation_date
- metatag_lyricist
- metatag_movement_number
- metatag_movement_title
- metatag_msc_version
- metatag_platform
- metatag_poet
- metatag_source
- metatag_source_revision_id
- metatag_subtitle
- metatag_translator
- metatag_work_number
- metatag_work_title
- readonly_abspath
- readonly_basename
- readonly_dirname
- readonly_extension
- readonly_filename
- readonly_relpath
- readonly_relpath_backup
- vbox_composer
- vbox_lyricist
- vbox_subtitle
- vbox_title

Functions
=========

Expand Down
74 changes: 3 additions & 71 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Comande line interface
[-l <log-file> <format-string>] [-y]
[-S DESTINATION_FIELD FORMAT_STRING]
[--metatag <field> <value>] [--vbox <field> <value>]
[--combined <field> <value>] [-x LYRICS_EXTRACT]
[-r LYRICS_REMAP] [-F] [--rename] [-f RENAME_FORMAT]
[-A] [-a] [-n] [-K FIELDS] [-t RENAME_TARGET] [-L]
[-x LYRICS_EXTRACT] [-r LYRICS_REMAP] [-F] [--rename]
[-f RENAME_FORMAT] [-A] [-a] [-n] [-K FIELDS]
[-t RENAME_TARGET] [-L]
[-g <glob-pattern> | --mscz | --mscx]
[-s <style-name> <value>] [--clean] [-Y <file>] [--s3]
[--s4] [--list-fonts] [--text-font <font-face>]
Expand Down Expand Up @@ -117,34 +117,6 @@ Comande line interface
- composer (1. vbox_composer 2. metatag_composer)
- lyricist (1. vbox_lyricist 2. metatag_lyricist)

You have access to all this metadata fields through following fields:

- combined_composer
- combined_lyricist
- combined_subtitle
- combined_title
- metatag_arranger
- metatag_audio_com_url
- metatag_composer
- metatag_copyright
- metatag_creation_date
- metatag_lyricist
- metatag_movement_number
- metatag_movement_title
- metatag_msc_version
- metatag_platform
- metatag_poet
- metatag_source
- metatag_source_revision_id
- metatag_subtitle
- metatag_translator
- metatag_work_number
- metatag_work_title
- vbox_composer
- vbox_lyricist
- vbox_subtitle
- vbox_title

-c META_CLEAN, --clean-meta META_CLEAN
Clean the meta data fields. Possible values: „all“ or a
comma separated list of fields, for example:
Expand Down Expand Up @@ -182,10 +154,6 @@ Comande line interface
--vbox <field> <value>, --vbox-meta <field> <value>
Define the metadata in VBox elements. Available fields:
composer, lyricist, subtitle, title.
--combined <field> <value>, --combined-meta <field> <value>
Define the metadata combined in one step for MetaTag and
VBox elements. Available fields: composer, lyricist,
subtitle, title.

lyrics:
-x LYRICS_EXTRACT, --extract LYRICS_EXTRACT, --extract-lyrics LYRICS_EXTRACT
Expand All @@ -206,42 +174,6 @@ Comande line interface
rename:
Rename the “*.msc[zx]” files.Fields and functions you can use in the format string (-f, --format):
Fields
======

- combined_composer
- combined_lyricist
- combined_subtitle
- combined_title
- metatag_arranger
- metatag_audio_com_url
- metatag_composer
- metatag_copyright
- metatag_creation_date
- metatag_lyricist
- metatag_movement_number
- metatag_movement_title
- metatag_msc_version
- metatag_platform
- metatag_poet
- metatag_source
- metatag_source_revision_id
- metatag_subtitle
- metatag_translator
- metatag_work_number
- metatag_work_title
- readonly_abspath
- readonly_basename
- readonly_dirname
- readonly_extension
- readonly_filename
- readonly_relpath
- readonly_relpath_backup
- vbox_composer
- vbox_lyricist
- vbox_subtitle
- vbox_title

Functions
=========

Expand Down
48 changes: 6 additions & 42 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import mscxyz.export
from mscxyz import utils
from mscxyz.meta import Combined, Interface, InterfaceReadWrite, Metatag, Vbox
from mscxyz.meta import Metatag, Vbox
from mscxyz.rename import rename
from mscxyz.score import Score
from mscxyz.settings import parse_args
Expand All @@ -28,13 +28,6 @@ def __inch(value: str) -> float:
return Dimension(value).to("in")


def __itemized_fields(fields: Sequence[str], prefix: str = "", suffix: str = "") -> str:
out: list[str] = []
for field in fields:
out.append(prefix + "- " + field + suffix)
return "\n".join(out)


def __embed_fields(
fields: Sequence[str], prefix: str = " Available fields: ", suffix: str = "."
) -> str:
Expand Down Expand Up @@ -240,11 +233,8 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]:
- subtitle (1. vbox_subtitle 2. metatag_movement_title)
- composer (1. vbox_composer 2. metatag_composer)
- lyricist (1. vbox_lyricist 2. metatag_lyricist)
You have access to all this metadata fields through following fields:"""
)
+ "\n\n"
+ __itemized_fields(InterfaceReadWrite.get_all_fields(), prefix=" "),
"""
),
)

group_meta.add_argument(
Expand Down Expand Up @@ -341,17 +331,6 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]:
help="Define the metadata in VBox elements." + __embed_fields(Vbox.fields),
)

group_meta.add_argument(
"--combined",
"--combined-meta",
nargs=2,
action="append",
metavar=("<field>", "<value>"),
dest="meta_combined",
help="Define the metadata combined in one step for MetaTag and VBox elements."
+ __embed_fields(Combined.fields),
)

###############################################################################
# lyrics
###############################################################################
Expand Down Expand Up @@ -401,10 +380,7 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]:
"Rename the “*.msc[zx]” files."
"Fields and functions you can use in the format "
"string (-f, --format):\n\n"
"Fields\n======\n\n{}\n\n"
"Functions\n=========\n\n{}".format(
__itemized_fields(Interface.get_all_fields(), prefix=" "), tmep.get_doc()
),
"Functions\n=========\n\n{}".format(tmep.get_doc()),
)

group_rename.add_argument(
Expand Down Expand Up @@ -766,7 +742,6 @@ def list_styles(version: int) -> None:
if (
args.meta_metatag
or args.meta_vbox
or args.meta_combined
or args.meta_set
or args.meta_clean
or args.meta_dist
Expand Down Expand Up @@ -800,26 +775,15 @@ def list_styles(version: int) -> None:
)
setattr(score.meta.vbox, field, value)

if args.meta_combined:
for a in args.meta_combined:
field = a[0]
value = a[1]
if field not in Combined.fields:
raise ValueError(
f"Unknown field {field}. "
f"Possible fields: {', '.join(Combined.fields)}"
)
setattr(score.meta.combined, field, value)

if args.meta_set:
for a in args.meta_set:
score.meta.set_field(destination_field=a[0], format_string=a[1])
score.fields.set(a[0], a[1])

if args.meta_clean:
score.fields.clean(args.meta_clean)

if args.meta_json:
score.meta.export_json()
score.fields.export_json()

if args.meta_dist:
for a in args.meta_dist:
Expand Down
4 changes: 4 additions & 0 deletions mscxyz/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pathlib import Path
from typing import Any, Iterator, Mapping, Sequence, Union

import tmep

from mscxyz.meta import FormatStringNoFieldError, UnmatchedFormatStringError
from mscxyz.settings import DefaultArguments
from mscxyz.utils import Color, colorize
Expand Down Expand Up @@ -310,6 +312,8 @@ def set(self, name: str, value: Any) -> None:
obj = getattr(obj, attr)
if obj is None:
raise Exception(f"Cannot set attribute {field.attr_path}")
if value is not None and isinstance(value, str) and "$" in value:
value = tmep.parse(value, self.export_to_dict())
setattr(obj, last, value)

def diff(self, args: DefaultArguments) -> None:
Expand Down
Loading

0 comments on commit c29c35d

Please sign in to comment.