Skip to content

Instantly share code, notes, and snippets.

@zengargoyle
Created November 6, 2011 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zengargoyle/1342508 to your computer and use it in GitHub Desktop.
Save zengargoyle/1342508 to your computer and use it in GitHub Desktop.
#!/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