mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-06-05 19:15:34 +00:00
This commit change split("\n") to splitlines()
fix: #269 and help by @WeeAris Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
a599ba7eee
commit
d0350e0fd0
@ -66,7 +66,7 @@ class SRTBookLoader(BaseBookLoader):
|
||||
if block.strip() == "":
|
||||
continue
|
||||
|
||||
lines = block.strip().split("\n")
|
||||
lines = block.strip().splitlines()
|
||||
new_block["number"] = lines[0].strip()
|
||||
timestamp = lines[1].strip()
|
||||
new_block["time"] = timestamp
|
||||
@ -94,7 +94,7 @@ class SRTBookLoader(BaseBookLoader):
|
||||
if not text:
|
||||
return {}
|
||||
|
||||
block = text.split("\n")
|
||||
block = text.splitlines()
|
||||
if len(block) < 2:
|
||||
return {"number": block[0], "text": ""}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class TXTBookLoader(BaseBookLoader):
|
||||
|
||||
try:
|
||||
with open(f"{txt_name}", encoding="utf-8") as f:
|
||||
self.origin_book = f.read().split("\n")
|
||||
self.origin_book = f.read().splitlines()
|
||||
|
||||
except Exception as e:
|
||||
raise Exception("can not load file") from e
|
||||
@ -127,7 +127,7 @@ class TXTBookLoader(BaseBookLoader):
|
||||
def load_state(self):
|
||||
try:
|
||||
with open(self.bin_path, encoding="utf-8") as f:
|
||||
self.p_to_save = f.read().split("\n")
|
||||
self.p_to_save = f.read().splitlines()
|
||||
except Exception as e:
|
||||
raise Exception("can not load resume file") from e
|
||||
|
||||
|
@ -147,7 +147,7 @@ The total token is too long and cannot be completely translated\n
|
||||
|
||||
def translate_and_split_lines(self, text):
|
||||
result_str = self.translate(text, False)
|
||||
lines = result_str.split("\n")
|
||||
lines = result_str.splitlines()
|
||||
lines = [line.strip() for line in lines if line.strip() != ""]
|
||||
return lines
|
||||
|
||||
@ -223,7 +223,7 @@ The total token is too long and cannot be completely translated\n
|
||||
print("continue")
|
||||
|
||||
def join_lines(self, text):
|
||||
lines = text.split("\n")
|
||||
lines = text.splitlines()
|
||||
new_lines = []
|
||||
temp_line = []
|
||||
|
||||
@ -244,7 +244,7 @@ The total token is too long and cannot be completely translated\n
|
||||
|
||||
# del ^M
|
||||
text = text.replace("^M", "\r")
|
||||
lines = text.split("\n")
|
||||
lines = text.splitlines()
|
||||
filtered_lines = [line for line in lines if line.strip() != "\r"]
|
||||
new_text = "\n".join(filtered_lines)
|
||||
|
||||
|
@ -170,7 +170,7 @@ The total token is too long and cannot be completely translated\n
|
||||
|
||||
def translate_and_split_lines(self, text):
|
||||
result_str = self.translate(text, False)
|
||||
lines = result_str.split("\n")
|
||||
lines = result_str.splitlines()
|
||||
lines = [line.strip() for line in lines if line.strip() != ""]
|
||||
return lines
|
||||
|
||||
@ -246,7 +246,7 @@ The total token is too long and cannot be completely translated\n
|
||||
print("continue")
|
||||
|
||||
def join_lines(self, text):
|
||||
lines = text.split("\n")
|
||||
lines = text.splitlines()
|
||||
new_lines = []
|
||||
temp_line = []
|
||||
|
||||
@ -267,7 +267,7 @@ The total token is too long and cannot be completely translated\n
|
||||
|
||||
# del ^M
|
||||
text = text.replace("^M", "\r")
|
||||
lines = text.split("\n")
|
||||
lines = text.splitlines()
|
||||
filtered_lines = [line for line in lines if line.strip() != "\r"]
|
||||
new_text = "\n".join(filtered_lines)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user