Skip to content

Commit

Permalink
fixes to rename related and audio replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
yajrendrag committed Apr 27, 2024
1 parent 0a78415 commit f180a74
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions source/rename_file/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

**<span style="color:#56adda">0.0.4</span>**
- fix audio replacement function - variables were reversed
- fix rename relaed function to explicitly exclude video suffix file

**<span style="color:#56adda">0.0.3</span>**
- added renaming of related files (same basename with other extensions, .e.g., .srt, .nfo, etc)

Expand Down
2 changes: 1 addition & 1 deletion source/rename_file/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"on_postprocessor_task_results": 0
},
"tags": "rename, postprocessor",
"version": "0.0.3"
"version": "0.0.4"
}
16 changes: 12 additions & 4 deletions source/rename_file/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ def rename_related(abspath, newpath):
basefile = os.path.splitext(abspath)[0]
basefile_new = os.path.splitext(newpath)[0]
related_files = glob.glob(glob.escape(basefile) + '.*')
related_files = [file for file in related_files if file != abspath]
# related_files = [file for file in related_files if file != abspath]
logger.debug("related_files: '{}'".format(related_files))
related_files = [file for file in related_files if os.path.splitext(file)[1] != os.path.splitext(abspath)[1]]
logger.debug("related_files: '{}'".format(related_files))
for file in related_files:
sfx = os.path.splitext(file)[1]
os.rename(basefile + sfx, basefile_new + sfx)
Expand Down Expand Up @@ -189,6 +192,7 @@ def append(data, settings, abspath, streams):
logger.debug("basefile: '{}', suffix: '{}', newpath: '{}'".format(basefile, suffix, newpath))
if newpath != abspath:
os.rename (abspath, newpath)
logger.debug("abspath: '{}', newpath: '{}'".format(abspath, newpath))
rename_related(abspath, newpath)
else:
logger.info("Newpath = existing path - nothing to rename")
Expand Down Expand Up @@ -248,9 +252,10 @@ def replace(data, settings, abspath, streams):
channel_layout = streams[astream]["channel_layout"]
channels = streams[astream]["channels"]
if channel_layout == "stereo" and channels == '2':
acodec = audio_codec + channel_layout + '.0'
acodec = audio_codec + ' ' + str(channels) + '.0'
elif channels > 4:
acodec = audio_codec + str(channel_layout).replace('(side)','')
acodec = audio_codec + ' ' + str(channel_layout).replace('(side)','')
logger.debug("acodec: '{}'".format(acodec))

if basename.find(codec) > 0:
basename = basename.replace(codec, video_codec)
Expand All @@ -261,7 +266,8 @@ def replace(data, settings, abspath, streams):
else:
basename = basename.replace(resolution, str(vrez_height))

if basename.find(acodec) > 0:
logger.debug("find_audio: '{}'".format(basename.find(audio)))
if basename.find(audio) > 0:
basename = basename.replace(audio, acodec)

newpath = dirname + '/' + basename
Expand Down Expand Up @@ -296,6 +302,8 @@ def on_postprocessor_task_results(data):

status = data.get('task_processing_success')
logger.debug("status: '{}'".format(status))
logger.debug("source: '{}'".format(data.get('source_data')))
logger.debug("destinations: '{}'".format(data.get('destination_files')))

if status:
append_or_replace = settings.get_setting('modify_name_fields')
Expand Down

0 comments on commit f180a74

Please sign in to comment.