I know I am missing something easy but I am new to Perl so I am not having any luck figuring this out so am hoping someone will point me in the right direction. When the tag field name EpisodeGlobalUniqueID is read it returns SCALAR(0x381b6bc). But I have not been able to figure out how to get it to return the actual string value. If you run exiftool.pl from the command line you have to specify the -b command to get it to return the correct information how do you do the same thing in Perl?
#!/usr/bin/perl -w
use Image::ExifTool::Quicktime qw(:Public);
use XML::Writer;
use IO::File;
### [[ http://www.exiftool.org/ExifTool.html ]] ###
while( glob('*.mp4') ) {
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo( $_ );
my $tagEGUID = EpisodeGlobalUniqueID;
my $tagAlbum = Album;
my $tagTitle = Title;
my $tagRating = Rating;
my $tagDescription = LongDescription;
my $tagAirDate = CreateDate;
my $tagDuration = Duration;
my $tagGenre = Genre;
my $tagArtist = Artist;
my $tagYear = Year;
my $val0 = $exifTool->GetValue($tagEGUID);
my $val1 = $exifTool->GetValue($tagAlbum, 'PrintConv');
my $val2 = $exifTool->GetValue($tagTitle, 'PrintConv');
my $val3 = $exifTool->GetValue($tagRating, 'PrintConv');
my $val4 = $exifTool->GetValue($tagDescription, 'ValueConv');
my $val5 = substr($exifTool->GetValue($tagAirDate, 'PrintConv'),0,10);
#replace : with -
$val5 =~ s/\:/-/g;
my $val6 = $exifTool->GetValue($tagDuration, 'PrintConv');
my $val7 = $exifTool->GetValue($tagGenre, 'PrintConv');
my $val8 = $exifTool->GetValue($tagArtist, 'PrintConv');
my $val9 = substr($exifTool->GetValue($tagYear, 'PrintConv'),0,4);
#Create XML File
my $output = new IO::File(">$val1.se$val2.xml");
my $writer = new XML::Writer(NEWLINES => 0, OUTPUT => $output);
$writer->xmlDecl("UTF-8");
$writer->startTag("Episodedetails");
$writer->startTag("title");
$writer->characters($val2);
$writer->endTag("title");
$writer->startTag("rating");
$writer->characters($val3);
$writer->endTag("rating");
$writer->startTag("season");
$writer->characters($val0);
$writer->endTag("season");
$writer->startTag("episode");
$writer->characters($val0);
$writer->endTag("episode");
$writer->startTag("plot");
$writer->characters($val4);
$writer->endTag("plot");
$writer->startTag("aired");
$writer->characters($val5);
$writer->endTag("aired");
$writer->startTag("runtime");
$writer->characters($val6);
$writer->endTag("runtime");
$writer->startTag("genre");
$writer->characters($val7);
$writer->endTag("genre");
$writer->startTag("studio");
$writer->characters($val8);
$writer->endTag("studio");
$writer->startTag("year");
$writer->characters($val9);
$writer->endTag("year");
$writer->endTag("Episodedetails");
$writer->end();
$output->close();
#Change the xml extension to nfo by renaming for xbmc import
foreach my $file (glob "*.xml"){
my $newfile = $file;
$newfile =~ s/\.xml$/.nfo/;
if (-e $newfile) {
warn "can't rename $file to $newfile: $newfile exists\n";
} elsif (rename $file, $newfile) {
## success, do nothing
} else {
warn "rename $file to $newfile failed: $!\n";
}}
}
This is what you need to do:
$val = $$val if ref $val eq 'SCALAR';
I don't have a sample QuickTime movie with this tag. Perhaps I should add a conversion to convert this to hex digits. It would be useful if you could post the exiftool -v3 output for one of these files.
- Phil
Thanks a lot for the help. The output of one of the files is attached.
Thanks for the output. The data in this case is indeed a text string, so converting it to hexadecimal doesn't make sense. I would say that the Flags are written incorrectly for this tag, since Flags=0x00 indicates byte data. If the Flags were 0x01, this would indicate string data (encoded in UTF-8), and exiftool would not treat this as binary data.
But since I can't find any documentation that specifies that the EpisodeGlobalUniqueID should be a string, I can't assume this will be true in all cases. So you are stuck de-referencing this tag at least for now.
- Phil