Created
November 6, 2011 05:11
-
-
Save zengargoyle/1342508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use File::Basename; | |
my $cbrfile = $ARGV[0] or die "Usage: $0 <cbrfile>\n"; | |
# get a verbose basic list of archive contents. (path/to/file.ext) | |
my $pid = open my $fh, '-|', rar => vb => $cbrfile | |
or die "rar list failed: $!\n"; | |
my @output = <$fh>; | |
waitpid $pid, 0; | |
chomp @output; | |
# extract first file in list. | |
my $first = shift @output; | |
system rar => e => $cbrfile, $first | |
and die "rar extract failed.\n"; | |
# extract basefilename (without path) and type extension. | |
my $firstbase = basename $first; | |
my ($ext) = $firstbase =~ m/\.(\w+)$/; | |
# foobar.cbr yields foobar_cover.ext | |
my $cover = $cbrfile; | |
$cover =~ s/\.cbr$/_cover.$ext/; | |
rename $firstbase, $cover or die "can't rename: $!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment