81 lines
1.9 KiB
Go
Executable File
81 lines
1.9 KiB
Go
Executable File
package arlo
|
|
|
|
import (
|
|
"fmt"
|
|
"local/logb"
|
|
"local/sandbox/arlo-cleaner/config"
|
|
"time"
|
|
|
|
"github.com/jeffreydwalter/arlo-go"
|
|
)
|
|
|
|
type Arlo struct {
|
|
client *arlo.Arlo
|
|
}
|
|
|
|
func New() (*Arlo, error) {
|
|
client, err := arlo.Login(config.ArloUser, config.ArloPass)
|
|
if err != nil {
|
|
err = fmt.Errorf("failed to arlo.New: %v", err)
|
|
}
|
|
logb.Debugf("logged into arlo @%v", config.ArloUser)
|
|
return &Arlo{
|
|
client: client,
|
|
}, err
|
|
}
|
|
|
|
func (a *Arlo) ListSince(since time.Time) ([]*Video, error) {
|
|
library, err := a.client.GetLibrary(since, time.Now())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
videos := make([]*Video, len(*library))
|
|
for i, recording := range *library {
|
|
videos[i] = NewVideo(recording)
|
|
}
|
|
logb.Debugf("found %v videos in library", len(videos))
|
|
return videos, nil
|
|
}
|
|
|
|
func (a *Arlo) DeleteVideos(videos []*Video) error {
|
|
library := make([]arlo.Recording, len(videos))
|
|
for i, video := range videos {
|
|
library[i] = video.Recording
|
|
}
|
|
lib := arlo.Library(library)
|
|
logb.Infof("deleting %v videos from library", len(videos))
|
|
if config.DryRun {
|
|
logb.Infof("delete", videos)
|
|
return nil
|
|
}
|
|
return a.client.BatchDeleteRecordings(&lib)
|
|
}
|
|
|
|
func (a *Arlo) DeleteVideo(video *Video) error {
|
|
if config.DryRun {
|
|
logb.Infof("delete", video)
|
|
return nil
|
|
}
|
|
logb.Infof("deleting %v videos from library", 1)
|
|
return a.DeleteVideos([]*Video{video})
|
|
}
|
|
|
|
func (a *Arlo) Usage() (int64, error) {
|
|
videos, err := a.ListSince(time.Now().Add(-1 * 24 * 30 * time.Hour))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
var current int64
|
|
for _, video := range videos {
|
|
current += video.Size()
|
|
}
|
|
logb.Debugf("arlo probably using %v B (%v MB) over %v videos", current, current/1000/1000, len(videos))
|
|
return current, nil
|
|
}
|
|
|
|
func (a *Arlo) NeedsPruning() (bool, error) {
|
|
usage, err := a.Usage()
|
|
logb.Debugf("arlo needs pruning = %v > %v", usage, config.ArloCapacity)
|
|
return usage > config.ArloCapacity, err
|
|
}
|