source: main/trunk/greenstone2/perllib/cpan/Image/ExifTool/Vorbis.pm

Last change on this file was 34921, checked in by anupama, 3 years ago

Committing the improvements to EmbeddedMetaPlugin's processing of Keywords vs other metadata fields. Keywords were literally stored as arrays of words rather than phrases in PDFs (at least in Diego's sample PDF), whereas other meta fields like Subjects and Creators stored them as arrays of phrases. To get both to work, Kathy updated EXIF to a newer version, to retrieve the actual EXIF values stored in the PDF. And Kathy and Dr Bainbridge came up with a new option that I added called apply_join_before_split_to_metafields that's a regex which can list the metadata fields to apply the join_before_split to and whcih previously always got applied to all metadata fields. Now it's applied to any *Keywords metafields by default, as that's the metafield we have experience of that behaves differently to the others, as it stores by word instead of phrases. Tested on Diego's sample PDF. Diego has double-checked it to works on his sample PDF too, setting the split char to ; and turning on the join_before_split and leaving apply_join_before_split_to_metafields at its default of .*Keywords. File changes are strings.properties for the tooltip, the plugin introducing the option and working with it and Kathy's EXIF updates affecting cpan/File and cpan/Image.

File size: 8.1 KB
Line 
1#------------------------------------------------------------------------------
2# File: Vorbis.pm
3#
4# Description: Read Ogg Vorbis audio meta information
5#
6# Revisions: 2006/11/10 - P. Harvey Created
7# 2011/07/12 - PH Moved Ogg to a separate module and added Theora
8#
9# References: 1) http://www.xiph.org/vorbis/doc/
10# 2) http://flac.sourceforge.net/ogg_mapping.html
11# 3) http://www.theora.org/doc/Theora.pdf
12#------------------------------------------------------------------------------
13
14package Image::ExifTool::Vorbis;
15
16use strict;
17use vars qw($VERSION);
18use Image::ExifTool qw(:DataAccess :Utils);
19
20$VERSION = '1.08';
21
22sub ProcessComments($$$);
23
24# Vorbis header types
25%Image::ExifTool::Vorbis::Main = (
26 NOTES => q{
27 Information extracted from Ogg Vorbis files. See
28 L<http://www.xiph.org/vorbis/doc/> for the Vorbis specification.
29 },
30 1 => {
31 Name => 'Identification',
32 SubDirectory => { TagTable => 'Image::ExifTool::Vorbis::Identification' },
33 },
34 3 => {
35 Name => 'Comments',
36 SubDirectory => { TagTable => 'Image::ExifTool::Vorbis::Comments' },
37 },
38);
39
40%Image::ExifTool::Vorbis::Identification = (
41 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
42 GROUPS => { 2 => 'Audio' },
43 0 => {
44 Name => 'VorbisVersion',
45 Format => 'int32u',
46 },
47 4 => 'AudioChannels',
48 5 => {
49 Name => 'SampleRate',
50 Format => 'int32u',
51 },
52 9 => {
53 Name => 'MaximumBitrate',
54 Format => 'int32u',
55 RawConv => '$val || undef',
56 PrintConv => 'ConvertBitrate($val)',
57 },
58 13 => {
59 Name => 'NominalBitrate',
60 Format => 'int32u',
61 RawConv => '$val || undef',
62 PrintConv => 'ConvertBitrate($val)',
63 },
64 17 => {
65 Name => 'MinimumBitrate',
66 Format => 'int32u',
67 RawConv => '$val || undef',
68 PrintConv => 'ConvertBitrate($val)',
69 },
70);
71
72%Image::ExifTool::Vorbis::Comments = (
73 PROCESS_PROC => \&ProcessComments,
74 GROUPS => { 2 => 'Audio' },
75 NOTES => q{
76 The tags below are only some common tags found in the Vorbis comments of Ogg
77 Vorbis and Ogg FLAC audio files, however ExifTool will extract values from
78 any tag found, even if not listed here.
79 },
80 vendor => { Notes => 'from comment header' },
81 TITLE => { Name => 'Title' },
82 VERSION => { Name => 'Version' },
83 ALBUM => { Name => 'Album' },
84 TRACKNUMBER=>{ Name => 'TrackNumber' },
85 ARTIST => { Name => 'Artist', Groups => { 2 => 'Author' }, List => 1 },
86 PERFORMER => { Name => 'Performer', Groups => { 2 => 'Author' }, List => 1 },
87 COPYRIGHT => { Name => 'Copyright', Groups => { 2 => 'Author' } },
88 LICENSE => { Name => 'License', Groups => { 2 => 'Author' } },
89 ORGANIZATION=>{Name => 'Organization', Groups => { 2 => 'Author' } },
90 DESCRIPTION=>{ Name => 'Description' },
91 GENRE => { Name => 'Genre' },
92 DATE => { Name => 'Date', Groups => { 2 => 'Time' } },
93 LOCATION => { Name => 'Location', Groups => { 2 => 'Location' } },
94 CONTACT => { Name => 'Contact', Groups => { 2 => 'Author' }, List => 1 },
95 ISRC => { Name => 'ISRCNumber' },
96 COVERARTMIME => { Name => 'CoverArtMIMEType' },
97 COVERART => {
98 Name => 'CoverArt',
99 Groups => { 2 => 'Preview' },
100 Notes => 'base64-encoded image',
101 ValueConv => q{
102 require Image::ExifTool::XMP;
103 Image::ExifTool::XMP::DecodeBase64($val);
104 },
105 },
106 REPLAYGAIN_TRACK_PEAK => { Name => 'ReplayGainTrackPeak' },
107 REPLAYGAIN_TRACK_GAIN => { Name => 'ReplayGainTrackGain' },
108 REPLAYGAIN_ALBUM_PEAK => { Name => 'ReplayGainAlbumPeak' },
109 REPLAYGAIN_ALBUM_GAIN => { Name => 'ReplayGainAlbumGain' },
110 # observed in "Xiph.Org libVorbis I 20020717" ogg:
111 ENCODED_USING => { Name => 'EncodedUsing' },
112 ENCODED_BY => { Name => 'EncodedBy' },
113 COMMENT => { Name => 'Comment' },
114 # in Theora documentation (ref 3)
115 DIRECTOR => { Name => 'Director' },
116 PRODUCER => { Name => 'Producer' },
117 COMPOSER => { Name => 'Composer' },
118 ACTOR => { Name => 'Actor' },
119 # Opus tags
120 ENCODER => { Name => 'Encoder' },
121 ENCODER_OPTIONS => { Name => 'EncoderOptions' },
122 METADATA_BLOCK_PICTURE => {
123 Name => 'Picture',
124 Binary => 1,
125 # ref https://wiki.xiph.org/VorbisComment#METADATA_BLOCK_PICTURE
126 RawConv => q{
127 require Image::ExifTool::XMP;
128 Image::ExifTool::XMP::DecodeBase64($val);
129 },
130 SubDirectory => {
131 TagTable => 'Image::ExifTool::FLAC::Picture',
132 ByteOrder => 'BigEndian',
133 },
134 },
135);
136
137# Vorbis composite tags
138%Image::ExifTool::Vorbis::Composite = (
139 Duration => {
140 Require => {
141 0 => 'Vorbis:NominalBitrate',
142 1 => 'FileSize',
143 },
144 RawConv => '$val[0] ? $val[1] * 8 / $val[0] : undef',
145 PrintConv => 'ConvertDuration($val) . " (approx)"', # (only approximate)
146 },
147);
148
149# add our composite tags
150Image::ExifTool::AddCompositeTags('Image::ExifTool::Vorbis');
151
152
153#------------------------------------------------------------------------------
154# Process Vorbis Comments
155# Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
156# Returns: 1 on success, otherwise returns 0 and sets a Warning
157sub ProcessComments($$$)
158{
159 my ($et, $dirInfo, $tagTablePtr) = @_;
160 my $dataPt = $$dirInfo{DataPt};
161 my $dataPos = $$dirInfo{DataPos};
162 my $pos = $$dirInfo{DirStart} || 0;
163 my $end = $$dirInfo{DirLen} ? $pos + $$dirInfo{DirLen} : length $$dataPt;
164 my ($num, $index);
165
166 SetByteOrder('II');
167 for (;;) {
168 last if $pos + 4 > $end;
169 my $len = Get32u($dataPt, $pos);
170 last if $pos + 4 + $len > $end;
171 my $start = $pos + 4;
172 my $buff = substr($$dataPt, $start, $len);
173 $pos = $start + $len;
174 my ($tag, $val);
175 if (defined $num) {
176 $buff =~ /(.*?)=(.*)/s or last;
177 ($tag, $val) = (uc $1, $2);
178 # Vorbis tag ID's are all capitals, so they may conflict with our internal tags
179 # --> protect against this by adding a trailing underline if necessary
180 $tag .= '_' if $Image::ExifTool::specialTags{$tag};
181 } else {
182 $tag = 'vendor';
183 $val = $buff;
184 $num = ($pos + 4 < $end) ? Get32u($dataPt, $pos) : 0;
185 $et->VPrint(0, " + [Vorbis comments with $num entries]\n");
186 $pos += 4;
187 }
188 # add tag to table unless it exists already
189 unless ($$tagTablePtr{$tag}) {
190 my $name = ucfirst(lc($tag));
191 # remove invalid characters in tag name and capitalize following letters
192 $name =~ s/[^\w-]+(.?)/\U$1/sg;
193 $name =~ s/([a-z0-9])_([a-z])/$1\U$2/g;
194 $et->VPrint(0, " | [adding $tag]\n");
195 AddTagToTable($tagTablePtr, $tag, { Name => $name });
196 }
197 $et->HandleTag($tagTablePtr, $tag, $et->Decode($val, 'UTF8'),
198 Index => $index,
199 DataPt => $dataPt,
200 DataPos => $dataPos,
201 Start => $start,
202 Size => $len,
203 );
204 # all done if this was our last tag
205 $num-- or return 1;
206 $index = (defined $index) ? $index + 1 : 0;
207 }
208 $et->Warn('Format error in Vorbis comments');
209 return 0;
210}
211
2121; # end
213
214__END__
215
216=head1 NAME
217
218Image::ExifTool::Vorbis - Read Ogg Vorbis audio meta information
219
220=head1 SYNOPSIS
221
222This module is used by Image::ExifTool
223
224=head1 DESCRIPTION
225
226This module contains definitions required by Image::ExifTool to extract meta
227information from Ogg Vorbis audio headers.
228
229=head1 AUTHOR
230
231Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
232
233This library is free software; you can redistribute it and/or modify it
234under the same terms as Perl itself.
235
236=head1 REFERENCES
237
238=over 4
239
240=item L<http://www.xiph.org/vorbis/doc/>
241
242=item L<http://flac.sourceforge.net/ogg_mapping.html>
243
244=item L<http://www.theora.org/doc/Theora.pdf>
245
246=back
247
248=head1 SEE ALSO
249
250L<Image::ExifTool::TagNames/Vorbis Tags>,
251L<Image::ExifTool::TagNames/Ogg Tags>,
252L<Image::ExifTool(3pm)|Image::ExifTool>
253
254=cut
255
Note: See TracBrowser for help on using the repository browser.