How to use the osxphotos._constants._PHOTOS_4_VERSION function in osxphotos

To help you get started, we’ve selected a few osxphotos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RhetTbull / osxphotos / osxphotos / albuminfo.py View on Github external
def album_info(self):
        """ return list of albums (as AlbumInfo objects) contained in the folder """
        try:
            return self._albums
        except AttributeError:
            if self._db._db_version <= _PHOTOS_4_VERSION:
                albums = [
                    AlbumInfo(db=self._db, uuid=album)
                    for album, detail in self._db._dbalbum_details.items()
                    if not detail["intrash"]
                    and detail["albumSubclass"] == _PHOTOS_4_ALBUM_KIND
                    and detail["folderUuid"] == self._uuid
                ]
            else:
                albums = [
                    AlbumInfo(db=self._db, uuid=album)
                    for album, detail in self._db._dbalbum_details.items()
                    if not detail["intrash"]
                    and detail["kind"] == _PHOTOS_5_ALBUM_KIND
                    and detail["parentfolder"] == self._pk
                ]
            self._albums = albums
github RhetTbull / osxphotos / osxphotos / photosdb / _photosdb_process_exif.py View on Github external
def _process_exifinfo(self):
    """ load the exif data from the database 
        this is a PhotosDB method that should be imported in 
        the PhotosDB class definition in photosdb.py
    """
    if self._db_version <= _PHOTOS_4_VERSION:
        _process_exifinfo_4(self)
    else:
        _process_exifinfo_5(self)
github RhetTbull / osxphotos / osxphotos / photoinfo / photoinfo.py View on Github external
def path_edited(self):
        """ absolute path on disk of the edited picture """
        """ None if photo has not been edited """

        # TODO: break this code into a _path_edited_4 and _path_edited_5
        # version to simplify the big if/then; same for path_live_photo

        photopath = None

        if self._db._db_version <= _PHOTOS_4_VERSION:
            if self._info["hasAdjustments"]:
                edit_id = self._info["edit_resource_id"]
                if edit_id is not None:
                    library = self._db._library_path
                    folder_id, file_id = _get_resource_loc(edit_id)
                    # todo: is this always true or do we need to search file file_id under folder_id
                    # figure out what kind it is and build filename
                    filename = None
                    if self._info["type"] == _PHOTO_TYPE:
                        # it's a photo
                        filename = f"fullsizeoutput_{file_id}.jpeg"
                    elif self._info["type"] == _MOVIE_TYPE:
                        # it's a movie
                        filename = f"fullsizeoutput_{file_id}.mov"
                    else:
                        # don't know what it is!
github RhetTbull / osxphotos / osxphotos / photosdb / _photosdb_process_searchinfo.py View on Github external
def labels_normalized(self):
    """ return list of all normalized search info labels found in the library """
    if self._db_version <= _PHOTOS_4_VERSION:
        logging.warning(f"SearchInfo not implemented for this library version")
        return []

    return list(self._db_searchinfo_labels_normalized.keys())
github RhetTbull / osxphotos / osxphotos / __main__.py View on Github external
if photosdb.db_version > _PHOTOS_4_VERSION:
        shared_photos = [p for p in photos if p.shared]
        info["shared_photo_count"] = len(shared_photos)

        shared_movies = [p for p in movies if p.shared]
        info["shared_movie_count"] = len(shared_movies)

    keywords = photosdb.keywords_as_dict
    info["keywords_count"] = len(keywords)
    info["keywords"] = keywords

    albums = photosdb.albums_as_dict
    info["albums_count"] = len(albums)
    info["albums"] = albums

    if photosdb.db_version > _PHOTOS_4_VERSION:
        albums_shared = photosdb.albums_shared_as_dict
        info["shared_albums_count"] = len(albums_shared)
        info["shared_albums"] = albums_shared

    persons = photosdb.persons_as_dict

    info["persons_count"] = len(persons)
    info["persons"] = persons

    if cli_obj.json or json_:
        click.echo(json.dumps(info))
    else:
        click.echo(yaml.dump(info, sort_keys=False))
github RhetTbull / osxphotos / osxphotos / photosdb / photosdb.py View on Github external
def _get_album_uuids(self, shared=False):
        """ Return list of album UUIDs found in photos database
        
            Filters out albums in the trash and any special album types
        
        Args:
            shared: boolean; if True, returns shared albums, else normal albums
        
        Returns: list of album UUIDs 
        """
        if self._db_version <= _PHOTOS_4_VERSION:
            version4 = True
            if shared:
                logging.warning(
                    f"Shared albums not implemented for Photos library version {self._db_version}"
                )
                return []  # not implemented for _PHOTOS_4_VERSION
            else:
                album_kind = _PHOTOS_4_ALBUM_KIND
        else:
            version4 = False
            album_kind = _PHOTOS_5_SHARED_ALBUM_KIND if shared else _PHOTOS_5_ALBUM_KIND

        album_list = []
        # look through _dbalbum_details because _dbalbums_album won't have empty albums it
        for album, detail in self._dbalbum_details.items():
            if (
github RhetTbull / osxphotos / osxphotos / photosdb / photosdb.py View on Github external
# photos data is in Photos.sqlite
        # In either case, a temporary copy will be made if the DB is locked by Photos
        # or photosanalysisd
        self._dbfile = self._dbfile_actual = self._tmp_db = os.path.abspath(dbfile)

        # if database is exclusively locked, make a copy of it and use the copy
        # Photos maintains an exclusive lock on the database file while Photos is open
        # photoanalysisd sometimes maintains this lock even after Photos is closed
        # In those cases, make a temp copy of the file for sqlite3 to read
        if _db_is_locked(self._dbfile):
            self._tmp_db = self._copy_db_file(self._dbfile)

        self._db_version = self._get_db_version(self._tmp_db)

        # If Photos >= 5, actual data isn't in photos.db but in Photos.sqlite
        if int(self._db_version) > int(_PHOTOS_4_VERSION):
            dbpath = pathlib.Path(self._dbfile).parent
            dbfile = dbpath / "Photos.sqlite"
            if not _check_file_exists(dbfile):
                raise FileNotFoundError(f"dbfile {dbfile} does not exist", dbfile)
            else:
                self._dbfile_actual = self._tmp_db = dbfile
                # if database is exclusively locked, make a copy of it and use the copy
                if _db_is_locked(self._dbfile_actual):
                    self._tmp_db = self._copy_db_file(self._dbfile_actual)

            if _debug():
                logging.debug(
                    f"_dbfile = {self._dbfile}, _dbfile_actual = {self._dbfile_actual}"
                )

        library_path = os.path.dirname(os.path.abspath(dbfile))
github RhetTbull / osxphotos / osxphotos / photoinfo / _photoinfo_searchinfo.py View on Github external
def __init__(self, photo):
        """ photo: PhotoInfo object """

        if photo._db._db_version <= _PHOTOS_4_VERSION:
            raise NotImplementedError(
                f"search info not implemented for this database version"
            )

        self._photo = photo
        self.uuid = photo.uuid
        try:
            # get search info for this UUID
            # there might not be any search info data (e.g. if Photo was missing or photoanalysisd not run yet)
            self._db_searchinfo = photo._db._db_searchinfo_uuid[self.uuid]
        except KeyError:
            self._db_searchinfo = None