Skip to content

Commit

Permalink
add try block around os.rename to avoid cross device link error
Browse files Browse the repository at this point in the history
  • Loading branch information
yajrendrag committed Oct 16, 2024
1 parent dd149ef commit 0014f39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions source/subtitle_from_audio/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

**<span style="color:#56adda">0.0.13</span>**
- add shutil.copy2 instead of os.rename to avoid invalid cross-device link error

**<span style="color:#56adda">0.0.12</span>**
- added logger.debug
- moved original_file_path assignment statement to avoid using before defined
Expand Down
2 changes: 1 addition & 1 deletion source/subtitle_from_audio/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"on_worker_process": 2
},
"tags": "subtitle",
"version": "0.0.12"
"version": "0.0.13"
}
7 changes: 6 additions & 1 deletion source/subtitle_from_audio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pathlib import Path
import whisper
import iso639
import shutil

from unmanic.libs.unplugins.settings import PluginSettings

Expand Down Expand Up @@ -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

0 comments on commit 0014f39

Please sign in to comment.