Permalink
Browse files

put helper functions in separate module

  • Loading branch information...
1 parent ad4d1d7 commit d3153ec82469f2f9853e540b43b3b3492aafae95 @Raven24 committed May 5, 2012
Showing with 85 additions and 44 deletions.
  1. +77 −0 common.pm
  2. +8 −44 webmize
View
77 common.pm
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+
+# common helpers
+# (c) 2011-2012 Florian Staudacher
+# http://github.com/Raven24/webmize
+#
+#
+# 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/>.
+
+# Log functions
+sub log_err {
+ logf(shift, "error");
+ exit 1;
+}
+
+sub log_info {
+ logf(shift, "info");
+}
+
+# logger
+sub logf {
+ my $msg = shift;
+ my $lvl = shift;
+ my $lvlLen = 7;
+ my $out = "";
+
+ if( !$lvl || $lvl eq "" ) {
+ $out .= "-" x ($lvlLen+2);
+ } else {
+ $out .= "[". sprintf('%*s', $lvlLen, $lvl) . "]";
+ }
+ $out .= " " . $msg . "\n";
+ print $out;
+}
+
+# round a number up to the next multiple of 8
+sub round_eight {
+ my $num = shift;
+ return ($num + 7) & ~7;
+}
+
+# load a CPAN module for further usage
+sub load_module {
+ # get the module name
+ my $name = shift;
+
+ eval "use $name";
+
+ if ($@) {
+ log_err("you need the module $name from CPAN!");
+ }
+
+ return 1;
+}
+
+# trim whitespace around a string
+sub trim
+{
+ my $string = shift;
+ $string =~ s/^\s+//;
+ $string =~ s/\s+$//;
+ return $string;
+}
+
+return 1;
+exit;
View
52 webmize
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# webmize
-# (c) 2011 Florian Staudacher
+# (c) 2011-2012 Florian Staudacher
# http://github.com/Raven24/webmize
#
#
@@ -23,10 +23,16 @@
# webmize -i input.mpeg -o output.webm -h 360 -w 0
use strict;
+use FindBin;
+use lib $FindBin::Bin;
+
+use common
+
load_module("Getopt::Long");
+load_module("File::Which");
load_module("Data::Dumper");
-my $ffmpeg = "/usr/bin/ffmpeg";
+my $ffmpeg = which('ffmpeg');
my %vbitrate = (
low => '1200k',
@@ -179,19 +185,6 @@ system("$ffmpeg -i \"$infile\" $filterString -vpre $vpreStr -b $vbitrateStr -r $
logf("done.");
-# load a CPAN module for further usage
-sub load_module {
- # get the module name
- my $name = shift;
-
- eval "use $name";
-
- if ($@) {
- log_err("you need the module $name from CPAN!");
- }
-
- return 1;
-}
# print out usage information
sub usage {
@@ -240,12 +233,6 @@ END
exit 0;
}
-# round a number up to the next multiple of 8
-sub round_eight {
- my $num = shift;
- return ($num + 7) & ~7;
-}
-
# get video dimensions
sub get_dimensions {
my $filename = shift;
@@ -275,27 +262,4 @@ sub get_dimensions {
return 0;
}
-sub log_err {
- logf(shift, "error");
- exit 1;
-}
-
-sub log_info {
- logf(shift, "info");
-}
-# logger
-sub logf {
- my $msg = shift;
- my $lvl = shift;
- my $lvlLen = 7;
- my $out = "";
-
- if( !$lvl || $lvl eq "" ) {
- $out .= "-" x ($lvlLen+2);
- } else {
- $out .= "[". sprintf('%*s', $lvlLen, $lvl) . "]";
- }
- $out .= " " . $msg . "\n";
- print $out;
-}

0 comments on commit d3153ec

Please sign in to comment.