File: print-metadata.pl

package info (click to toggle)
compass-blueprint-plugin 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 460 kB
  • ctags: 9
  • sloc: ruby: 99; makefile: 46; perl: 43
file content (67 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/perl

# Copyright © 2014 Jonas Smedegaard <dr@jones.dk>
# Description: Extract copyright/licensing metadata from binary files
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;
use IPC::System::Simple;
use autodie qw(:all);
use feature 'say';
use Regexp::Assemble;
use Image::ExifTool qw(:Public);

BEGIN { $Image::ExifTool::configFile = '' }

my $exifTool = new Image::ExifTool;

my $dispatch = {
	'.*\.(png|jpg|jpeg|gif|icc)' => sub {
		my ( $infile, $outfile ) = @_;
		my $info = $exifTool->ImageInfo($infile, '*Name*', '*Copyright*');
		open(my $fh, ">>", $outfile);
		foreach (sort keys %$info) {
#			print $fh "$_: $$info{$_}\n";
			my $tagdesc = $exifTool->GetDescription($_);
			print $fh "$tagdesc: $$info{$_}\n";
		}
	},
	'.*\.(ttf|otf)' => sub {
		my ( $infile, $outfile ) = @_;
		system 'sh', '-c',
			"otfinfo -i '$infile' | egrep 'Copyright|Licens' > '$outfile'";
	},
};

my $re = Regexp::Assemble->new( track => 1 )->add( keys %$dispatch );

while( <> ) {
	chomp;
	if( $re->match($_) ) {
		my $infile = $re->mvar(0);
		my $outfile = "$infile.metadata_dump";
		if ( -e $outfile ) {
			say STDERR "ERROR: dumpfile exist: $outfile";
			say STDERR "       remove or put aside and try again";
			exit 1;
		}
		$dispatch->{ $re->matched }( $infile, $outfile );
	}
	else {
		last if /q/;
		print "\tignored\n";
	}
}