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() == "":
|
if block.strip() == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
lines = block.strip().split("\n")
|
lines = block.strip().splitlines()
|
||||||
new_block["number"] = lines[0].strip()
|
new_block["number"] = lines[0].strip()
|
||||||
timestamp = lines[1].strip()
|
timestamp = lines[1].strip()
|
||||||
new_block["time"] = timestamp
|
new_block["time"] = timestamp
|
||||||
@ -94,7 +94,7 @@ class SRTBookLoader(BaseBookLoader):
|
|||||||
if not text:
|
if not text:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
block = text.split("\n")
|
block = text.splitlines()
|
||||||
if len(block) < 2:
|
if len(block) < 2:
|
||||||
return {"number": block[0], "text": ""}
|
return {"number": block[0], "text": ""}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class TXTBookLoader(BaseBookLoader):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with open(f"{txt_name}", encoding="utf-8") as f:
|
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:
|
except Exception as e:
|
||||||
raise Exception("can not load file") from e
|
raise Exception("can not load file") from e
|
||||||
@ -127,7 +127,7 @@ class TXTBookLoader(BaseBookLoader):
|
|||||||
def load_state(self):
|
def load_state(self):
|
||||||
try:
|
try:
|
||||||
with open(self.bin_path, encoding="utf-8") as f:
|
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:
|
except Exception as e:
|
||||||
raise Exception("can not load resume file") from 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):
|
def translate_and_split_lines(self, text):
|
||||||
result_str = self.translate(text, False)
|
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() != ""]
|
lines = [line.strip() for line in lines if line.strip() != ""]
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ The total token is too long and cannot be completely translated\n
|
|||||||
print("continue")
|
print("continue")
|
||||||
|
|
||||||
def join_lines(self, text):
|
def join_lines(self, text):
|
||||||
lines = text.split("\n")
|
lines = text.splitlines()
|
||||||
new_lines = []
|
new_lines = []
|
||||||
temp_line = []
|
temp_line = []
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ The total token is too long and cannot be completely translated\n
|
|||||||
|
|
||||||
# del ^M
|
# del ^M
|
||||||
text = text.replace("^M", "\r")
|
text = text.replace("^M", "\r")
|
||||||
lines = text.split("\n")
|
lines = text.splitlines()
|
||||||
filtered_lines = [line for line in lines if line.strip() != "\r"]
|
filtered_lines = [line for line in lines if line.strip() != "\r"]
|
||||||
new_text = "\n".join(filtered_lines)
|
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):
|
def translate_and_split_lines(self, text):
|
||||||
result_str = self.translate(text, False)
|
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() != ""]
|
lines = [line.strip() for line in lines if line.strip() != ""]
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ The total token is too long and cannot be completely translated\n
|
|||||||
print("continue")
|
print("continue")
|
||||||
|
|
||||||
def join_lines(self, text):
|
def join_lines(self, text):
|
||||||
lines = text.split("\n")
|
lines = text.splitlines()
|
||||||
new_lines = []
|
new_lines = []
|
||||||
temp_line = []
|
temp_line = []
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ The total token is too long and cannot be completely translated\n
|
|||||||
|
|
||||||
# del ^M
|
# del ^M
|
||||||
text = text.replace("^M", "\r")
|
text = text.replace("^M", "\r")
|
||||||
lines = text.split("\n")
|
lines = text.splitlines()
|
||||||
filtered_lines = [line for line in lines if line.strip() != "\r"]
|
filtered_lines = [line for line in lines if line.strip() != "\r"]
|
||||||
new_text = "\n".join(filtered_lines)
|
new_text = "\n".join(filtered_lines)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user