Skip to content

Commit

Permalink
add non-standard rez naming option
Browse files Browse the repository at this point in the history
  • Loading branch information
yajrendrag committed Oct 1, 2024
1 parent 09c517e commit c403be8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 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.9</span>**
- add option to use non-standard resolution based on height only and field_order value
- cleaned up logger output and made consistent between replace and append modes

**<span style="color:#56adda">0.0.8</span>**
- change reference to file's parsed resolution to rez from resolution

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.8"
"version": "0.0.9"
}
31 changes: 20 additions & 11 deletions source/rename_file/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"1280x720": "720p",
"1920x1080": "1080p",
"2560x1440": "1440p",
"2560x1440": "1080p",
"3840x2160": "2160p",
"7680x4320": "4320p",
}
Expand All @@ -46,6 +45,7 @@
class Settings(PluginSettings):
settings = {
"modify_name_fields": True,
"get_rez_from_height": False,
"append_video_resolution": "",
"append_audio_codec": "",
"append_audio_channel_layout": "",
Expand All @@ -58,6 +58,9 @@ def __init__(self, *args, **kwargs):
"modify_name_fields": {
"label": "Check this option if you want replace existing fields names with new values from ffprobe of transcoded file; uncheck if your wish to append new fields to file name from ffprobe metadata",
},
"get_rez_from_height": {
"label": "check this if you want the resolution named only from the height dimension, e.g., 854x480 (a non standard) would be named 480i or 480p depending on field_order param",
},
"append_video_resolution": self.__set_append_video_resolution_form_settings(),
"append_audio_codec": self.__set_append_audio_codec_form_settings(),
"append_audio_channel_layout": self.__set_append_audio_channel_layout_form_settings(),
Expand Down Expand Up @@ -117,6 +120,7 @@ def append(data, settings, abspath, streams):
append_audio_codec = settings.get_setting('append_audio_codec')
append_audio_channel_layout = settings.get_setting('append_audio_channel_layout')
append_audio_language = settings.get_setting('append_audio_language')
non_std_rez = settings.get_setting('get_rez_from_height')

logger.debug("abspath: '{}', append_video_resolution: '{}', append_audio_codec: '{}', append_audio_channel_layout: '{}', append_audio_language: '{}'".format(abspath, append_video_resolution, append_audio_codec, append_audio_channel_layout, append_audio_language))

Expand Down Expand Up @@ -146,7 +150,12 @@ def append(data, settings, abspath, streams):
vrez = resolution[vrez]
if field_order != "progressive": vrez = vrez.replace("p","i")
except KeyError:
logger.info("Leaving video resolution as WxH - cannot match to standard resolution: '{}'".format(vrez))
if not non_std_rez:
logger.info("Leaving video resolution as WxH - cannot match to standard resolution: '{}'".format(vrez))
else:
vrez = str(vrezh) + "p"
if field_order != "progressive": vrez = vrez.replace("p","i")
logger.info("using non standard resolution name - cannot match to standard resolution: '{}'".format(vrez))
else:
vrez = ''

Expand Down Expand Up @@ -219,6 +228,7 @@ def replace(data, settings, abspath, streams):
dirname = os.path.dirname(abspath)
parsed_info = PTN.parse(basename, standardise=False)
logger.debug("Parsed info: '{}'".format(parsed_info))
non_std_rez = settings.get_setting('get_rez_from_height')

try:
codec = parsed_info["codec"]
Expand Down Expand Up @@ -253,15 +263,20 @@ def replace(data, settings, abspath, streams):
except:
vrez_height = ""
vrez_width = ""
logger.debug("Error extracting resolution from file: '{}'".format(abspath))
logger.info("removing resolution from filename, resolution cannot be extracted from file")
vrez=""
else:
vrez = str(vrez_width) + "x" + str(vrez_height)
try:
vrez = resolution[vrez]
if field_order != "progressive": vrez = vrez.replace("p","i")
except KeyError:
logger.info("Leaving video resolution as WxH - cannot match to standard resolution: '{}'".format(vrez))
if not non_std_rez:
logger.info("Leaving video resolution as WxH - cannot match to standard resolution: '{}'".format(vrez))
else:
vrez = str(vrezh) + "p"
if field_order != "progressive": vrez = vrez.replace("p","i")
logger.info("using non standard resolution name - cannot match to standard resolution: '{}'".format(vrez))

astreams_default = [i for i in range(0, len(streams)) if "codec_type" in streams[i] and streams[i]["codec_type"] == 'audio' and "disposition" in streams[i] and "default" in streams[i]["disposition"] and streams[i]["disposition"] == 1]
astreams_first = [i for i in range(0, len(streams)) if "codec_type" in streams[i] and streams[i]["codec_type"] == 'audio']
Expand Down Expand Up @@ -289,13 +304,7 @@ def replace(data, settings, abspath, streams):

logger.debug("rez: '{}', vrez: '{}'".format(rez, vrez))
if basename.find(rez) > 0:
if 'i' in vrez or 'p' in vrez:
basename = basename.replace(rez, vrez)
elif vrez == "":
basename = basename.replace(rez, "")
logger.info("removing resolution from filename, resolution cannot be extracted from file")
else:
basename = basename.replace(rez, str(vrez_height))
basename = basename.replace(rez, vrez)

logger.debug("find_audio: '{}'".format(basename.find(audio)))
if basename.find(audio) > 0:
Expand Down

0 comments on commit c403be8

Please sign in to comment.