Skip to content

Commit

Permalink
Merge pull request #101 from jmarmstrong1207/convert-library-conversion
Browse files Browse the repository at this point in the history
convert-library - don't copy original book when failed to convert the file | import converted book first before rm existing book | move failed import to processed_books/failed
  • Loading branch information
jmarmstrong1207 authored Oct 13, 2024
2 parents fb03c95 + 7077fa9 commit 57cd82e
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions scripts/convert-library.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ def convert_library(self):
print_and_log(f"[convert-library]: Conversion of {os.path.basename(file)} successful! Removing old version from library...")
except subprocess.CalledProcessError as e:
print_and_log(f"[convert-library]: Conversion of {os.path.basename(file)} was unsuccessful. See the following error:\n{e}")
shutil.copyfile(file, f"/config/processed_books/failed/{os.path.basename(file)}")
self.current_book += 1
continue

try: # Remove Book from Existing Library
subprocess.run(["calibredb", "remove", book_id, "--permanent", "--with-library", self.library_dir], check=True)

print_and_log(f"[convert-library]: Non-epub version of {Path(file).stem} (Book ID: {book_id}) was successfully removed from library.\nAdding converted version to library...")
except subprocess.CalledProcessError as e:
print_and_log(f"[convert-library]: Non-epub version of {Path(file).stem} couldn't be successfully removed from library. See the following error:\n{e}")
self.current_book += 1
continue

Expand All @@ -125,7 +115,17 @@ def convert_library(self):

print_and_log(f"[convert-library]: Import of {os.path.basename(target_filepath)} successfully completed!")
except subprocess.CalledProcessError as e:
print_and_log(f"[convert-library]: Import of {os.path.basename(target_filepath)} was not successfully completed. See the following error:\n{e}")
print_and_log(f"[convert-library]: Import of {os.path.basename(target_filepath)} was not successfully completed. Converted file moved to /config/processed_books/failed/{os.path.basename(target_filepath)}. See the following error:\n{e}")
shutil.move(target_filepath, f"/config/processed_books/failed/{os.path.basename(target_filepath)}")
self.current_book += 1
continue

try: # Remove Book from Existing Library
subprocess.run(["calibredb", "remove", book_id, "--permanent", "--with-library", self.library_dir], check=True)

print_and_log(f"[convert-library]: Non-epub version of {Path(file).stem} (Book ID: {book_id}) was successfully removed from library.\nAdding converted version to library...")
except subprocess.CalledProcessError as e:
print_and_log(f"[convert-library]: Non-epub version of {Path(file).stem} couldn't be successfully removed from library. See the following error:\n{e}")
self.current_book += 1
continue

Expand Down

0 comments on commit 57cd82e

Please sign in to comment.