]> jfr.im git - yt-dlp.git/commitdiff
[outtmpl] Support multiplication
authorpukkandan <redacted>
Tue, 5 Dec 2023 22:14:11 +0000 (03:44 +0530)
committerpukkandan <redacted>
Tue, 5 Dec 2023 22:14:11 +0000 (03:44 +0530)
Related: #8683

README.md
test/test_YoutubeDL.py
yt_dlp/YoutubeDL.py

index f67cab572d9574733d75f0cec8e3adef10f646ce..78d4799a1b6cddafe5596a107a19c2e7b234f48e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1268,7 +1268,7 @@ # OUTPUT TEMPLATE
 
 1. **Object traversal**: The dictionaries and lists available in metadata can be traversed by using a dot `.` separator; e.g. `%(tags.0)s`, `%(subtitles.en.-1.ext)s`. You can do Python slicing with colon `:`; E.g. `%(id.3:7:-1)s`, `%(formats.:.format_id)s`. Curly braces `{}` can be used to build dictionaries with only specific keys; e.g. `%(formats.:.{format_id,height})#j`. An empty field name `%()s` refers to the entire infodict; e.g. `%(.{id,title})s`. Note that all the fields that become available using this method are not listed below. Use `-j` to see such fields
 
-1. **Addition**: Addition and subtraction of numeric fields can be done using `+` and `-` respectively. E.g. `%(playlist_index+10)03d`, `%(n_entries+1-playlist_index)d`
+1. **Arithmetic**: Simple arithmetic can be done on numeric fields using `+`, `-` and `*`. E.g. `%(playlist_index+10)03d`, `%(n_entries+1-playlist_index)d`
 
 1. **Date/time Formatting**: Date/time fields can be formatted according to [strftime formatting](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes) by specifying it separated from the field name using a `>`. E.g. `%(duration>%H-%M-%S)s`, `%(upload_date>%Y-%m-%d)s`, `%(epoch-3600>%H-%M-%S)s`
 
index 0cf130db03b1c711f1377731cc62d995e0526a3a..48c710e00c75de1c09cafb52d5e2ce685ad36092 100644 (file)
@@ -797,6 +797,7 @@ def expect_same_infodict(out):
         test('%(title|%)s %(title|%%)s', '% %%')
         test('%(id+1-height+3)05d', '00158')
         test('%(width+100)05d', 'NA')
+        test('%(filesize*8)d', '8192')
         test('%(formats.0) 15s', ('% 15s' % FORMATS[0], None))
         test('%(formats.0)r', (repr(FORMATS[0]), None))
         test('%(height.0)03d', '001')
index e65bef862c5025e20054da82ec7cd5cdc3e3c5ee..29dd761862faa362af0e9b0b7c3816d2894f80fa 100644 (file)
@@ -1179,6 +1179,7 @@ def prepare_outtmpl(self, outtmpl, info_dict, sanitize=False):
         MATH_FUNCTIONS = {
             '+': float.__add__,
             '-': float.__sub__,
+            '*': float.__mul__,
         }
         # Field is of the form key1.key2...
         # where keys (except first) can be string, int, slice or "{field, ...}"