def main():

    gphoto.init()

    do_raw = True
    do_jpg = True

    library_type = None
    if len(sys.argv) > 1:
        if sys.argv[1] == "raw":
            do_jpg = False
        elif sys.argv[1] == "jpg":
            do_raw = False

    start_time = datetime.now()
    print(f"Start Time: {start_time}")

    if do_raw:
        # LocalLibraryMetadata.cache_library_metadata("P:\\pics\\2014\\2014-02-14 Valentine's Day Celeberation", 'raw')
        LocalLibraryMetadata.cache_library_metadata("P:\\pics", 'raw')
        LocalLibraryMetadata.save_library_metadata('raw')
    if do_jpg:
        LocalLibraryMetadata.cache_library_metadata("d:\\picsHres", 'jpg')
        LocalLibraryMetadata.save_library_metadata('jpg')

    elapsed_time = datetime.now() - start_time
    print(f"Total Time: {elapsed_time}")
def main():
    gphoto.init()
    LocalLibrary.cache_library("p:\\pics", 'raw')
    LocalLibrary.save_library('raw')

    LocalLibrary.cache_library("d:\\picsHres", 'jpg')
    LocalLibrary.save_library('jpg')
Example #3
0
def main():
    gphoto.init()

    service = GoogleService.service()
    if not service:
        logging.error(
            "GoogleAlbums.cache_albums: GoogleService.service() is not initialized"
        )
        return

    # Album name used
    albumName = "2060 API Album"

    imageid01 = 'ALE2QTBp8OkubJCEMGMr4GTsThO3qMLWTit1_5DRyyQOD4IBUu5LJ8qFGwEb8AFy2yrlNlFTgtKt'
    imageid02 = 'ALE2QTBGNjlDhWc7Y3gwpGtIKvba849RolzOtcQ8xFgz1dh8J-Jmwa8vX80cYAGxJDjUu9m58gUu'
    image_ids = [imageid01, imageid02]

    # Create album
    request_body = {'album': {'title': albumName}}
    response_google_album = service.albums().create(
        body=request_body).execute()
    album_id = response_google_album['id']

    request_body = {'mediaItemIds': image_ids}
    response = service.albums().batchAddMediaItems(
        albumId=album_id, body=request_body).execute()

    print(response)
def main():
    """
    Test code to se if image caption can updated if the images
    was uploaded using Google Photos UI.

    This is not working at this time.  You will see the following
    error:

        "code": 403,
        "message: "Request had insufficient authentication scopes"
        "status": "PERMISSION_DENIED"
    """
    gphoto.init()

    cache = GoogleImages.load_images()
    filenames = cache['filenames']

    image_name = "20050101_000436_OSWA_D70.jpg"
    image_idx = filenames[image_name]
    image = cache['list'][image_idx]
    
    # "ALE2QTAJEnDlApTBWwq-U5n0pg6ulXVp5wdAkqwXVj0knHwrKGcyqFoCt5x5CzeXd_1FUD4VEvrkAZzGaqOxiJIcrsuZmHgJYw"
    image_id = image['id']

    request_body = {
        "description": f"{datetime.now()}: new-media-item-description"
    }

    service = GoogleService.service()
    response = service.mediaItems().patch(
        id=image_id,
        body=request_body
    ).execute()

    print(response)
def main():

    gphoto.init()

    LocalLibraryMetadata.load_library_metadata('raw')
    cache = LocalLibraryMetadata.cache_raw()

    for image_id, image in cache.items():
        desc = image.get('Description')
        title = image.get('Title')

        # filename = os.path.basename(image_id)
        # if filename.startswith("PFILM"):
        #     continue

        # ext = image.get('FileTypeExtension')
        # if ext and ext == 'mov':
        #     continue

        if '2009-10-31 Haloween party at Gambhir' in image_id:
            continue

        if "2011-07-04 Amitabh's 50th Birthday Post Celeberation" in image_id:
            continue

        if "2017 04 16 Vocal Performance M.A." in image_id:
            continue

        if "2009-08-06 Italy Trip" in image_id:
            continue

        if desc is not None and title is not None and desc != title:
            print(image_id)
            print(f"     desc='{desc}'")
            print(f"    title='{title}'")
Example #6
0
    def upload_album_names(album_names):

        gphoto.init()
        service = GoogleService.service()

        LocalLibrary.load_library('jpg')

        for album_name in album_names:
            Uploader.upload_album_name(service, album_name)
Example #7
0
def main():

    if len(sys.argv) < 2:
        print("[ERROR]: Album index not specified")
        sys.exit()

    gphoto.init()
    GoogleAlbums.load_albums()
    cache = GoogleAlbums.cache()
    album_list = cache['list']

    idx = int(sys.argv[1])
    album = album_list[idx]
    util.pprint(album)
def main():
    gphoto.init()

    # Load Local picsHres jpg Library
    LocalLibrary.load_library('jpg')
    local_cache = LocalLibrary.cache_jpg()
    local_albums = local_cache.get('albums')
    local_album_paths = local_cache.get('album_paths')
    local_album_names = local_cache.get('album_names')
    local_images = local_cache.get('images')
    local_image_ids = local_cache.get('image_ids')

    # temp_result is a dict holding image name as key
    # and an array value of image paths
    temp_result = {}

    # Loop through each images, get their leaf names and see
    # if image part with this name already exists
    for local_image in local_images:

        # Add image name and path to the temp_result
        image_name = local_image.get('name')
        image_path = local_image.get('path')

        image_path_list = temp_result.get(image_name)
        if image_path_list is None:
            image_path_list = [image_path]
            temp_result[image_name] = image_path_list
        else:
            image_path_list.append(image_path)

    # Now remove entries for temp_result where there is only one image path
    result = {}
    found = False
    for image_name in temp_result:
        image_path_list = temp_result.get(image_name)
        if len(image_path_list) > 1:
            found = True
            result[image_name] = image_path_list

    print(f"found duplicates = {found}")

    # Save to cache file also
    if found:
        gphoto.save_to_file(result, "find_duplicate_local_image_names.json")
Example #9
0
  def find():
    """
    This method builds the cache for local raw pics folder,
    traverses it and find image name duplicates
    """
    gphoto.init()
    LocalLibrary.cache_raw_library("p:\\pics")
    LocalLibrary.save_library('raw')

    # The dups dict holds
    #   key: image name
    #   list: list of image paths
    name_to_paths = {}

    # traverse the images list. For each image add its name
    cache = LocalLibrary.cache_raw()
    cache_images = cache['images']
    cache_image_ids = cache['image_ids']

    for image in cache_images:
      imagename = image['name']
      imagepath = image['path']

      if imagename not in name_to_paths:
        name_to_paths[imagename] = [imagepath]
      else:
        name_to_paths[imagename].append(imagepath)

    # review the dups where imagename is holding multiple image paths
    dups = []
    for imagename, imagelist in name_to_paths.items():
      if len(imagelist) > 1:
        dup = {
          'name': imagename,
          'paths': []
        }

        paths = dup['paths']
        for imagepath in imagelist:
          paths.append(imagepath)
        
        dups.append(dup)
    
    return dups
Example #10
0
def main():

    gphoto.init()

    if len(sys.argv) < 2:
        print("Album pattern not provided.")
        return

    album_path_filter_year = sys.argv[1]

    print("--------------------------------------------")
    print(f"filter: {album_path_filter_year}")
    print("--------------------------------------------")

    start_time = datetime.now()

    file_filter_include = None
    file_filter_exclude = None
    # file_filter_exclude = "PFILM"
    test_missing_date_shot = True
    test_bad_date_shot = True
    test_filename_FMT = True
    test_Tag_mismatch = True
    test_missing_caption = True
    test_unique_caption = True
    test_missing_caption_year = True
    test_missing_geotags = True

    with exiftool.ExifTool() as et:
        check_album_readiness(et, album_path_filter_year, file_filter_include,
                              file_filter_exclude, test_missing_date_shot,
                              test_bad_date_shot, test_filename_FMT,
                              test_Tag_mismatch, test_missing_caption,
                              test_unique_caption, test_missing_caption_year,
                              test_missing_geotags)

    elapsed_time = datetime.now() - start_time
    print(f"Total Time: {elapsed_time}")
def do_work(et, google_image_filter, album_folder_path, list_only):

    # Find folder album in the database
    LocalLibrary.load_library('raw')
    local_library_cache = LocalLibrary.cache_raw()
    images = local_library_cache['images']
    albums = local_library_cache['albums']
    album_paths = local_library_cache['album_paths']

    album_idx = album_paths[album_folder_path]
    album = albums[album_idx]
    local_album_path = album['path']

    print(f"[INFO]: Found album '{local_album_path}'")

    # Collect list of local album files
    local_files_results = []
    local_album_images = album['images']
    for image_idx in local_album_images:
        image = images[image_idx]
        image_name = image['name']
        image_path = image['path']
        local_files_results.append(image_path)

    sorted(local_files_results)
    util.pprint(local_files_results)
    print(f"[INFO] Local files count '{len(local_files_results)}'")

    # Collect a list of images from google photos
    # Each element in this list will be an object:
    #     {'path': 'image path', 'caption': 'images caption...'}
    google_images_results = []
    gphoto.init()
    GoogleImages.load_images()
    google_image_cache = GoogleImages.cache()
    google_images = google_image_cache['list']
    for google_image in google_images:
        image_name = google_image['filename']
        if image_name.find(google_image_filter) < 0:
            continue
        image_desc = google_image['description']

        google_images_results.append((image_name, image_desc))

    google_images_results = sorted(google_images_results,
                                   key=lambda record: record[0])
    util.pprint(google_images_results)
    print(f"[INFO] Google files count '{len(google_images_results)}'")

    # Perform basic validations
    # If counts are not the same then error out
    if len(local_files_results) != len(google_images_results):
        print(
            f"[ERROR]: Count mismatch local: '{len(local_files_results)}', google: '{len(google_images_results)}'.  Aborting"
        )

    # Now loop through the list of folder images, get its
    # equivalent caption from the corresponding google image
    if list_only:
        return

    for image_idx, local_image_path in enumerate(local_files_results):
        desc = google_images_results[image_idx][1]

        # Get image extension and identify it as an image or video
        image_name = os.path.basename(local_image_path)
        image_ext = ImageUtils.get_file_extension(image_name)
        is_video = ImageUtils.is_ext_video(image_ext)

        # Set the caption now
        ImageUtils.set_caption(et, local_image_path, desc, is_video)
Example #12
0
def main():
    gphoto.init()
    GoogleImages.download_images()
Example #13
0
def main():
    gphoto.init()

    # Load Google Library
    GoogleLibrary.load_library()
    google_cache = GoogleLibrary.cache()
    google_album_ids = google_cache['album_ids']
    google_album_titles = google_cache['album_titles']

    google_image_ids = google_cache['image_ids']
    google_image_filenames = google_cache['image_filenames']

    google_album_images = google_cache['album_images']
    google_image_albums = google_cache['image_albums']

    # Load Local picsHres jpg Library
    LocalLibrary.load_library('jpg')
    local_cache = LocalLibrary.cache_jpg()
    local_albums = local_cache.get('albums')
    local_album_paths = local_cache.get('album_paths')
    local_album_names = local_cache.get('album_names')
    local_images = local_cache.get('images')
    local_image_ids = local_cache.get('image_ids')
    local_image_names = local_cache.get('image_names')

    # Initialize the result
    missing_images_with_album_reason = "MISSING_IMAGES_WITH_ALBUM"
    missing_images_with_no_album_reason = "MISSING_IMAGES_WITH_NO_ALBUM"
    image_exist_locally_reason = "IMAGE_EXIST_LOCALLY"

    result_missing_images_with_album = {}
    result_missing_images_with_no_album = []
    result_image_exist_locally = []
    result = {
        missing_images_with_album_reason: result_missing_images_with_album,
        missing_images_with_no_album_reason: result_missing_images_with_no_album,
        image_exist_locally_reason: result_image_exist_locally
    }

    # Walk through each Google images that begins with PFILMmmm_nnn.jpg
    for google_image_id in google_image_ids:
        google_image = google_image_ids[google_image_id]

        # Ignore images not begining with "PFILM"
        image_name = google_image.get('filename')
        if image_name is not None and not image_name.startswith("PFILM"):
            continue

        # Check for image exist locally
        local_image_idx = local_image_names.get(image_name)
        if local_image_idx is not None:
            local_image = local_images[local_image_idx]
            result_image_exist_locally.append(local_image.get('path'))
            continue

        # We now know that the image is missing locally
        # No figure out if this images does not have an album parent
        google_albums_of_this_image = google_image_albums.get(google_image_id)
        if google_albums_of_this_image is not None:

            # Images does have parent albums
            # add first album to the result first if not already done
            google_album_idx = None
            for idx in google_albums_of_this_image:
                google_album_idx = idx
                break

            google_album = google_album[google_album_idx]
            google_album_id = google_album.get('id')
            result_album = result.get(google_album_id)

            # If album not in result then add the album
            missing_images_with_album = None
            if result_album is None:

                missing_images_with_album = []
                result_album = {
                    'id': google_album_id,
                    'title': google_album.get('title'),
                    'images': missing_images_with_album
                }
                result_missing_images_with_album[google_album_id] = result_album


            # Add missing image to parent album result
            missing_images_with_album.append({
                'id': google_image_id,
                'filename': image_name,
                'productUrl': google_image['productUrl']
            })

        # Google image is missing locally and has no parent album
        else:
            result_missing_images_with_no_album.append({
                    'id': google_image_id,
                    'filename': image_name,
                    'productUrl': google_image['productUrl']
                })

    # Save to cache file also
    gphoto.save_to_file(result, "can_PFILMs_be_deleted.json")
def main():
    gphoto.init()

    GoogleAlbums.load_albums()
    google_album_cache = GoogleAlbums.cache()
    google_albums = google_album_cache['list']

    GoogleImages.load_images()
    google_image_cache = GoogleImages.cache()
    google_images = google_image_cache['list']

    GoogleAlbumImages.load_album_images()
    google_album_image_cache = GoogleAlbumImages.cache()

    result = []

    # Loop through each google album
    for google_album in google_albums:

        google_album_id = google_album['id']

        album_images = None
        if google_album_id in google_album_image_cache:
            album_images = google_album_image_cache[google_album_id]

        count = 0
        not_mine_count = 0
        if album_images:
            count = len(album_images)

            for image_idx in album_images:

                google_image = google_images[image_idx]
                if 'mine' in google_image:
                    mine = google_image['mine']
                    if not mine:
                        not_mine_count += 1

        ownership = None
        if not_mine_count == 0:
            ownership = "All-Mine"
        elif not_mine_count == count:
            ownership = "None-Mine"
        else:
            ownership = f"{count - not_mine_count}" + " Partial"

        title = None
        if 'title' not in google_album:
            title = "[EMPTY]" + google_album_id
        else:
            title = google_album['title']

        album_result = {
            'title': title,
            'shared': google_album['shared'],
            'image_count': count,
            'ownership': ownership
        }

        result.append(album_result)

    # Save to cache file also
    gphoto.save_to_file(result, "google_albums_summary.json")
def main():
    gphoto.init()
    GoogleLibrary.download_library()
Example #16
0
import context; context.set_context()

import gphoto
import util
from gphoto.google_albums import GoogleAlbums
from gphoto.google_images import GoogleImages
from gphoto.google_album_images import GoogleAlbumImages

gphoto.init()

def do_work():
    albums_cache = GoogleAlbums.load_albums()
    images_cache = GoogleImages.load_images()
    album_images_cache = GoogleAlbumImages.load_album_images()

    album_ids = albums_cache['ids']
    album_titles = albums_cache['titles']

    image_ids = images_cache['ids']
    image_filenames = images_cache['filenames']

    album_images_dict = album_images_cache['album_images']
    image_albums_dict = album_images_cache['image_albums']

    result = {}

    for image_id, image_albums in image_albums_dict.items():
        image = image_ids[image_id]
        if len(image_albums) > 1:
            consider_image = False
            start_pattern = None