Skip to content

Commit

Permalink
change video resolution format to common name
Browse files Browse the repository at this point in the history
  • Loading branch information
yajrendrag committed May 18, 2024
1 parent f180a74 commit bc71010
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions source/rename_file/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

**<span style="color:#56adda">0.0.5</span>**
- change video resolution format from WxH to Common Name, e.g., 1080p

**<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
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.4"
"version": "0.0.5"
}
17 changes: 17 additions & 0 deletions source/rename_file/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@

from rename_file.lib.ffmpeg import Probe, Parser

resolution = {
"640x480": "480p",
"1280x720": "720p",
"1920x1080": "1080p",
"2560x1440": "1440p",
"2560x1440": "1080p",
"3840x2160": "2160p",
"7680x4320": "4320p",
}

# Configure plugin logger
logger = logging.getLogger("Unmanic.Plugin.rename_file")

Expand Down Expand Up @@ -122,14 +132,21 @@ def append(data, settings, abspath, streams):
if append_video_resolution:
vrezw = [streams[i]["width"] for i in range(len(streams)) if "codec_type" in streams[i] and streams[i]["codec_type"] == 'video']
vrezh = [streams[i]["height"] for i in range(len(streams)) if "codec_type" in streams[i] and streams[i]["codec_type"] == 'video']
field_order = [streams[i]["field_order"] for i in range(len(streams)) if "codec_type" in streams[i] and streams[i]["codec_type"] == 'video']
try:
vrezw = vrezw[0]
vrezh = vrezh[0]
field_order = field_order[0]
except IndexError:
vrez = ''
logger.info("Not including video resolution - could not extract video resolution from file: '{}'".format(abspath))
else:
vrez = str(vrezw) + "x" + str(vrezh)
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))
else:
vrez = ''

Expand Down

0 comments on commit bc71010

Please sign in to comment.