Skip to content

Commit

Permalink
fix: Try to fix the bug that causes the output error on Windows. #242
Browse files Browse the repository at this point in the history
  • Loading branch information
bookfere committed Mar 18, 2024
1 parent 548db7f commit 5db4a23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions engines/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class GeminiPro(Base):

concurrency_limit = 1
request_interval = 1
request_timeout = 30.0

prompt = (
'You are a meticulous translator who translates any given content '
Expand Down
13 changes: 5 additions & 8 deletions lib/conversion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
import os.path
from types import MethodType
from tempfile import gettempdir
Expand Down Expand Up @@ -209,8 +210,8 @@ def translate_ebook(self, ebook, cache_only=False, is_batch=False):
input_path = ebook.get_input_path()
if not self.config.get('to_library'):
output_path = os.path.join(
self.config.get('output_path'), '%s [%s].%s' % (
ebook.title[:200], ebook.target_lang, ebook.output_format))
self.config.get('output_path'),
'%s.%s' % (ebook.title[:200], ebook.output_format))
else:
output_path = PersistentTemporaryFile(
suffix='.' + ebook.output_format).name
Expand Down Expand Up @@ -266,21 +267,17 @@ def translate_done(self, job):
metadata.title = ebook_title

if self.config.get('to_library'):
# with open(output_path, 'rb') as file:
# metadata = get_metadata(file, ebook.output_format)
# if ebook.is_extra_format():
# metadata.title = ebook.title
book_id = self.db.create_book_entry(metadata)
self.api.add_format(
book_id, ebook.output_format, output_path, run_hooks=False)
self.gui.library_view.model().books_added(1)
output_path = self.api.format_abspath(book_id, ebook.output_format)
# os.remove(temp_file)
else:
dirname = os.path.dirname(output_path)
filename = '%s.%s' % (ebook_title, ebook.output_format)
new_output_path = os.path.join(dirname, filename)
os.rename(output_path, new_output_path)
# os.rename(output_path, new_output_path)
shutil.move(output_path, new_output_path)
output_path = new_output_path

self.gui.status_bar.show_message(
Expand Down

0 comments on commit 5db4a23

Please sign in to comment.