From 0014f3976b4091be33cb454309d5d075c26827b2 Mon Sep 17 00:00:00 2001 From: yajrendrag Date: Tue, 15 Oct 2024 18:17:15 -0600 Subject: [PATCH] add try block around os.rename to avoid cross device link error --- source/subtitle_from_audio/changelog.md | 3 +++ source/subtitle_from_audio/info.json | 2 +- source/subtitle_from_audio/plugin.py | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/subtitle_from_audio/changelog.md b/source/subtitle_from_audio/changelog.md index 876be5b9d..101dda20f 100644 --- a/source/subtitle_from_audio/changelog.md +++ b/source/subtitle_from_audio/changelog.md @@ -1,4 +1,7 @@ +**0.0.13** +- add shutil.copy2 instead of os.rename to avoid invalid cross-device link error + **0.0.12** - added logger.debug - moved original_file_path assignment statement to avoid using before defined diff --git a/source/subtitle_from_audio/info.json b/source/subtitle_from_audio/info.json index 21a85ee60..62e78f303 100644 --- a/source/subtitle_from_audio/info.json +++ b/source/subtitle_from_audio/info.json @@ -15,5 +15,5 @@ "on_worker_process": 2 }, "tags": "subtitle", - "version": "0.0.12" + "version": "0.0.13" } diff --git a/source/subtitle_from_audio/plugin.py b/source/subtitle_from_audio/plugin.py index 22447ed46..d7a863137 100644 --- a/source/subtitle_from_audio/plugin.py +++ b/source/subtitle_from_audio/plugin.py @@ -25,6 +25,7 @@ from pathlib import Path import whisper import iso639 +import shutil from unmanic.libs.unplugins.settings import PluginSettings @@ -341,7 +342,11 @@ def on_postprocessor_task_results(data): srt_file = base_dest + '.' + audio_language_to_convert + '.srt' path = Path(srt_file_sans_lang) if path.is_file(): - os.rename(srt_file_sans_lang,srt_file) + try: + os.rename(srt_file_sans_lang,srt_file) + except OSError: + # avoid invalide cross-device link error + shutil.copy2(srt_file_sans_lang,srt_file) else: logger.error("Cannot create srt file. basename is: '{}' and srt file path should be: '{}'".format(base, srt_file)) return data