| 1 | #!/usr/bin/env perl | ||
| 2 | #=============================================================================== | ||
| 3 | # | ||
| 4 | # FILE: pronom2wxhexeditor.pl | ||
| 5 | # | ||
| 6 | # USAGE: ./pronom2wxhexeditor.pl | ||
| 7 | # | ||
| 8 | # DESCRIPTION: perl ./pronom2wxhexeditor.pl <DROIDSIGNATURE-FILE> <BINARYFILE> | ||
| 9 | # | ||
| 10 | # OPTIONS: --- | ||
| 11 | # REQUIREMENTS: --- | ||
| 12 | # BUGS: --- | ||
| 13 | # NOTES: --- | ||
| 14 | # AUTHOR: Andreas Romeyke, | ||
| 15 | # CREATED: 22.07.2020 14:26:43 | ||
| 16 | # REVISION: --- | ||
| 17 | #=============================================================================== | ||
| 18 | # PODNAME: pronomidentify.pl | ||
| 19 | use strict; | ||
| 20 | use warnings 'FATAL'; | ||
| 21 | use utf8; | ||
| 22 | use feature qw(say); | ||
| 23 | use Fcntl qw(:seek); | ||
| 24 | use File::Map qw(:map :extra); | ||
| 25 | use File::FormatIdentification::Pronom; | ||
| 26 | use Getopt::Long; | ||
| 27 | use Carp; | ||
| 28 | use List::Util qw( all ); | ||
| 29 | use Path::Tiny; | ||
| 30 | |||
| 31 | ################################################################################ | ||
| 32 | # main | ||
| 33 | ################################################################################ | ||
| 34 | my $pronomfile; | ||
| 35 | GetOptions ( | ||
| 36 | "signature=s" => \$pronomfile, | ||
| 37 | "help" => sub { | ||
| 38 | say "$0 --signature=droid_signature_filename <files or directory>"; | ||
| 39 | say "$0 --help "; | ||
| 40 | say ""; | ||
| 41 | exit 1; | ||
| 42 | } | ||
| 43 | ) or croak "wrong option, try '$0 --help'"; | ||
| 44 | |||
| 45 | if ( !defined $pronomfile ) { | ||
| 46 | say "you need at least a pronom signature file"; | ||
| 47 | exit; | ||
| 48 | } | ||
| 49 | my @files; | ||
| 50 | if (scalar @ARGV > 1) { | ||
| 51 | # assert all are files | ||
| 52 | if (any {path($_)->is_dir} @ARGV) { | ||
| 53 | say "you should use either files or one directory!"; | ||
| 54 | exit; | ||
| 55 | } else { | ||
| 56 | @files = @ARGV; | ||
| 57 | } | ||
| 58 | } elsif (scalar @ARGV == 1) { | ||
| 59 | my $path = path( $ARGV[0] ); | ||
| 60 | if ($path->is_dir) { | ||
| 61 | @files = grep { $_->is_file() } $path->children; | ||
| 62 | } | ||
| 63 | if ($path->is_file) { | ||
| 64 | push @files, $path; | ||
| 65 | } | ||
| 66 | } else { | ||
| 67 | say "you should use at least a file or directory!"; | ||
| 68 | exit; | ||
| 69 | } | ||
| 70 | |||
| 71 | my $pronom = File::FormatIdentification::Pronom->new( | ||
| 72 | "droid_signature_filename" => $pronomfile | ||
| 73 | ); | ||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | foreach my $binaryfile ( @files ) { | ||
| 78 | map_file my $filestream, $binaryfile, "<"; | ||
| 79 | advise( $filestream, 'random' ); | ||
| 80 | say "checking $binaryfile"; | ||
| 81 | foreach my $internalid ( $pronom->get_all_internal_ids() ) { | ||
| 82 | my @regexes = $pronom->get_regular_expressions_by_internal_id($internalid); | ||
| 83 | if (all {$filestream =~ m/$_/saa} @regexes ) { | ||
| 84 | my $sig = $pronom->get_signature_id_by_internal_id($internalid); | ||
| 85 | if (!defined $sig) {next;} | ||
| 86 | my $puid = $pronom->get_puid_by_signature_id($sig); | ||
| 87 | my $name = $pronom->get_name_by_signature_id($sig); | ||
| 88 | my $quality = $pronom->get_qualities_by_internal_id($internalid); | ||
| 89 | say "\tidentified as $name with PUID $puid (regex quality $quality)"; | ||
| 90 | last; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | ; | ||
| 95 | |||
| 96 | __END__ | ||
| 97 | |||
| 98 | =pod | ||
| 99 | |||
| 100 | =encoding UTF-8 | ||
| 101 | |||
| 102 | =head1 NAME | ||
| 103 | |||
| 104 | pronomidentify.pl | ||
| 105 | |||
| 106 | =head1 VERSION | ||
| 107 | |||
| 108 | version 0.06 | ||
| 109 | |||
| 110 | =head1 AUTHOR | ||
| 111 | |||
| 112 | Andreas Romeyke <pause@andreas-romeyke.de> | ||
| 113 | |||
| 114 | =head1 COPYRIGHT AND LICENSE | ||
| 115 | |||
| 116 | This software is copyright (c) 2018 by Andreas Romeyke. | ||
| 117 | |||
| 118 | This is free software; you can redistribute it and/or modify it under | ||
| 119 | the same terms as the Perl 5 programming language system itself. | ||
| 120 | |||
| 121 | =cut |