2018-09-22 19:22:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Jeffrey Walter <jeffreydwalter@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
|
|
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
|
|
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2018-09-19 07:07:32 +00:00
|
|
|
package arlo
|
2017-12-10 19:17:09 +00:00
|
|
|
|
|
|
|
import (
|
2018-09-22 19:22:42 +00:00
|
|
|
"fmt"
|
2017-12-10 19:17:09 +00:00
|
|
|
"time"
|
2018-09-22 19:22:42 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2017-12-10 19:17:09 +00:00
|
|
|
)
|
2017-12-09 03:55:38 +00:00
|
|
|
|
|
|
|
// LibraryMetaData is the library meta data.
|
|
|
|
type LibraryMetaData struct {
|
|
|
|
DateTo string `json:"dateTo"`
|
|
|
|
DateFrom string `json:"dateFrom"`
|
|
|
|
Meta map[string]map[string]Favorite `json:"meta"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// presignedContentUrl is a link to the actual video in Amazon AWS.
|
|
|
|
// presignedThumbnailUrl is a link to the thumbnail .jpg of the actual video in Amazon AWS.
|
|
|
|
type Recording struct {
|
|
|
|
MediaDurationSecond int `json:"mediaDurationSecond"`
|
|
|
|
ContentType string `json:"contentType"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
PresignedContentUrl string `json:"presignedContentUrl"`
|
|
|
|
LastModified int64 `json:"lastModified"`
|
|
|
|
LocalCreatedDate int64 `json:"localCreatedDate"`
|
|
|
|
PresignedThumbnailUrl string `json:"presignedThumbnailUrl"`
|
|
|
|
Reason string `json:"reason"`
|
|
|
|
DeviceId string `json:"deviceId"`
|
|
|
|
CreatedBy string `json:"createdBy"`
|
|
|
|
CreatedDate string `json:"createdDate"`
|
|
|
|
TimeZone string `json:"timeZone"`
|
|
|
|
OwnerId string `json:"ownerId"`
|
|
|
|
UtcCreatedDate int64 `json:"utcCreatedDate"`
|
|
|
|
CurrentState string `json:"currentState"`
|
|
|
|
MediaDuration string `json:"mediaDuration"`
|
2018-09-22 19:22:42 +00:00
|
|
|
UniqueId string `json:"uniqueId"`
|
2017-12-09 03:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Library []Recording
|
2017-12-10 19:17:09 +00:00
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
func (a *Arlo) GetLibraryMetaData(fromDate, toDate time.Time) (libraryMetaData *LibraryMetaData, err error) {
|
|
|
|
msg := "failed to get library metadata"
|
2017-12-10 19:17:09 +00:00
|
|
|
|
|
|
|
body := map[string]string{"dateFrom": fromDate.Format("20060102"), "dateTo": toDate.Format("20060102")}
|
2018-09-19 21:41:00 +00:00
|
|
|
resp, err := a.post(LibraryMetadataUri, "", body, nil)
|
2018-09-22 19:22:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithMessage(err, msg)
|
2017-12-10 19:17:09 +00:00
|
|
|
}
|
2018-09-22 19:22:42 +00:00
|
|
|
defer resp.Body.Close()
|
2017-12-10 19:17:09 +00:00
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
response := new(LibraryMetaDataResponse)
|
|
|
|
if err := resp.Decode(&response); err != nil {
|
2017-12-10 19:17:09 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
if !response.Success {
|
|
|
|
return nil, errors.New(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &response.Data, nil
|
2017-12-10 19:17:09 +00:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
func (a *Arlo) GetLibrary(fromDate, toDate time.Time) (library *Library, err error) {
|
|
|
|
msg := "failed to get library"
|
2017-12-10 19:17:09 +00:00
|
|
|
|
|
|
|
body := map[string]string{"dateFrom": fromDate.Format("20060102"), "dateTo": toDate.Format("20060102")}
|
2018-09-19 21:41:00 +00:00
|
|
|
resp, err := a.post(LibraryUri, "", body, nil)
|
2018-09-22 19:22:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithMessage(err, msg)
|
2017-12-10 19:17:09 +00:00
|
|
|
}
|
2018-09-22 19:22:42 +00:00
|
|
|
defer resp.Body.Close()
|
2017-12-10 19:17:09 +00:00
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
response := new(LibraryResponse)
|
|
|
|
if err := resp.Decode(&response); err != nil {
|
2017-12-10 19:17:09 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
if !response.Success {
|
|
|
|
return nil, errors.New(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &response.Data, nil
|
2017-12-10 19:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-09-19 19:12:06 +00:00
|
|
|
Delete a single video recording from arlo.
|
2017-12-10 19:17:09 +00:00
|
|
|
|
|
|
|
All of the date info and device id you need to pass into this method are given in the results of the GetLibrary() call.
|
|
|
|
|
|
|
|
NOTE: {"data": [{"createdDate": r.CreatedDate, "utcCreatedDate": r.UtcCreatedDate, "deviceId": r.DeviceId}]} is all that's really required.
|
|
|
|
*/
|
2018-09-22 19:22:42 +00:00
|
|
|
func (a *Arlo) DeleteRecording(r *Recording) error {
|
2017-12-10 19:17:09 +00:00
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
body := map[string]Library{"data": {*r}}
|
2018-09-19 21:41:00 +00:00
|
|
|
resp, err := a.post(LibraryRecycleUri, "", body, nil)
|
2018-09-20 22:38:01 +00:00
|
|
|
return checkRequest(resp, err, "failed to delete recording")
|
2017-12-10 19:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-09-19 19:12:06 +00:00
|
|
|
Delete a batch of video recordings from arlo.
|
2017-12-10 19:17:09 +00:00
|
|
|
|
|
|
|
The GetLibrary() call response json can be passed directly to this method if you'd like to delete the same list of videos you queried for.
|
|
|
|
|
|
|
|
NOTE: {"data": [{"createdDate": r.CreatedDate, "utcCreatedDate": r.UtcCreatedDate, "deviceId": r.DeviceId}]} is all that's really required.
|
|
|
|
*/
|
2018-09-22 19:22:42 +00:00
|
|
|
func (a *Arlo) BatchDeleteRecordings(l *Library) error {
|
2017-12-10 19:17:09 +00:00
|
|
|
|
2018-09-22 19:22:42 +00:00
|
|
|
body := map[string]Library{"data": *l}
|
|
|
|
fmt.Printf("%+v\n", body)
|
|
|
|
return nil
|
|
|
|
//resp, err := a.post(LibraryRecycleUri, "", body, nil)
|
|
|
|
//return checkRequest(resp, err, "failed to delete recordings")
|
2017-12-10 19:17:09 +00:00
|
|
|
}
|