diff options
author | Boteium | 2017-10-28 20:52:31 +0800 |
---|---|---|
committer | Boteium | 2017-10-28 20:52:31 +0800 |
commit | 3383e6f37f9ad8e57003cffaefa87d687cc487de (patch) | |
tree | a4d939fca814d015ec28d97bb1004c4a9fd5ca49 | |
parent | 3b1c8634c4db58635b22f984aeefafec2160fe7e (diff) | |
download | aur-3383e6f37f9ad8e57003cffaefa87d687cc487de.tar.gz |
update to version 0.0.4
-rw-r--r-- | .SRCINFO | 8 | ||||
-rw-r--r-- | PKGBUILD | 6 | ||||
-rw-r--r-- | srt-delay | 97 |
3 files changed, 104 insertions, 7 deletions
@@ -1,13 +1,13 @@ pkgbase = srt-delay pkgdesc = A commandline tool to adjust srt's time stamp. - pkgver = 0.0.3 + pkgver = 0.0.4 pkgrel = 1 - url = http://code.google.com/p/trizen/downloads/detail?name=srt-delay-0.0.3.tar.gz + url = http://code.google.com/p/trizen/downloads/detail?name=srt-delay-0.0.4.tar.gz arch = any license = GPL depends = perl>=5.10.1 - source = http://trizen.googlecode.com/files/srt-delay-0.0.3.tar.gz - md5sums = 61417d74fa64e394e69124d133c0bf6b + source = https://raw.githubusercontent.com/trizen/perl-scripts/master/Subtitle/srt-delay + md5sums = 0db4d334d487101b3674b72a5439b86e pkgname = srt-delay @@ -1,15 +1,15 @@ # Maintainer: Trizen <echo dHJpemVueEBnbWFpbC5jb20K | base64 -d> pkgname=srt-delay -pkgver=0.0.3 +pkgver=0.0.4 pkgrel=1 pkgdesc="A commandline tool to adjust srt's time stamp." arch=('any') url="http://code.google.com/p/trizen/downloads/detail?name=$pkgname-$pkgver.tar.gz" license=('GPL') depends=('perl>=5.10.1') -source=("http://trizen.googlecode.com/files/$pkgname-$pkgver.tar.gz") -md5sums=('61417d74fa64e394e69124d133c0bf6b') +source=("https://raw.githubusercontent.com/trizen/perl-scripts/master/Subtitle/srt-delay") +md5sums=('0db4d334d487101b3674b72a5439b86e') package() { install -Dm 755 "$pkgname" "$pkgdir/usr/bin/$pkgname" diff --git a/srt-delay b/srt-delay new file mode 100644 index 000000000000..771bbd8663b2 --- /dev/null +++ b/srt-delay @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +# Copyright (C) 2011-2017 Daniel "Trizen" Șuteu <echo dHJpemVueEBnbWFpbC5jb20K | base64 -d>. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +#------------------------------------------------------- +# Appname: srt-delay +# Version: 0.0.4 +# Created on: 26 December 2011 +# Latest edit on: 12 October 2017 +# https://github.com/trizen +#------------------------------------------------------- + +use 5.014; +use strict; + +use Scalar::Util qw(looks_like_number); +use experimental qw(smartmatch); + +sub usage { + print <<"USAGE"; +usage: $0 [options] [seconds] [file.srt] + +Options: + -b, --backup : backup original to .bak + +Examples: $0 -b 1.439 file.srt + $0 -b 0.321 file.srt + $0 -b -3.14 file.srt +USAGE + exit 0; +} + +sub time2sec { + my @out; + foreach my $time (@_) { + my ($hours, $min, $sec, $milisec) = split(/[:,]/, $time, 4); + push @out, $hours * 3600 + $min * 60 + $sec + $milisec / 1000; + } + return @out; +} + +sub sec2time { + my @out; + foreach my $sec (map { sprintf '%.3f', $_ } @_) { + push @out, + sprintf('%02d:%02d:%02d,%03d', ($sec / 3600 % 24, $sec / 60 % 60, $sec % 60, substr($sec, index($sec, '.') + 1))); + } + return @out; +} + +my $addition = (grep { looks_like_number($_) } @ARGV)[0] // usage(); + +my $backup = do { + (grep { $_ ~~ ['-b', '--backup'] } @ARGV) ? 1 : 0; +}; + +foreach my $file (grep { -f $_ } @ARGV) { + my @output; + open my $fh, '<', $file or die "Unable to open for read ${file}: $!\n"; + while (defined(my $line = <$fh>)) { + if ($line =~ /^\d+:\d+:\d+(?:,\d+)?\s*-->\s*\d+:\d+:\d+(?:,\d+)?(\s*)\z/) { + push @output, join( + ' --> ', + sec2time( + map ({ + my $sec = $_ + $addition; + $sec >= 0 + ? $sec + : !warn "[!] Time cannot be lower than zero at line $.\n"; + } time2sec(split(/\s*-->\s*/, $line, 2))) + ) + ) + . $1; + } + else { push @output, $line } + } + + close $fh; + rename $file, "$file.bak" if $backup; + + open $fh, '>', $file or die "Unable to open for write ${file}: $!\n"; + print {$fh} @output; + close $fh; +} |