GooglePhotosTakeoutHelper icon indicating copy to clipboard operation
GooglePhotosTakeoutHelper copied to clipboard

Some MVIMG files are not organized correctly with the --divide-to-dates flag

Open jacobastern opened this issue 3 years ago • 0 comments

For me, some MVIMG.MP4 files were not placed in the correct folder with the --divide-to-dates flag. It seems that the program was not able to detect the dates correctly on the MP4 files. I wrote a short Python script to post-process these after running GooglePhotosTakeoutHelper. It reads in all files in a directory (I used the directory containing the recently modified files, which corresponds to the current year and month), and for .MP4 files with the 'creation_time' tag, it extracts the date and month, then moves those files to the folder year/month, just like all other files processed by the program. Unfortunately it depends on having ffmpeg installed, which is kind of annoying, but hopefully this is helpful to others.

import ffmpeg
import sys
import os
from datetime import datetime as dt

if __name__ == '__main__':
    base_dir = '/files/photos_proc'
    base_path = os.path.join(base_dir, '2022/01')
    for filename in os.listdir(base_path):
        orig_path = os.path.join(base_path, filename)
        # uses ffprobe command to extract all possible metadata from the media file
        metadata = ffmpeg.probe(orig_path)["streams"]
        try:
            datetime = metadata[0]['tags']['creation_time']
        except:
            print(orig_path)
            continue
        datetime = dt.strptime(datetime, "%Y-%m-%dT%H:%M:%S.%fZ")
        year, month = datetime.year, datetime.month
        new_path = os.path.join(base_dir, str(year), str(month).zfill(2), filename)
        os.makedirs(os.path.dirname(new_path), exist_ok=True)
        os.rename(orig_path, new_path)

jacobastern avatar Jan 20 '22 23:01 jacobastern