Created
March 8, 2012 18:48
-
-
Save ndw/2002633 to your computer and use it in GitHub Desktop.
Patch unique identifier in Linux Journal EPUB files
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/perl -- # -*- Perl -*- | |
# Fixes the bookid identifier in Linux Journal EPUB files. | |
# No warranty. YMMV. etc. | |
use strict; | |
use English; | |
use Cwd qw(abs_path); | |
use File::Temp qw(tempdir); | |
my $ZIP = "zip"; | |
my $UNZIP = "unzip"; | |
my $JAVA = "java"; | |
my $EPUBCHECK = "/usr/local/epubcheck-1.2/epubcheck-1.2.jar"; | |
my $usage = "Usage: $0 dljxxx[.epub]\n"; | |
my $EPUB = shift @ARGV || die $usage; | |
$EPUB = abs_path($EPUB); | |
$EPUB =~ s/\.epub$//; | |
my $ID = $EPUB; | |
$ID =~ s/^.*\///; | |
my $NPUB = "$EPUB-patched.epub"; | |
my $tmp = tempdir('CLEANUP' => 1); | |
chdir ($tmp); | |
system ("$UNZIP -q $EPUB.epub"); | |
my $content = "OEBPS/content.opf"; | |
open (F, $content) || die "Unexpected archive format."; | |
read (F, $_, -s $content); | |
close (F); | |
system ("$ZIP -q0X $NPUB mimetype"); | |
system ("$ZIP -qXr9D $NPUB *"); | |
if (defined($EPUBCHECK)) { | |
system ("JAVA -jar $EPUBCHECK $NPUB"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment