NicholasDawson / ArchiverForGooglePhotos

A tool to maintain an archive/mirror of your Google Photos library for backup purposes.
GNU General Public License v3.0
190 stars 30 forks source link

Feature: Add created date into media metadata after download #16

Open seantran6 opened 2 years ago

seantran6 commented 2 years ago

Hey, just recently installed the archiver. Works great in installing the photos in a pretty decent time as well. However after upon further examination, a lot of my photos dates are changed. I could be a complete beginner at this, so let me know if I need to do anything. Some of my recent videos are not dated back to 1969 and my photos from 2016 are dated as 2022. Thanks.

NicholasDawson commented 2 years ago

Okay, so the date that is on the photos when downloaded from Google is the date you uploaded them to Google Photos.

However, I do have existing functionality to add descriptive metadata to the photo.

I will take this as a feature request to embed the date the media was created/taken into the media item after download. My idea is that this will be the new default behavior.

Will keep you updated in this thread. It may be a while as I am busy will school work, but over my spring break, I will have some time.

Thank you for the feedback, it is greatly appreciated.

deanthing commented 1 year ago

Hey Nicholas, would you consider a pull request for this feature? This is a great tool and would like to be able to contribute.

NicholasDawson commented 1 year ago

Hey Nicholas, would you consider a pull request for this feature? This is a great tool and would like to be able to contribute.

Of course, I'd be happy to accept the PR.

Let me know if you want to work on something together, I've been too busy to add enhancements so this is a big help!

Andi7da commented 3 weeks ago

This caused quite a mess for me too. But your program is cool anyway :).

I can't program in Python, but I found a workaround that works for me. It's not that nice, I know, it results in long file names. But it's very easy to integrate.

So I inserted some code in gparch.py "def process_media_items" (about line 287, changes marked here with "AM"):

def process_media_items(self, media_items, save_directory, album_uuid=None):
    media = []
    for item in media_items:
        # Path where the media item will be saved to
        item_path = None

        # AM added two lines
        mm = item["mediaMetadata"]
        mmctime = mm["creationTime"].replace(":","-") + "_"

        # Select the media item from the database
        # -> if it doesn't exist then generate the item_path
        # -> if it already exists then just pull the item_path from the existing db entry
        item_db_entry = self.select_media_item(item["id"])
        if not item_db_entry:
            item["filename"] = sanitize(item["filename"])
            # AM changed, original: item_path = f'{save_directory}/{item["filename"]}'
            item_path = f'{save_directory}/{mmctime + item["filename"]}'

Oh, PS: If you change the code, the data has to be downloaded again completely. I therefore recommend deleting everything in the target directory except credentials.json and photoslibrary_token.pickle. Yes, also delete database.sqlite3... Or select first another directory for testing. And with a new version, this will be necessary again. Unless you integrate my code again...