Created
February 18, 2021 13:39
-
-
Save tetebueno/5800504133709c9844bcd1779019d390 to your computer and use it in GitHub Desktop.
Google Photos Takeout archive holds a JSON file with photo/video metadata, thing is that the naming for this JSON file is not always so obvious. This takes care of resolving the name with all the variants I found so far.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re as _re | |
import json as _json | |
JSON_EXTENSION = '.json' | |
def find_json_for_file(file: Path): | |
try: | |
if file.with_name(file.name + JSON_EXTENSION).is_file(): | |
# file.jpg -> file.jpg.json | |
the_json_path = file.with_name(file.name + JSON_EXTENSION) | |
elif file.with_name(file.name.replace(file.suffix, JSON_EXTENSION)).is_file(): | |
# file.jpg -> file.json | |
the_json_path = file.with_name(file.name.replace(file.suffix.lower(), JSON_EXTENSION)) | |
elif len(file.name) >= 47: | |
# fileee...eee.jpg -> fileee...eee..json | |
the_json_path = file.with_name(file.name[0:46] + JSON_EXTENSION) | |
elif bool(_re.search(r'^(.+)(\(\d+\))(\..+)$', file.name)): | |
weird_search = _re.search(r'^(.+)(\(\d+\))(\..+)$', file.name) | |
if file.with_name(weird_search.group(1) + JSON_EXTENSION).is_file(): | |
# file(1).jpg -> file.json | |
the_json_path = file.with_name(weird_search.group(1) + JSON_EXTENSION) | |
else: | |
# file(1).jpg -> file.jpg(1).json | |
the_json_path = file.with_name(weird_search.group(1) + weird_search.group(3) + weird_search.group(2) + JSON_EXTENSION) | |
#print('Using ' + the_json_path.name + ' for ' + file.name) | |
with open(the_json_path, 'r') as f: | |
json_dict = _json.load(f) | |
return json_dict | |
except: | |
raise FileNotFoundError(f'Couldn\'t find json for file: {file}') |
I never got the tutorial, but I somehow found a solution online and managed to make it work. Don’t remember where exactly tho. Keep researching and you should find it Sent from my iPhoneOn Nov 9, 2022, at 3:54 PM, HJ1q ***@***.***> wrote:Re: ***@***.*** commented on this ***@***.*** did you get that step by step instruction? I'm in the same situation you wear in a year ago. I would really appreciate any help anyone. @tetebueno—Reply to this email directly, view it on GitHub or unsubscribe.You are receiving this email because you were mentioned.Triage notifications on the go with GitHub Mobile for iOS or Android.
@HJ1q I ended up using a different python script. (https://pastebin.com/SkYwF0Jy)
should be something like, nameofprogram "folder to be scanned")
It should rename all your jason files to match the name of the image files.
then i used exiftool (https://exiftool.org/) to apply the jason metadata to the images.
(https://pastebin.com/5Wr7yzkh)
That's all if i remember correctly form a year ago.
Also, do not run this on your only copy of your take out. Make a backup and
try it on a smaller set of images, so you don't waste time on something that
didn't do what you thought it would do.
Please check this:
https://github.com/TheLastGimbus/GooglePhotosTakeoutHelper
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kyro-h did you get that step by step instruction? I'm in the same situation you wear in a year ago. I would really appreciate any help anyone. @tetebueno