74 lines
1.4 KiB
Go
Executable File
74 lines
1.4 KiB
Go
Executable File
package arlo
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"local/logb"
|
|
"local/sandbox/arlo-cleaner/config"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/jeffreydwalter/arlo-go"
|
|
)
|
|
|
|
const TSFormat = "2006_01_02_15_04"
|
|
|
|
type Video struct {
|
|
Duration time.Duration
|
|
Loc *url.URL
|
|
Created time.Time
|
|
Device string
|
|
ID string
|
|
Recording arlo.Recording
|
|
}
|
|
|
|
func NewVideo(recording arlo.Recording) *Video {
|
|
url, err := url.Parse(recording.PresignedContentUrl)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &Video{
|
|
Duration: time.Duration(recording.MediaDurationSecond) * time.Second,
|
|
Loc: url,
|
|
Created: time.Unix(0, int64(time.Millisecond)*recording.UtcCreatedDate),
|
|
Device: recording.DeviceId,
|
|
ID: recording.UniqueId,
|
|
Recording: recording,
|
|
}
|
|
}
|
|
|
|
func (v *Video) Key() string {
|
|
return path.Join(
|
|
fmt.Sprintf("%s.%s.%s",
|
|
v.Created.Format(TSFormat),
|
|
v.Device,
|
|
v.Loc.Path[strings.LastIndex(v.Loc.Path, ".")+1:],
|
|
),
|
|
)
|
|
}
|
|
|
|
func (v *Video) String() string {
|
|
return fmt.Sprintf("%s:{dur:%q,create:%q,url:%q}",
|
|
v.ID,
|
|
v.Duration.String(),
|
|
v.Created.String(),
|
|
v.Loc.String(),
|
|
)
|
|
}
|
|
|
|
func (v *Video) Download() (io.ReadCloser, error) {
|
|
resp, err := http.Get(v.Loc.String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
logb.Infof("downloading arlo video from %v", v.Created)
|
|
return resp.Body, err
|
|
}
|
|
|
|
func (v *Video) Size() int64 {
|
|
return int64(v.Duration.Seconds()) * config.ArloBPS
|
|
}
|