Visitar URL original
Live2D model dropdown truncates names: str.rstrip() used instead of removing the suffix · Issue #168 · NyarchLinux/NyarchAssistant · GitHub
Skip to content

Live2D model dropdown truncates names: str.rstrip() used instead of removing the suffix #168

Closed

Description

@joshua-krimmer

Describe the bug

The Live2D Model dropdown truncates model names. The label is derived from the *.model3.json filename using str.rstrip(), which strips a set of characters rather than a suffix — so trailing letters that belong to the model's actual name get eaten.

str.rstrip('.model3.json') removes any trailing characters from the set . m o d e l 3 j s n. Any model whose name ends in one of those letters is displayed incorrectly.

Where

src/handlers/avatar/live2d_handler.py, line 37 (identical in the shipped 1.5.2 Flatpak):

def get_available_models(self):
    file_list = []
    for root, _, files in os.walk(self.models_dir):
        for file in files:
            if file.endswith('.model3.json') or file.endswith('.model.json'):
                file_name = file.rstrip('.model3.json').rstrip('.model.json')   # <-- bug
                relative_path = os.path.relpath(os.path.join(root, file), self.models_dir)
                file_list.append((file_name, relative_path))
    return file_list

Reproduction

  1. Put a model into ~/.var/app/moe.nyarchlinux.assistant/config/avatars/live2d/web/models/FuXuan/ as fuxuan.model3.json
  2. Open Settings → Live2D → Live2D Model
  3. The entry reads fuxua instead of fuxuan

Actual vs. expected

Verified by running the exact expression from line 37:

filename shown as expected
fuxuan.model3.json fuxua fuxuan
Jane Doe.model3.json Jane D Jane Doe
mikumiku.model3.json mikumiku mikumiku (unaffected)
TUBASA_014.model3.json TUBASA_014 TUBASA_014 (unaffected)

The last two only survive because they happen to end in u / 4, i.e. characters outside the strip set. This affects the bundled model too — Jane Doe ships with the app and renders as Jane D.

Worse: the .model.json branch is broken outright

The same line also handles Cubism 2 (*.model.json), and there the second rstrip chews through almost the whole name:

filename shown as expected
hiyori_free.model.json hiyori_fr hiyori_free
hiyori_pro.model.json hiyori_pr hiyori_pro
model.json (empty) model.json

A file literally named model.json produces an empty dropdown entry, because both rstrip calls together strip every character.

Suggested fix

-                    file_name = file.rstrip('.model3.json').rstrip('.model.json')
+                    file_name = file.removesuffix('.model3.json').removesuffix('.model.json')

str.removesuffix() needs Python ≥ 3.9; the app already targets 3.13, so this is safe.

Environment

  • Nyarch Assistant: 1.5.2 (Flathub Flatpak, moe.nyarchlinux.assistant)
  • Also present on: master — checked src/handlers/avatar/live2d_handler.py today, line 37 is unchanged
  • OS: Arch Linux

Workaround people are landing on

Since the label is the filename (not the folder name), users are forced to pick names that don't end in . 3 d e j l m n o s — e.g. naming a model FUXUAN.model3.json in all caps just so it isn't displayed as fuxua. That is a confusing thing to have to discover.

Related nit (same function, feel free to split out)

file_name is used purely as the display label while relative_path is the stored value, so two models in different folders with the same filename (e.g. two model3.json) render as two identical, indistinguishable dropdown entries. Showing the folder name as a fallback or suffix would make that unambiguous — and would arguably be the more intuitive label anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions