seconv: Shift-JIS and GBK files without a BOM are read as windows-1252
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
Research direction
Start with src/libse/Common/LanguageAutoDetect.cs, especially DetectAnsiEncoding around line 2506 and the call from GetEncodingFromFile around line 2860. Compare how code page 949 is detected, then use the attached Shift-JIS, GBK, and cp949 samples to check encoding and language results with seconv info. Done means the Japanese and Chinese samples are identified correctly without changing the cp949 result.
Written by the indexing model from the issue text.
Description
Summary
Japanese and Chinese subtitle or lyric files in a legacy encoding (Shift-JIS, GBK) and without a BOM are decoded as windows-1252, so seconv translates and saves mojibake. libse's ANSI auto-detection tries Korean (cp949) but no Japanese or Chinese code page.
Seen with seconv 5.4.0-beta6 on Windows 11. The code is the same on main (cf1c3e3).
Steps to reproduce
- Unzip the attached
seconv-encoding-samples.zip.shift-jis.lrc,gbk.lrcandcp949.lrchold three lines of lyrics each, saved in that encoding without a BOM;utf-8.lrcis the Japanese file again in UTF-8, for comparison. seconv info shift-jis.lrc --jsonseconv shift-jis.lrc LrcLyrics --output-folder out
Expected and actual
seconv info on the attached files:
| File | Encoding | encoding reported |
language reported |
Expected |
|---|---|---|---|---|
shift-jis.lrc |
Shift-JIS (cp932) | windows-1252 | no | shift_jis, ja |
gbk.lrc |
GBK (cp936) | windows-1252 | sk | gb2312, zh |
cp949.lrc |
cp949 (Korean) | euc-kr | ko | as reported |
Step 3 writes the first line as [00:00.00]‚±‚ñ‚É‚¿‚ÍAŒ³‹C‚Å‚·‚© (UTF-8 with BOM). With --translate-to, that mojibake is what the translation engine receives, and the translated file replaces the original.
Side note: info prints zh without a script for UTF-8 Chinese too: SubtitleInfoGatherer calls AutoDetectGoogleLanguageOrNull without detectChineseScript, while the translation path passes true and gets zh-Hans / zh-Hant. I am not sure if this is intentional or a bug so figured I would call it out.
Cause
LanguageAutoDetect.GetEncodingFromFile finds no BOM, IsUtf8 fails, and with AutoGuessAnsiEncoding (default true) it calls DetectAnsiEncoding (LanguageAutoDetect.cs#L2860).
DetectAnsiEncoding tries 1251, 949, 1253, 1250, 1252, 1254, 28592, 28595, 874, 1255, 1256, 28591 and 28599 (LanguageAutoDetect.cs#L2506). There is no 932 (Shift-JIS), 936 (GBK) or 950 (Big5), so a Japanese or Chinese file can never be detected and falls through to the windows-1252 default.
Suggestion
Add 932, 936 and 950 as candidates in DetectAnsiEncoding, the way 949 is handled with AutoDetectWordsKorean: decode the buffer with each code page and count Hiragana/Katakana (U+3040–U+30FF, unambiguous for Japanese) or CJK ideographs (U+4E00–U+9FFF), and take the code page whose decode has the most of them and no replacement characters. A smaller alternative: when --translate-from is ja or zh and the input is not UTF-8, use the matching code page as the fallback encoding.
This report was drafted with the help of an AI assistant. The reproduction steps, outputs and source references were verified against seconv 5.4.0-beta6 and the linked lines before posting.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 1.4k
- Avg merge
- 1h 4m
- Merged PRs (30d)
- 643
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SubtitleEdit/subtitleedit
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
SubtitleEdit/subtitleedit#16699 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
SubtitleEdit/subtitleedit#16614 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
SubtitleEdit/subtitleedit#16374 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
SubtitleEdit/subtitleedit#14510 · 3 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
SubtitleEdit/subtitleedit#16701 ·
Maintainers usually reply within 1 day
All issues in SubtitleEdit/subtitleedit
Similar issues
-
needs-triage
Difficulty 1/5 1-3 hours Newbie friendliness 76/100
Azure/azure-sdk-for-net#64658 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
dotnet/aspnetcore#70370 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
NethermindEth/nethermind#15684 ·
Maintainers usually reply within 1 day
-
area/ai-assistant squad/flyt
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Altinn/altinn-studio#21798 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
arastella625/DAORework#181 ·
Maintainers usually reply within 1 day