Daanoz / ha-google-photos

Home Assistant Google Photos integration
MIT License
87 stars 7 forks source link

Support Shared Albums #25

Closed arcsur closed 1 year ago

arcsur commented 1 year ago

Support for shared albums and a bit better error handling (account with no albums)

        def get_albums() -> List[Album]:
            album_list = []
            service: PhotosLibraryService = get_photoslibrary()

            albums = service.albums()  # pylint: disable=no-member
            fields = "albums(id,title,mediaItemsCount),nextPageToken"
            request = albums.list(pageSize=50, fields=fields)
            while request is not None:
                result = request.execute()
                album_list = album_list + result.get("albums", [])
                request = albums.list_next(request, result)

            sharedAlbums = service.sharedAlbums()  # pylint: disable=no-member
            fields = "sharedAlbums(id,title,mediaItemsCount),nextPageToken"
            request = sharedAlbums.list(pageSize=50, fields=fields)
            while request is not None:
                result = request.execute()
                album_list = album_list + result.get("sharedAlbums", [])
                request = sharedAlbums.list_next(request, result)
            return list(filter(lambda a: ("id" in a and "title" in a), album_list))

        albums = await self.hass.async_add_executor_job(get_albums)
        album_selection = dict({CONF_ALBUM_ID_FAVORITES: "Favorites"})
        for album in albums:
            album_selection[album.get("id")] = "{0} ({1} items)".format(
                album.get("title"), album.get("mediaItemsCount", "?")
            )
Daanoz commented 1 year ago

Looks good, feel free to create a PR with the changes. Otherwise I'll see if I can pick it up a bit later.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Daanoz commented 1 year ago

Added your feature as part of #30