Sync subtitles: Difference between revisions

(julia example)
Line 827:
 
</syntaxhighlight>
 
=={{header|jq}}==
'''Works with gojq, the Go implementation of jq'''
 
The following program has been written for gojq, the Go implementation of jq,
and will almost surely need adapting for use with other versions of jq.
 
'''Usage'''
 
To fast-forward the subtitles by 9 seconds:
<pre>
< movie.srt gojq -nRr --argjson seconds 9 -f sync-subtitles.jq
</pre>
where sync-subtitles.jq is the name of the file containing the jq program.
To roll-back, specify `seconds` as a negative number, e.g.:
<pre>
< movie.srt gojq -nRr --argjson seconds -9 -f sync-subtitles.jq
</pre>
<syntaxhighlight lang="jq">
def syncSubtitles($secs):
def fmt: "%H:%M:%S";
def adjust: strptime(fmt) | .[5] += $seconds | strftime(fmt);
 
if ($secs|type) != "number" then "The number of seconds must be specified as an integer" | error end
| inputs as $line
| ($line
| capture("^(?<start>[^,]*),(?<startms>[0-9]*) *--> *(?<finish>[^,]*),(?<finishms>[0-9]*)")
| "\(.start|adjust),\(.startms) --> \(.finish|adjust),\(.finishms)" )
// $line ;
 
if $seconds > 0 then
"Fast-forwarding \($seconds) seconds" | debug
| syncSubtitles($seconds)
elif $seconds == 0 then
"No resynchronization is needed" | debug
else
"Rolling-back \(-$seconds) seconds" | debug
| syncSubtitles($seconds)
end
</syntaxhighlight>
{{output}}
As shown elsewhere on this page.
 
=={{header|Julia}}==
2,502

edits