Skip to content

Commit

Permalink
feat: add beet.contrib.text_encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Sep 14, 2022
1 parent fd8b0fc commit 37a23ce
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions beet/contrib/text_encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Plugin that configures text encoding before writing out files."""


__all__ = [
"TextEncodingOptions",
"text_encoding",
]


from typing import Any, Optional

from pydantic import BaseModel

from beet import Context, ListOption, TextFileBase, configurable


class TextEncodingOptions(BaseModel):
extensions: ListOption[str] = ListOption()
encoding: str = "utf-8"
errors: Optional[str] = None


def beet_default(ctx: Context):
ctx.require(text_encoding)


@configurable(validator=TextEncodingOptions)
def text_encoding(ctx: Context, opts: TextEncodingOptions):
"""Plugin that configures text encoding before writing out files."""
for pack in ctx.packs:
for _, text_file in pack.list_files(
*opts.extensions.entries(),
extend=TextFileBase[Any],
):
text_file.encoding = opts.encoding
text_file.errors = opts.errors

0 comments on commit 37a23ce

Please sign in to comment.