googlephotos

package
v0.0.0-...-a508f9c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeAcceptedPage = `` /* 438-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func GetUnmarshalJSON

func GetUnmarshalJSON(c *http.Client, url string, target interface{}) error

GetUnmarshalJSON gets a JSON response from url and unmarshals into target

func Login

func Login(consumerKey string, consumerSecret string) (*oauth2.Token, error)

Login does the OAuth2 login flow to google photos, resulting in Access tokens

func PostUnmarshalJSON

func PostUnmarshalJSON(c *http.Client, url string, reqBody string, target interface{}) error

Types

type Album

type Album struct {
	Id                    string           `json:"id"`
	Title                 string           `json:"title"`
	ProductUrl            string           `json:"productUrl"`
	IsWriteable           bool             `json:"isWriteable"`
	MediaItemsCount       MaybeQuotedInt64 `json:"mediaItemsCount"`
	CoverPhotoBaseUrl     string           `json:"coverPhotoBaseUrl"`
	CoverPhotoMediaItemId string           `json:"coverPhotoMediaItemId"`
}

type CachedMediaItem

type CachedMediaItem struct {
	CacheId     int64
	Sha256      string
	Md5         string
	LastUpdated time.Time
	LastUsed    time.Time
	MediaItem   *MediaItem
}

type Client

type Client interface {
	ListAlbums() ([]*Album, error)
	ListSharedAlbums() ([]*Album, error)
	ListMediaItemsForAlbumId(albumId string, nextPageToken string) (*SearchMediaItemsResponse, error)
	UpdateCacheForAlbumId(albumId string, nextPageToken string, cb UpdateCacheCallback) (*UpdateCacheResult, error)
}

func NewClient

func NewClient(
	consumerKey string,
	consumerSecret string,
	ctx context.Context,
	t *oauth2.Token,
	c cache.Cache,
	reg prometheus.Registerer,
) Client

type CodeCatcher

type CodeCatcher struct {
	Server     http.Server
	CatcherURL string
	State      string
	Codes      chan string
	Errors     chan error
}

type GooglephotosAuth

type GooglephotosAuth struct {
	Access oauth2.Token `json:"access,omitempty"`
}

type MaybeQuotedInt64

type MaybeQuotedInt64 int64

The Google Photos API sometimes returns ints wrapped in quotes.

{
	  mediaItemsCount: "6"
}

Go's default JSON parser will only allow this as the string "6". Define a new optionally-quoted int type, where the custom unmarshaller will pull off one pair of quotes, if present.

func (MaybeQuotedInt64) MarshalJSON

func (i MaybeQuotedInt64) MarshalJSON() ([]byte, error)

func (*MaybeQuotedInt64) UnmarshalJSON

func (i *MaybeQuotedInt64) UnmarshalJSON(data []byte) error

type MediaItem

type MediaItem struct {
	Id            string        `json:"id"`
	Description   string        `json:"description"`
	ProductUrl    string        `json:"productUrl"`
	BaseUrl       string        `json:"baseUrl"`
	MimeType      string        `json:"mimeType"`
	Filename      string        `json:"filename"`
	MediaMetadata MediaMetadata `json:"mediaMetadata"`
}

type MediaMetadata

type MediaMetadata struct {
	CreationTime string           `json:"creationTime"`
	Width        MaybeQuotedInt64 `json:"width"`
	Height       MaybeQuotedInt64 `json:"height"`

	// Either Photo or Video will be present
	Photo *PhotoMediaMetadata `json:"photo"`
	Video *VideoMediaMetadata `json:"video"`
}

type PhotoMediaMetadata

type PhotoMediaMetadata struct {
	CameraMake      string           `json:"cameraMake"`
	CameraModel     string           `json:"cameraModel"`
	FocalLength     float64          `json:"focalLength"`
	ApertureFNumber float64          `json:"apertureFNumber"`
	IsoEquivalent   MaybeQuotedInt64 `json:"isoEquivalent"`
	ExposureTime    string           `json:"exposureTime"`
}

type SearchMediaItemsResponse

type SearchMediaItemsResponse struct {
	MediaItems    []*MediaItem `json:"mediaItems"`
	NextPageToken string       `json:"nextPageToken"`
}

type UpdateCacheCallback

type UpdateCacheCallback func(*CachedMediaItem)

type UpdateCacheResult

type UpdateCacheResult struct {
	CachedMediaItems []*CachedMediaItem
	NextPageToken    string
}

type VideoMediaMetadata

type VideoMediaMetadata struct {
	CameraMake  string  `json:"cameraMake"`
	CameraModel string  `json:"cameraModel"`
	Fps         float64 `json:"fps"`
	Status      string  `json:"status"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL