EBook:...Unpack(3pm)
π EBook::Tools::Unpack β the manual, but make it cute π
okay bestie, so this is the page for EBook::Tools::Unpack from EBook::Tools, and it lives in section 3pm (that's "User Contributed Perl Documentation" for the uninitiated, iykyk π«Ά).
It's an object class. Its whole deal? Unpacking e-book files into their component parts and their metadata. Like, it guts the book, hands you the insides, and tells you who wrote it and what it's called. Iconic behavior honestly. πΈ
β¨ NAME β¨
EBook::Tools::Unpack β Object class for unpacking e-book files into their component parts and metadata π
β¨ SYNOPSIS β¨
The full-blown, choose-your-own-adventure version:
use EBook::Tools::Unpack;
my $unpacker = EBook::Tools::Unpack->new(
'file' => $filename,
'dir' => $dir,
'encoding' => $encoding,
'format' => $format,
'raw' => $raw,
'author' => $author,
'title' => $title,
'opffile' => $opffile,
'tidy' => $tidy,
'nosave' => $nosave,
);
$unpacker->unpack;
Or, more simply β the low-effort, high-reward route bestie, we love her:
use EBook::Tools::Unpack;
my $unpacker = EBook::Tools::Unpack->new('file' => 'mybook.prc');
$unpacker->unpack;
main character energy, honestly. one line and she's done. π
β¨ CONSTRUCTOR β¨
new(%args)
Instantiates a new Ebook::Tools::Unpack object. Baby's first unpacker. π
Arguments
fileβ The file to unpack. Specifying this is mandatory. No file, no vibes, no unpacking. periodt.dirβ The directory to unpack into. If you don't say anything, it defaults to the basename of the file. she'll figure it out herself πencodingβ If specified, this overrides the encoding to use when unpacking. Normally this gets detected from the file and you genuinely do not need to specify it. Valid values are'1252'(which means Windows-1252) and'65001'(which means UTF-8). narrow it down bestie.htmlconvertβ If set to true, an attempt will be made to convert non-HTML output text to HTML where possible. glow-up for your text files β¨keyβ The decryption key to use if necessary (not yet implemented). π§keyfileβ The file holding the decryption keys to use if necessary (not yet implemented). π§languageβ If specified, overrides the detected language information.opffileβ The name of the file in which the metadata will be stored. If you don't specify one, it defaults tocontent.opf.rawβ If set true, this forces no corrections to be done on any extracted text, and a lot of raw, unparsed, unmodified data gets dumped into the directory along with everything else. It's useful for debugging exactly what was in the file being unpacked, and β when combined withnosaveβ for reducing the time needed to extract parsed data from an ebook container without actually unpacking it. forensic girlie behavior πauthorβ Overrides the detected author name. (The detect said one thing, you said another. You win.) πtitleβ Overrides the detected title.tidyβ If set to true, the unpacker will runtidyon any HTML output files to convert them to valid XHTML. Be warned that this can occasionally change the formatting, because Tidy isn't very forgiving on certain common tricks (such as empty<pre>elements with style elements) that abuse the standard. π she does NOT play.nosaveβ If set to true, the unpacker will run through all of the unpacking steps except those that actually write to the disk. Useful for testing, but also β particularly when combined withrawβ it can be used for extracting parsed data from an ebook container without actually unpacking it. look but don't touch, we love a boundaries queen π«Ά
β¨ ACCESSOR METHODS β¨
See new() above for more details on what some of these actually mean. π Note that some values cannot be autodetected until an unpack method executes.
authordirfilefilebaseβ In scalar context, this is the basename offile. In list context, it actually returns the basename, directory, and extension β as perfileparsefromFile::Basename. context matters, bestie, it's giving shapeshifter π¦formatkeykeyfilelanguageβ This returns the language specified by the user, if any. It staysundefinedif the user has not requested that a language code be set β even if a language was autodetected. no means no, autodetect πopffilerawtitleβ This returns the title specified by the user, if any. It staysundefinedif the user has not requested a title be set β even if a title was autodetected. same energy, she respects your choices β¨detectedβ This returns a hash containing the autodetected metadata, if any. the receipts π
β¨ MODIFIER METHODS β¨
detect_format()
Attempts to automatically detect the format of the input file and set the internal object attributes $self->{format} and $self->{formatinfo}. The former is a one-word string used by the dispatcher to select the correct unpacking method; the latter may contain additional detected information (such as a title or version). π
Croaks if detection fails. dramatic, but fair π
In scalar context, returns $self->{format}. In list context, returns the two element list ($self->{format},$self->{formatinfo}).
This is automatically called by new() if the format argument is not specified. she just does it, no asking π
detect_from_mobi_exth()
Detects metadata values from the MOBI EXTH headers retrieved via unpack_mobi_exth() and places them into the detected attribute.
gen_opf(%args)
This generates an OPF file from detected and specified metadata. β οΈ It does not honor the nosave flag, and will always write its output. she said what she said.
Normally this is called automatically from inside the unpack methods, but it can be called manually after an unpack if the nosave flag was set β to write an OPF anyway. π retroactive OPF, we love a second chance.
Returns the filename of the OPF file.
Arguments
opffile(optional) β If specified, this overrides the object attributeopffile, and determines the filename to use for the generated OPF file. If it's not specified, and the object attributeopffilehas somehow been cleared (the attribute is set duringnew()), it will be generated by looking at thetextfileargument. If no value can be found, the method croaks. If a value was found somewhere other than the object attributeopffile, then the object attribute is updated to match. she syncs up, slay π₯textfile(optional) β The file containing the main text of the document. If specified, the method will attempt to split metadata out of the file and add whatever remains to the manifest of the OPF.mediatype(optional) β The media type (mime type) of the document specified viatextfile. Iftextfileis not specified, this argument is ignored. Iftextfileis specified, but
π bestie the sentence justβ¦ ends? the original manpage leaves us hanging right there at "but". no cap, that is genuinely how it's written. I'm not going to invent a finish line for her.
unpack()
This is a dispatcher for the specific unpacking methods needed to unpack a particular format. Unless you feel a need to override the unpacking method specified or detected during object construction, it is probalby better to call this than the specific unpacking methods. (yes that typo is hers, and yes we're keeping it, it's part of the lore π)
unpack_ereader()
Unpacks Fictionwise/PeanutPress eReader (-er.pdb) files.
unpack_imp()
Unpacks SoftBook/GEB/REB/eBookWise (.imp) files.
unpack_mobi()
Unpacks Mobipocket (.prc / .mobi) files.
unpack_msreader()
Unpacks Microsoft Reader (.lit) files
unpack_palmdoc()
Unpacks PalmDoc / AportisDoc (.pdb) files
unpack_zip()
Unpacks Zip archives (including ePub files).
β¨ BUGS AND LIMITATIONS β¨
the fine print, but make it fashion π
- DRM isn't handled. Infrastructure to support this via an external plug-in module may eventually be built, but it will never become part of the main module for legal reasons. legal girlies said no. π
- Unit tests are incomplete.
- Documentation is incomplete. Accessors in particular could use some cleaning up. (she's aware. she's working on herself. π§)
- Need to implement setter methods for object attributes.
- Import/extraction/unpacking is currently limited to PalmDoc, Mobipocket, and eReader. Extraction from Microsoft Reader (
.lit) and ePub is also eventually planned. Other formats may follow from there. the roadmap is... vibes-based β¨
β¨ AUTHOR β¨
Zed Pobre <zed@debian.org> π«Ά
β¨ LICENSE AND COPYRIGHT β¨
Copyright 2008 Zed Pobre
Licensed to the public under the terms of the GNU GPL, version 2. π
okay that's the whole thing bestie, you're officially unpacked-and-informed π this was perl v5.40.0, dated 2025-01-10 β go forth and unpack something iconic πβ¨
π¦ where this page comes from
- debian trixie: libebook-tools-perl 0.5.4-2 Β· GPL-2.0-only
- ubuntu resolute: libebook-tools-perl 0.5.4-2 Β· GPL-2.0-only
- ubuntu stonking: libebook-tools-perl 0.5.4-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms