Repository navigation
Live2D model dropdown truncates names: str.rstrip() used instead of removing the suffix #168
Description
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_listReproduction
- Put a model into
~/.var/app/moe.nyarchlinux.assistant/config/avatars/live2d/web/models/FuXuan/asfuxuan.model3.json - Open Settings → Live2D → Live2D Model
- The entry reads
fuxuainstead offuxuan
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— checkedsrc/handlers/avatar/live2d_handler.pytoday, 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.
Activity