1// Copyright 2014 Tamás Gulácsi. All rights reserved.
2// Use of this source code is governed by an Apache 2.0
3// license that can be found in the LICENSE file.
4
5package picago
6
7import (
8	"encoding/xml"
9	"io"
10	"time"
11)
12
13type Atom struct {
14	ID           string    `xml:"id"`
15	Name         string    `xml:"name"`
16	Updated      time.Time `xml:"updated"`
17	Title        string    `xml:"title"`
18	Subtitle     string    `xml:"subtitle"`
19	Icon         string    `xml:"icon"`
20	Thumbnail    string    `xml:"http://schemas.google.com/photos/2007 thumbnail"`
21	Author       Author    `xml:"author"`
22	NumPhotos    int       `xml:"numphotos"`
23	StartIndex   int       `xml:"startIndex"`
24	TotalResults int       `xml:"totalResults"`
25	ItemsPerPage int       `xml:"itemsPerPage"`
26	Entries      []Entry   `xml:"entry"`
27}
28
29type Entry struct {
30	ETag      string       `xml:"etag,attr"`
31	EntryID   string       `xml:"http://www.w3.org/2005/Atom id"`
32	ID        string       `xml:"http://schemas.google.com/photos/2007 id"`
33	Published time.Time    `xml:"published"`
34	Updated   time.Time    `xml:"updated"`
35	Name      string       `xml:"http://schemas.google.com/photos/2007 name"`
36	Title     string       `xml:"title"`
37	Summary   string       `xml:"summary"`
38	Rights    string       `xml:"rights"`
39	AlbumType string       `xml:"albumType"`
40	Links     []Link       `xml:"link"`
41	Author    Author       `xml:"author"`
42	Location  string       `xml:"http://schemas.google.com/photos/2007 location"`
43	NumPhotos int          `xml:"numphotos"`
44	Content   EntryContent `xml:"content"`
45	Media     *Media       `xml:"group"`
46	Exif      *Exif        `xml:"tags"`
47	Point     string       `xml:"where>Point>pos"`
48}
49
50type Exif struct {
51	FStop       float32 `xml:"fstop"`
52	Make        string  `xml:"make"`
53	Model       string  `xml:"model"`
54	Exposure    float32 `xml:"exposure"`
55	Flash       bool    `xml:"flash"`
56	FocalLength float32 `xml:"focallength"`
57	ISO         int32   `xml:"iso"`
58	Timestamp   int64   `xml:"time"`
59	UID         string  `xml:"imageUniqueID"`
60}
61
62type Link struct {
63	Rel  string `xml:"rel,attr"`
64	Type string `xml:"type,attr"`
65	URL  string `xml:"href,attr"`
66}
67
68type Media struct {
69	Title       string         `xml:"http://search.yahoo.com/mrss title"`
70	Description string         `xml:"description"`
71	Keywords    string         `xml:"keywords"`
72	Content     []MediaContent `xml:"content"`
73	Thumbnail   []MediaContent `xml:"thumbnail"`
74}
75
76type MediaContent struct {
77	URL    string `xml:"url,attr"`
78	Type   string `xml:"type,attr"`
79	Width  int    `xml:"width,attr"`
80	Height int    `xml:"height,attr"`
81	Medium string `xml:"medium,attr"` // "image" or "video" for Picasa at least
82}
83
84type EntryContent struct {
85	URL  string `xml:"src,attr"`
86	Type string `xml:"type,attr"`
87}
88
89type Author struct {
90	Name string `xml:"name"`
91	URI  string `xml:"uri"`
92}
93
94func ParseAtom(r io.Reader) (*Atom, error) {
95	result := new(Atom)
96	if err := xml.NewDecoder(r).Decode(result); err != nil {
97		return nil, err
98	}
99	return result, nil
100}
101