diff --git a/beets/library.py b/beets/library.py index 84f6a7bf03..b97a80b13d 100644 --- a/beets/library.py +++ b/beets/library.py @@ -1783,6 +1783,11 @@ def tmpl_upper(s): """Convert a string to upper case.""" return s.upper() + @staticmethod + def tmpl_capitalize(s): + """Converts to a capitalized string.""" + return s.capitalize() + @staticmethod def tmpl_title(s): """Convert a string to title case.""" diff --git a/docs/changelog.rst b/docs/changelog.rst index 38997d4a9e..bb36281e87 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,8 @@ Changelog goes here! Please add your entry to the bottom of one of the lists bel New features: +* New template function added: ``%capitalize``. Converts the first letter of + the text to uppercase and the rest to lowercase. * Ability to query albums with track db fields and vice-versa, for example `beet list -a title:something` or `beet list artpath:cover`. Consequently album queries involving `path` field have been sped up, like `beet list -a diff --git a/docs/reference/pathformat.rst b/docs/reference/pathformat.rst index 7c52a92eb2..d80bdec346 100644 --- a/docs/reference/pathformat.rst +++ b/docs/reference/pathformat.rst @@ -60,6 +60,7 @@ These functions are built in to beets: * ``%lower{text}``: Convert ``text`` to lowercase. * ``%upper{text}``: Convert ``text`` to UPPERCASE. +* ``%capitalize{text}``: Make the first letter of ``text`` UPPERCASE and the rest lowercase. * ``%title{text}``: Convert ``text`` to Title Case. * ``%left{text,n}``: Return the first ``n`` characters of ``text``. * ``%right{text,n}``: Return the last ``n`` characters of ``text``. diff --git a/test/test_library.py b/test/test_library.py index 4e9c50b44e..9b29505a3d 100644 --- a/test/test_library.py +++ b/test/test_library.py @@ -629,6 +629,10 @@ def test_upper_case_variable(self): self._setf("%upper{$title}") self._assert_dest(b"/base/THE TITLE") + def test_capitalize_variable(self): + self._setf("%capitalize{$title}") + self._assert_dest(b"/base/The title") + def test_title_case_variable(self): self._setf("%title{$title}") self._assert_dest(b"/base/The Title")