On 18/07/2025 05:52, Greg Wooledge wrote:
On Thu, Jul 17, 2025 at 23:39:02 +0200, [email protected] wrote:
Video durations are formatted in youtube's .info.json files as "HH:MM:SS";
jq '.duration_string,.duration' m.info.json
"2:10:14"
7814
Taking into account earlier posts, I think that overall complexity of
the problem is enough to switch from shell to a better programming
language, e.g. python.
[...]
s=${m#*:} s=${s##+(0)}
[...]
This is one way to tackle the problem. It's *almost* POSIX compliant;
the bashisms here are the local variables in the function, and the +(0)
extended glob for removing multiple leading zeroes.
A mathematical trick may be used instead even if external processes like
sed are considered as undesired overhead
for i in 0 09 008 59 080; do i1=1$i; i2=2$i; echo "$i = $((2*i1 - i2))";
done
0 = 0
09 = 9
008 = 8
59 = 59
080 = 80