Fixed the way we handle creation dates in videos missing timezones
[videoscripts/.git] / merge_videos_by_day
index 193a7bdf32da50c262e3e686a0bab9df9f3621dd..3fdb42660bd16761e9802507a75557e47f81110a 100755 (executable)
@@ -10,7 +10,8 @@ use Time::localtime;
 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');
 $ctime_format = DateTime::Format::Strptime->new(pattern=>'%a %b %d %H:%M:%S %Y', time_zone => 'local', on_error => 'croak');
 
 # Early command line options processing
@@ -104,8 +105,12 @@ foreach $file (sort `$find_cmd`) {
 
     # Make a note of the month, year, and day this video was taken
     $creation_time = `$ffmpeg -i "$srcdir/$srcfile" 2>&1 | grep "creation_time" | head -n 1 | awk '{print \$3}'`;
+    $brands = `$ffmpeg -i "$srcdir/$srcfile" 2>&1 | grep "compatible_brands" | tail -n 1`; chomp($brands);
     if($creation_time) {
-       $date_taken = $ffmpeg_time_format->parse_datetime($creation_time);
+       $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);
+        }
     } else {
        # From the modification time of the file since we couldn't find it in the video file
        $date_modified = ctime(stat("$srcdir/$srcfile")->mtime);