picago

package module
v0.0.0-...-7cafae2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: Apache-2.0 Imports: 20 Imported by: 3

README

WARNING

As Google deprecated the Picasa API, and it won't work from 15 March 2019, I sunset this project.

ATM Google Drive is the only way I know to retrieve your photos. See Perkeep for an importer!

picago

Picago is a small Go library for downloading and uploading photos from Picasa Web.

Install

go install github.com/tgulacsi/picago/pica-dl

Permissions

You must obtain a client ID and secret from Google in order to call the APIs this project relies on.

  1. Go to https://console.developers.google.com/project and create a new project. You can name it whatever you want. You can also reuse an existing project if you have one.

  2. Click on the project, and under "APIs & auth" > "Consent screen", ensure you have "Product name" and "Email address" specified.

  3. Under "APIs and auth" > "Credentials" click "Create new client ID". Choose type "Installed application", then installed application type "Other".

Running

After getting a client ID and secret, you can run the example app as

pica-dl -id=11849328232-4q13l4hgr5mdt35lbe49l8banqg5e1mk.apps.googleusercontent.com -secret=Y0xf_rauB9MVTNYAI2MYIz2w -dir=/tmp/pica

This will download all photos from all albums under /tmp/pica. Each album and photo is accompanied with a .json file containing some metadata.

Documentation

Overview

Package picago contains functions for downloading albums and photos from Picasa Web. Implemented from scratch following https://developers.google.com/picasa-web/docs/2.0/developers_guide_protocol?hl=en .

Index

Constants

View Source
const PicasaScope = "https://picasaweb.google.com/data/"

OAuth2 scope, manage your Picasa account

Variables

View Source
var DebugDir = os.Getenv("PICAGO_DEBUG_DIR")
View Source
var Endpoint = oauth2.Endpoint{
	AuthURL:  "https://accounts.google.com/o/oauth2/auth",
	TokenURL: "https://accounts.google.com/o/oauth2/token",
}

Endpoint contains the URL of the picasa auth endpoints

View Source
var ErrCodeNeeded = errors.New("Authorization code is needed")

Functions

func Authorize

func Authorize(ID, secret string) error

Authorize authorizes using OAuth2 the ID and secret strings can be acquired from Google for the application https://developers.google.com/accounts/docs/OAuth2#basicsteps

func Config

func Config(id, secret string) *oauth2.Config

func DownloadPhoto

func DownloadPhoto(client *http.Client, url string) (io.ReadCloser, error)

DownloadPhoto returns an io.ReadCloser for reading the photo bytes

func NewAuthorizeHandler

func NewAuthorizeHandler(cfg *oauth2.Config, donech chan<- *oauth2.Token) http.HandlerFunc

NewAuthorizeHandler returns a http.HandlerFunc which will set the Token of the given oauth2.Transport and send a struct{} on the donech on success.

func NewClient

func NewClient(ctx context.Context, id, secret, code, tokenCacheFilename string, Log func(...interface{}) error) (*http.Client, error)

For redirect_uri, see https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi .

NewClient returns an authorized http.Client usable for requests.

Types

type Album

type Album struct {
	// ID is the stable identifier for an album.
	// e.g. "6041693388376552305"
	ID string

	// Name appears to be the Title, but with spaces removed. It
	// shows up in URLs but is not a stable
	// identifier. e.g. "BikingWithBlake"
	Name string

	// Title is the title of the album.
	// e.g. "Biking with Blake"
	Title string

	// AlbumType
	// e.g. "Blogger", "ProfilePhotos", "InstantUpload", or empty sring
	AlbumType string

	// Rights
	// e.g. "public", "protected", or "private"
	Rights string

	// Description is the Picasaweb "Description" field, and does
	// not appear available or shown in G+ Photos. It may be
	// contain newlines.
	Description string

	// Location is free-form location text. e.g. "San Bruno Mountain"
	Location string

	// URL is the main human-oriented (HTML) URL to the album.
	URL string

	// Published is the either the time the user actually created
	// and published the gallery or (in the case of Picasaweb at
	// least), the date that the user set on the gallery.  It will
	// be at day granularity, but the hour will be adjusted based
	// on whatever timezone the user is it. For instance, setting
	// July 21, 2014 while in California results in a time of
	// 2014-07-21T07:00:00.000Z since that was the UTC time at
	// which it became July 21st in US/Pacific on that day.
	Published time.Time

	// Updated is the server time any property of the gallery was
	// changed.  It appears to be at millisecond granularity.
	Updated time.Time

	AuthorName, AuthorURI string
}

An Album is a collection of Picasaweb or Google+ photos.

func GetAlbums

func GetAlbums(client *http.Client, userID string) ([]Album, error)

GetAlbums returns the list of albums of the given userID. If userID is empty, "default" is used.

type Atom

type Atom struct {
	ID           string    `xml:"id"`
	Name         string    `xml:"name"`
	Updated      time.Time `xml:"updated"`
	Title        string    `xml:"title"`
	Subtitle     string    `xml:"subtitle"`
	Icon         string    `xml:"icon"`
	Thumbnail    string    `xml:"http://schemas.google.com/photos/2007 thumbnail"`
	Author       Author    `xml:"author"`
	NumPhotos    int       `xml:"numphotos"`
	StartIndex   int       `xml:"startIndex"`
	TotalResults int       `xml:"totalResults"`
	ItemsPerPage int       `xml:"itemsPerPage"`
	Entries      []Entry   `xml:"entry"`
}

func ParseAtom

func ParseAtom(r io.Reader) (*Atom, error)

type Author

type Author struct {
	Name string `xml:"name"`
	URI  string `xml:"uri"`
}

type Entry

type Entry struct {
	ETag      string       `xml:"etag,attr"`
	EntryID   string       `xml:"http://www.w3.org/2005/Atom id"`
	ID        string       `xml:"http://schemas.google.com/photos/2007 id"`
	Published time.Time    `xml:"published"`
	Updated   time.Time    `xml:"updated"`
	Name      string       `xml:"http://schemas.google.com/photos/2007 name"`
	Title     string       `xml:"title"`
	Summary   string       `xml:"summary"`
	Rights    string       `xml:"rights"`
	AlbumType string       `xml:"albumType"`
	Links     []Link       `xml:"link"`
	Author    Author       `xml:"author"`
	Location  string       `xml:"http://schemas.google.com/photos/2007 location"`
	NumPhotos int          `xml:"numphotos"`
	Content   EntryContent `xml:"content"`
	Media     *Media       `xml:"group"`
	Exif      *Exif        `xml:"tags"`
	Point     string       `xml:"where>Point>pos"`
}

func (*Entry) DecodeReader

func (e *Entry) DecodeReader(r io.Reader) error

type EntryContent

type EntryContent struct {
	URL  string `xml:"src,attr"`
	Type string `xml:"type,attr"`
}

type Exif

type Exif struct {
	FStop       float32 `xml:"fstop"`
	Make        string  `xml:"make"`
	Model       string  `xml:"model"`
	Exposure    float32 `xml:"exposure"`
	Flash       bool    `xml:"flash"`
	FocalLength float32 `xml:"focallength"`
	ISO         int32   `xml:"iso"`
	Timestamp   int64   `xml:"time"`
	UID         string  `xml:"imageUniqueID"`
}

type FileCache

type FileCache struct {
	Log func(...interface{}) error
	// contains filtered or unexported fields
}

func NewTokenCache

func NewTokenCache(path string, ts oauth2.TokenSource, Log func(...interface{}) error) (*FileCache, error)

NewTokenCache returns a TokenSource wrapped in a file cache, which saves tokens into the file.

ts can be nil, and later be set with SetTokenSource.

func (*FileCache) SetTokenSource

func (fc *FileCache) SetTokenSource(ts oauth2.TokenSource)

func (*FileCache) Token

func (fc *FileCache) Token() (*oauth2.Token, error)
type Link struct {
	Rel  string `xml:"rel,attr"`
	Type string `xml:"type,attr"`
	URL  string `xml:"href,attr"`
}

type Media

type Media struct {
	Title       string         `xml:"http://search.yahoo.com/mrss title"`
	Description string         `xml:"description"`
	Keywords    string         `xml:"keywords"`
	Content     []MediaContent `xml:"content"`
	Thumbnail   []MediaContent `xml:"thumbnail"`
}

type MediaContent

type MediaContent struct {
	URL    string `xml:"url,attr"`
	Type   string `xml:"type,attr"`
	Width  int    `xml:"width,attr"`
	Height int    `xml:"height,attr"`
	Medium string `xml:"medium,attr"` // "image" or "video" for Picasa at least
}

type Photo

type Photo struct {
	// ID is the stable identifier for the photo.
	ID string

	// Filename is the image's filename from the Atom title field.
	Filename string

	// Description is the caption of the photo.
	Description string

	Keywords           []string
	Published, Updated time.Time

	// Latitude and Longitude optionally contain the GPS coordinates
	// of the photo.
	Latitude, Longitude float64

	// Location is free-form text describing the location of the
	// photo.
	Location string

	// URL is the URL of the photo or video.
	URL string

	// PageURL is the URL to the page showing just this image.
	PageURL string

	// Type is the Content-Type.
	Type string

	// Position is the 1-based position within a gallery.
	// It is zero if unknown.
	Position int

	Exif *Exif

	Width, Height int
}

A Photo is a photo (or video) in a Picasaweb (or G+) gallery.

func GetPhotos

func GetPhotos(client *http.Client, userID, albumID string) ([]Photo, error)

func UploadPhoto

func UploadPhoto(client *http.Client, userID, albumID, fileName, summary, MIME string, photoRaw []byte) (*Photo, error)

Upload photo If userID is empty, "default" is used. If albumID is empty, "default" is used.

fileName is the image's filename summary is the caption of the photo. MIME is the Content-Type, only support "image/bmp", "image/gif", "image/jpeg", and "image/png"

type User

type User struct {
	ID, URI, Name, Thumbnail string
}

func GetUser

func GetUser(client *http.Client, userID string) (User, error)

GetUser returns the user's info

Directories

Path Synopsis
pica-dl implements a simple Picasa Web downloader.
pica-dl implements a simple Picasa Web downloader.

Jump to

Keyboard shortcuts

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