nItemsFlag=flag.Int("n",-1,"number of items to download. If negative, get them all.")
nItemsFlag=flag.Int("n",-1,"number of items to download. If negative, get them all.")
devFlag=flag.Bool("dev",false,"dev mode. we reuse the same session dir (/tmp/gphotos-cdp), so we don't have to auth at every run.")
devFlag=flag.Bool("dev",false,"dev mode. we reuse the same session dir (/tmp/gphotos-cdp), so we don't have to auth at every run.")
dlDirFlag=flag.String("dldir","","where to (temporarily) write the downloads. defaults to $HOME/Downloads/gphotos-cdp.")
dlDirFlag=flag.String("dldir","","where to (temporarily) write the downloads. defaults to $HOME/Downloads/gphotos-cdp.")
startFlag=flag.String("start","","skip all photos until this location is reached. for debugging.")
)
)
funcmain(){
funcmain(){
@ -30,6 +31,9 @@ func main() {
if*nItemsFlag==0{
if*nItemsFlag==0{
return
return
}
}
if!*devFlag&&*startFlag!=""{
log.Fatal("-start only allowed in dev mode")
}
s,err:=NewSession()
s,err:=NewSession()
iferr!=nil{
iferr!=nil{
log.Fatal(err)
log.Fatal(err)
@ -140,16 +144,18 @@ func main() {
varfilenamestring
varfilenamestring
started:=false
started:=false
endTimeout:=time.Now().Add(30*time.Second)
// TODO(mpl): do not use just an endTimeout. instead, only start a countdown if/when size of download stops progressing. and reset it everytime dowload makes progress again.
startTimeout:=time.Now().Add(5*time.Second)
varendTimeouttime.Time
startTimeout:=time.Now().Add(time.Minute)
tick:=500*time.Millisecond
tick:=500*time.Millisecond
for{
for{
time.Sleep(tick)
time.Sleep(tick)
if time.Now().After(endTimeout){
ifstarted &&time.Now().After(endTimeout){
return"",fmt.Errorf("timeout while downloading in %q",dir)
return"",fmt.Errorf("timeout while downloading in %q",dir)
}
}
// TODO(mpl): this breaks for a large video/file?
// TODO(mpl): download starts late if it's a video. figure out if dl can only
// start after video has started playing or something like that?
if!started&&time.Now().After(startTimeout){
if!started&&time.Now().After(startTimeout){
return"",fmt.Errorf("downloading in %q took too long to start",dir)
return"",fmt.Errorf("downloading in %q took too long to start",dir)