Fixed the way we handle creation dates in videos missing timezones
[videoscripts/.git] / make_mkv
index f0481165d5a0dde18e56d347cb8952ad0d2e921b..0ad7534b8fef4408f46960faa1691ec6e30bac20 100755 (executable)
--- a/make_mkv
+++ b/make_mkv
@@ -20,7 +20,8 @@ use DateTime::Format::Duration;
 use DateTime::Format::Strptime qw( );
 
 # Set our ffmpeg creation_time format
-$ffmpeg_time_format = DateTime::Format::Strptime->new(pattern=>'%Y-%m-%dT%H:%M:%S', time_zone => 'UTC', on_error => 'croak');
+$ffmpeg_time_format_utc = DateTime::Format::Strptime->new(pattern=>'%Y-%m-%dT%H:%M:%S', time_zone => 'UTC', on_error => 'croak');
+$ffmpeg_time_format_local = DateTime::Format::Strptime->new(pattern=>'%Y-%m-%dT%H:%M:%S', time_zone => 'local', on_error => 'croak');
 
 ####################################################################################################
 # Configuration parameters
@@ -72,8 +73,12 @@ foreach $video (split(/,/, $opt_i)) {
     if(! -r "$video") { die "-E- Unable to read input video file: $video\n"; }
     my $mtime_epoch = 0;
     my $creation_time = `$ffmpeg -i "$video" 2>&1 | grep "creation_time" | head -n 1 | awk '{print \$3}'`;
+    my $brands = `$ffmpeg -i "$video" 2>&1 | grep "compatible_brands" | tail -n 1`; chomp($brands);
     if($creation_time) {
-       my $date_taken = $ffmpeg_time_format->parse_datetime($creation_time);
+       my $date_taken = $ffmpeg_time_format_utc->parse_datetime($creation_time);
+       if ($brands && $brands =~ /$local_tz_brands/) {
+           $date_taken = $ffmpeg_time_format_local->parse_datetime($creation_time);
+       }
        $date_taken->set_time_zone('local');
        $mtime_epoch = $date_taken->epoch;
     } else {
@@ -291,8 +296,12 @@ foreach my $key (keys %merge_videos) {
        my $sec  = 0;
        my $mtime_epoch = 0;
        my $creation_time = `$ffmpeg -i "$video" 2>&1 | grep "creation_time" | head -n 1 | awk '{print \$3}'`;
-       if($creation_time) {
-           my $date_taken = $ffmpeg_time_format->parse_datetime($creation_time);
+       my $brands = `$ffmpeg -i "$video" 2>&1 | grep "compatible_brands" | tail -n 1`; chomp($brands);
+       if($creation_time) {
+            my $date_taken = $ffmpeg_time_format_utc->parse_datetime($creation_time);
+            if ($brands && $brands =~ /$local_tz_brands/) {
+                $date_taken = $ffmpeg_time_format_local->parse_datetime($creation_time);
+            }
            $date_taken->set_time_zone('local');
            $mtime_epoch = $date_taken->epoch;
        } else {