Compare commits
No commits in common. "c47c4817315bc02bba0218afa5d3c4209dd38ec8" and "fb031fcaf6331fbe6cad52b19d8acdebc257f191" have entirely different histories.
c47c481731
...
fb031fcaf6
@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
from karaokatalog.instructions.MoveInstruction import MoveInstruction
|
from karaokatalog.instructions.MoveInstruction import MoveInstruction
|
||||||
from karaokatalog.Song import Song
|
from karaokatalog.Song import Song
|
||||||
|
|
||||||
FORBIDDEN_CHARACTERS = re.compile(r'[\/<>:"\\|?*]')
|
FORBIDDEN_CHARACTERS = re.compile(r'[/<>:"\\|?*]')
|
||||||
|
|
||||||
|
|
||||||
def _get_canonical_song_dir(song: Song, variant: int = 0) -> Path:
|
def _get_canonical_song_dir(song: Song, variant: int = 0) -> Path:
|
||||||
|
@ -26,20 +26,8 @@ def _parse_tag_line(tag_line: str) -> tuple[str, str | None]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _parse_song_txt_with_encoding(song_txt: Path, encoding: str) -> dict[str, Any]:
|
def parse_song_txt(song_txt: Path) -> dict[str, Any]:
|
||||||
with song_txt.open(encoding=encoding) as f:
|
with song_txt.open(encoding="utf-8", errors="ignore") as f:
|
||||||
tags = dict(_parse_tag_line(line) for line in f if line.startswith("#"))
|
tags = dict(_parse_tag_line(line) for line in f if line.startswith("#"))
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
def parse_song_txt(song_txt: Path) -> dict[str, Any]:
|
|
||||||
encodings_to_try = ("utf-8", "cp1252")
|
|
||||||
|
|
||||||
for encoding_to_try in encodings_to_try:
|
|
||||||
try:
|
|
||||||
return _parse_song_txt_with_encoding(song_txt, encoding_to_try)
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
raise UnicodeError(f"Could not guess encoding for {song_txt}")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user