summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authortrizen2023-07-08 11:22:09 +0300
committertrizen2023-07-08 11:22:09 +0300
commit4d6e6567501f010e78ad5baf49e4452836b01848 (patch)
tree7bb85d69f733714ad12d4bf0cf921e3f9d4f1c77
parent3383e6f37f9ad8e57003cffaefa87d687cc487de (diff)
downloadaur-4d6e6567501f010e78ad5baf49e4452836b01848.tar.gz
Version 0.0.6
-rw-r--r--.SRCINFO7
-rw-r--r--PKGBUILD6
-rwxr-xr-x[-rw-r--r--]srt-delay59
3 files changed, 42 insertions, 30 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 2826bc72a037..71ef85f1c056 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,13 +1,12 @@
pkgbase = srt-delay
pkgdesc = A commandline tool to adjust srt's time stamp.
- pkgver = 0.0.4
+ pkgver = 0.0.6
pkgrel = 1
- url = http://code.google.com/p/trizen/downloads/detail?name=srt-delay-0.0.4.tar.gz
+ url = https://github.com/trizen/perl-scripts
arch = any
license = GPL
depends = perl>=5.10.1
source = https://raw.githubusercontent.com/trizen/perl-scripts/master/Subtitle/srt-delay
- md5sums = 0db4d334d487101b3674b72a5439b86e
+ md5sums = ff37b6803ad128e43b05fc066e8936b3
pkgname = srt-delay
-
diff --git a/PKGBUILD b/PKGBUILD
index fb474a6cebf5..66a7e8c8f796 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,15 +1,15 @@
# Maintainer: Trizen <echo dHJpemVueEBnbWFpbC5jb20K | base64 -d>
pkgname=srt-delay
-pkgver=0.0.4
+pkgver=0.0.6
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"
+url="https://github.com/trizen/perl-scripts"
license=('GPL')
depends=('perl>=5.10.1')
source=("https://raw.githubusercontent.com/trizen/perl-scripts/master/Subtitle/srt-delay")
-md5sums=('0db4d334d487101b3674b72a5439b86e')
+md5sums=('ff37b6803ad128e43b05fc066e8936b3')
package() {
install -Dm 755 "$pkgname" "$pkgdir/usr/bin/$pkgname"
diff --git a/srt-delay b/srt-delay
index 771bbd8663b2..3cddead79e91 100644..100755
--- a/srt-delay
+++ b/srt-delay
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# Copyright (C) 2011-2017 Daniel "Trizen" Șuteu <echo dHJpemVueEBnbWFpbC5jb20K | base64 -d>.
+# Copyright (C) 2011-2017 Daniel "Trizen" Șuteu
#
# 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
@@ -13,34 +13,37 @@
# 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/>.
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#-------------------------------------------------------
# Appname: srt-delay
-# Version: 0.0.4
-# Created on: 26 December 2011
-# Latest edit on: 12 October 2017
+# Version: 0.0.6
+# Created: 26 December 2011
+# Edit on: 19 October 2020
# https://github.com/trizen
#-------------------------------------------------------
use 5.014;
use strict;
+use warnings;
-use Scalar::Util qw(looks_like_number);
-use experimental qw(smartmatch);
+use Getopt::Long qw(GetOptions);
sub usage {
+ my ($exit_code) = @_;
print <<"USAGE";
usage: $0 [options] [seconds] [file.srt]
Options:
- -b, --backup : backup original to .bak
+ -b --backup : backup original to .bak
+ -d --delay=f : number of seconds of delay
+ -s --scale=f : scale the timestamps by a multiple
-Examples: $0 -b 1.439 file.srt
- $0 -b 0.321 file.srt
- $0 -b -3.14 file.srt
+Examples: $0 -b -d=1.439 file.srt
+ $0 -b -d=0.321 file.srt
+ $0 -b -d=-3.14 file.srt
USAGE
- exit 0;
+ exit($exit_code // 0);
}
sub time2sec {
@@ -61,13 +64,23 @@ sub sec2time {
return @out;
}
-my $addition = (grep { looks_like_number($_) } @ARGV)[0] // usage();
+my $delay = 0;
+my $backup = 0;
+my $scale = 1;
-my $backup = do {
- (grep { $_ ~~ ['-b', '--backup'] } @ARGV) ? 1 : 0;
-};
+GetOptions(
+ "b|backup!" => \$backup,
+ "s|scale=f" => \$scale,
+ "d|delay=f" => \$delay,
+ "h|help" => sub { usage(0) },
+ )
+ or die("Error in command line arguments");
-foreach my $file (grep { -f $_ } @ARGV) {
+my @files = grep { -f $_ } @ARGV;
+
+@files || usage(2);
+
+foreach my $file (@files) {
my @output;
open my $fh, '<', $file or die "Unable to open for read ${file}: $!\n";
while (defined(my $line = <$fh>)) {
@@ -75,12 +88,12 @@ foreach my $file (grep { -f $_ } @ARGV) {
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)))
+ map {
+ my $sec = $scale * $_ + $delay;
+ ($sec >= 0)
+ ? $sec
+ : !warn "[!] Time cannot be lower than zero at line $.\n";
+ } time2sec(split(/\s*-->\s*/, $line, 2))
)
)
. $1;