Login
You're viewing the functional.cafe public feed.
  • Sep 15, 2026, 4:21 AM

    I just wrote a script that generates valid vtt files in #jq

    def format_number: if . == 0 then "00" else if . < 10 then "0\(.)" else .|tostring end end;
    def format_number3: if . == 0 then "000" else if . < 100 then "0\(.)" else if . < 10 then "00\(.)" else .|tostring end end end;
    def format_time: ./3600|floor as $hour | ./60%60 as $minute | .%60 as $second | .*1000%1000 as $subsecond | "\($hour|format_number):\($minute|format_number):\($second|format_number).\($subsecond|format_number3)";
    "WEBVTT\n\n" , foreach .[] as $line (0; .+1; "\(.)\n\($line.Time|format_time) --> \(($line.Time+$line.CaptionDuration)|format_time)\n\($line.Caption)\n")

    FEAR MY AWESOME AUTISM POWERS

    (please clap this was difficult and unneccessary but i feel so accomplished)

    💬 1🔄 1⭐ 0

Replies

  • 💬 1🔄 0⭐ 0
  • Sep 15, 2026, 8:03 PM

    @esoteric_programmer the language is called jq and it is extremely trippy

    it's nothing like lua. basically everything is a stream. the pipe character means take the value of the expression on the left and use it as the input (represented by the dot character) of the expression on the right. ./3600|floor as $hour means "take the input of the current expression, divide each element (there's only one element) by 3600, then feed each result to the floor function, and bind the result to $hour for each evaluation of the expression that follows.

    jqlang.org/manual

    💬 0🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0