From f6bce88ebdc1e9dab902a1a78ab95a013fee4990 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Wed, 18 Jun 2025 20:56:25 -0700 Subject: [PATCH] [FEATURE] `height` and `width` variables (#1243) Adds `height` and `width` entry variables, representing pixels to know resolution. For audio, defaults to 0. --- .../scripting/entry_variables.rst | 14 +++++++++++++ src/ytdl_sub/entries/entry.py | 3 +++ .../entries/script/variable_definitions.py | 20 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/docs/source/config_reference/scripting/entry_variables.rst b/docs/source/config_reference/scripting/entry_variables.rst index eea90981..74107134 100644 --- a/docs/source/config_reference/scripting/entry_variables.rst +++ b/docs/source/config_reference/scripting/entry_variables.rst @@ -83,6 +83,13 @@ extractor_key :description: The yt-dlp extractor key +height +~~~~~~ +:type: ``Integer`` +:description: + Height in pixels of the video. If this value is unavailable (i.e. audio download), it + will default to 0. + ie_key ~~~~~~ :type: ``String`` @@ -165,6 +172,13 @@ webpage_url :description: The url to the webpage. +width +~~~~~ +:type: ``Integer`` +:description: + Width in pixels of the video. If this value is unavailable (i.e. audio download), it + will default to 0. + ---------------------------------------------------------------------------------------------------- Metadata Variables diff --git a/src/ytdl_sub/entries/entry.py b/src/ytdl_sub/entries/entry.py index 401afd49..f97e98f5 100644 --- a/src/ytdl_sub/entries/entry.py +++ b/src/ytdl_sub/entries/entry.py @@ -102,6 +102,9 @@ class Entry(BaseEntry, Scriptable): v.sponsorblock_chapters.metadata_key, [] ), v.comments: download_entry._kwargs_get(v.comments.metadata_key, []), + # Updates with more accurate value, which may differ from the metadata value + v.height: download_entry._kwargs_get(v.height.metadata_key, 0), + v.width: download_entry._kwargs_get(v.width.metadata_key, 0), } ) return self diff --git a/src/ytdl_sub/entries/script/variable_definitions.py b/src/ytdl_sub/entries/script/variable_definitions.py index cc86737d..75496a96 100644 --- a/src/ytdl_sub/entries/script/variable_definitions.py +++ b/src/ytdl_sub/entries/script/variable_definitions.py @@ -1093,6 +1093,24 @@ class EntryVariableDefinitions(ABC): definition="{ {} }", ) + @cached_property + def height(self: "VariableDefinitions") -> IntegerMetadataVariable: + """ + :description: + Height in pixels of the video. If this value is unavailable (i.e. audio download), it + will default to 0. + """ + return IntegerMetadataVariable.from_entry(metadata_key="height", default=0) + + @cached_property + def width(self: "VariableDefinitions") -> IntegerMetadataVariable: + """ + :description: + Width in pixels of the video. If this value is unavailable (i.e. audio download), it + will default to 0. + """ + return IntegerMetadataVariable.from_entry(metadata_key="width", default=0) + class VariableDefinitions( EntryVariableDefinitions, @@ -1133,6 +1151,8 @@ class VariableDefinitions( self.ytdl_sub_input_url_index, self.ytdl_sub_input_url_count, self.ytdl_sub_keep_files_date_eval, + self.width, + self.height, } @cache