Skip to content

Commit

Permalink
Fix detection of ASCII in title
Browse files Browse the repository at this point in the history
Now only detect the first character of each title, to avoid strange behaviour when mixed types of string is inputed, i.e. "中文测试 EnglishTest“
  • Loading branch information
byf3332 authored Jun 25, 2024
1 parent 96a0e60 commit 6f30d28
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion listCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def scan_directory(directory):
# function: sort titles of audio files
def sort_titles(audio_titles):
collator = icu.Collator.createInstance(icu.Locale("zh-CN.UTF-8")) # use chinese environment
return sorted(audio_titles, key=lambda x: (0 if x[0].isascii() else 1, collator.getSortKey(x[0])))
# check only the first character of the title whether it is ASCII, and sort according to the whole title
return sorted(audio_titles, key=lambda x: (0 if x[0][0].isascii() else 1, collator.getSortKey(x[0])))

# function: create m3u8 playlist
def create_m3u8(sorted_titles, root_directory, list_name):
Expand Down

0 comments on commit 6f30d28

Please sign in to comment.