| 1 | package File::Sticker::Scribe::Epub; | ||
| 2 | $File::Sticker::Scribe::Epub::VERSION = '4.9'; | ||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | File::Sticker::Scribe::Epub - read, write and standardize meta-data from GIF file | ||
| 6 | |||
| 7 | =head1 VERSION | ||
| 8 | |||
| 9 | version 4.9 | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | use File::Sticker::Scribe::Epub; | ||
| 14 | |||
| 15 | my $obj = File::Sticker::Scribe::Epub->new(%args); | ||
| 16 | |||
| 17 | my %meta = $obj->read_meta($filename); | ||
| 18 | |||
| 19 | $obj->write_meta(%args); | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | This will read meta-data from EPUB files, and standardize it to a common | ||
| 24 | nomenclature, such as "tags" for things called tags, or Keywords or Subject etc. | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | 1 | ▶ | use common::sense; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 30 | 0 | ▶ | use File::LibMagic; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 31 | use Image::ExifTool qw(:Public); | ||
| 32 | use YAML::Any; | ||
| 33 | use File::Spec; | ||
| 34 | |||
| 35 | use parent qw(File::Sticker::Scribe::Exif); | ||
| 36 | |||
| 37 | # FOR DEBUGGING | ||
| 38 | =head1 DEBUGGING | ||
| 39 | |||
| 40 | =head2 whoami | ||
| 41 | |||
| 42 | Used for debugging info | ||
| 43 | |||
| 44 | =cut | ||
| 45 | sub whoami { ( caller(1) )[3] } | ||
| 46 | |||
| 47 | =head1 METHODS | ||
| 48 | |||
| 49 | =head2 priority | ||
| 50 | |||
| 51 | The priority of this scribe. Scribes with higher priority get tried first. | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | sub priority { | ||
| 56 | my $class = shift; | ||
| 57 | return 2; | ||
| 58 | } # priority | ||
| 59 | |||
| 60 | =head2 allowed_file | ||
| 61 | |||
| 62 | If this scribe can be used for the given file, then this returns true. | ||
| 63 | File must be an EPUB file. | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | sub allowed_file { | ||
| 68 | my $self = shift; | ||
| 69 | my $file = shift; | ||
| 70 | say STDERR whoami() if $self->{verbose} > 2; | ||
| 71 | |||
| 72 | my $realfile = $self->_get_the_real_file(filename=>$file); | ||
| 73 | my $ft = $self->{file_magic}->info_from_filename($realfile); | ||
| 74 | # The mime type may not be correct, so check the extension as well | ||
| 75 | if ($ft =~ /epub/ or $realfile =~ /\.epub/) | ||
| 76 | { | ||
| 77 | say STDERR 'Scribe ' . $self->name() . ' allows filetype ' . $ft->{mime_type} . ' of ' . $realfile if $self->{verbose} > 1; | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | return 0; | ||
| 81 | } # allowed_file | ||
| 82 | |||
| 83 | =head1 Helper Functions | ||
| 84 | |||
| 85 | Private interface. | ||
| 86 | |||
| 87 | =head2 _get_the_real_file | ||
| 88 | |||
| 89 | If the file is a soft link, look for the file it is pointing to | ||
| 90 | (because ExifTool behaves badly with soft links). | ||
| 91 | |||
| 92 | my $real_file = $scribe->_get_the_real_file(filename=>$filename); | ||
| 93 | |||
| 94 | =cut | ||
| 95 | |||
| 96 | sub _get_the_real_file { | ||
| 97 | my $self = shift; | ||
| 98 | my %args = @_; | ||
| 99 | say STDERR whoami() if $self->{verbose} > 2; | ||
| 100 | |||
| 101 | my $filename = $args{filename}; | ||
| 102 | # ExifTool has a wicked habit of replacing soft-linked files with the | ||
| 103 | # contents of the file rather than honouring the link. While using the | ||
| 104 | # exiftool script offers -overwrite_original_in_place to deal with this, | ||
| 105 | # the Perl module does not appear to have such an option available. | ||
| 106 | |||
| 107 | # So the way to get around this is to check if the file is a soft link, and | ||
| 108 | # if it is, find the real file, and write to that. And if *that* file is | ||
| 109 | # a soft link... go down the rabbit-hole as deep as it goes. | ||
| 110 | |||
| 111 | while (-l $filename) | ||
| 112 | { | ||
| 113 | my $realfile = readlink $filename; | ||
| 114 | if (-f $realfile) | ||
| 115 | { | ||
| 116 | $filename = $realfile; | ||
| 117 | } | ||
| 118 | else # give up and die | ||
| 119 | { | ||
| 120 | croak "$args{filename} is soft link, cannot find $realfile"; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | return $filename; | ||
| 125 | } # _get_the_real_file | ||
| 126 | |||
| 127 | =head1 BUGS | ||
| 128 | |||
| 129 | Please report any bugs or feature requests to the author. | ||
| 130 | |||
| 131 | =cut | ||
| 132 | |||
| 133 | 1; # End of File::Sticker::Scribe::Epub | ||
| 134 | __END__ | ||