Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
fix bug where Photos/ folder were moved to the Albums/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYakobo committed May 3, 2023
1 parent 81745de commit f9916d1
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions fix_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,20 @@ def process_photos(rootdir):

run_mattwilson1024_google_photos_exif(albumdir, outdir, errdir)

def _restructure_if_needed(globstr, target_dir):
def _restructure_if_needed(folders, target_dir):
if os.path.exists(target_dir) and len(glob(f"{target_dir}/*")) > 0:
p(f"{target_dir} exists and is non-empty, assuming no further restructuring is needed")
return

os.makedirs(target_dir, exist_ok=True)

albums = glob(globstr)
if len(albums) == 0:
p(f"Warning: {globstr} didn't match anything")
if len(folders) == 0:
p(f"Warning: no folders were moved to {target_dir}")

for album in albums:
shutil.move(album, target_dir)
for folder in folders:
shutil.move(folder, target_dir)

p(f"Restructured {len(albums)} folders")
p(f"Restructured {len(folder)} folders")


def restructure_folders_if_needed(rootdir):
Expand All @@ -97,19 +96,23 @@ def restructure_folders_if_needed(rootdir):
# $rootdir/Albums/My Album 2
# $rootdir/Photos/Photos from 2008

photos_dir = f"{rootdir}/Photos/"

# move the "Photos from $YEAR" directories to Photos/
_restructure_if_needed(f"{rootdir}/Photos from */", f"{rootdir}/Photos")
_restructure_if_needed(glob(f"{rootdir}/Photos from */"), photos_dir)

# move everything else to Albums/, so we end up with two top-level folders
everything_except_photos_dir = set(glob(f"{rootdir}/*/")) - set([photos_dir])

# move the other directories to Albums/
_restructure_if_needed(f"{rootdir}/*/", f"{rootdir}/Albums")
_restructure_if_needed(everything_except_photos_dir, f"{rootdir}/Albums")


def main(rootdir):
# at least in my takeout, the Takeout folder contains a subfolder
# Takeout/Google Foto
# rootdir refers to that subfolder

rootdir = glob(f"{rootdir}/Google*/")[0]
rootdir = glob(f"{rootdir}/Google*/")[0].rstrip('/')
restructure_folders_if_needed(rootdir)

process_albums(rootdir)
Expand Down

0 comments on commit f9916d1

Please sign in to comment.