wtf is going on

pull/2/merge
mpl 5 years ago
parent ab2802257c
commit ed55198ec4

@ -20,8 +20,6 @@ import (
var startFlag = flag.String("start", "", "skip all the photos more recent than the one at that URL") var startFlag = flag.String("start", "", "skip all the photos more recent than the one at that URL")
var secondDir string
func main() { func main() {
flag.Parse() flag.Parse()
s, err := NewSession() s, err := NewSession()
@ -47,7 +45,7 @@ func main() {
}), }),
chromedp.Navigate("https://photos.google.com/"), chromedp.Navigate("https://photos.google.com/"),
// chromedp.Sleep(30000*time.Millisecond), // chromedp.Sleep(30000*time.Millisecond),
chromedp.Sleep(15000*time.Millisecond), chromedp.Sleep(5000*time.Millisecond),
chromedp.ActionFunc(func(ctx context.Context) error { chromedp.ActionFunc(func(ctx context.Context) error {
log.Printf("post-navigate") log.Printf("post-navigate")
return nil return nil
@ -190,68 +188,86 @@ func main() {
} }
} }
_, _, _ = download, navRight, navRightN _, _, _, _ = download, navRight, navRightN, firstNav
if err := chromedp.Run(ctx, photosList := []string{
// TODO(mpl): change dl dir for each photo, to detect it's finished downloading. "https://photos.google.com/photo/AF1QipPMVPPg5TI2-cnAj-gDXYZL_7fG95jqNDCNb6WP",
// TODO(mpl): add policy func over photo URL, which decides what we do (with?) "https://photos.google.com/photo/AF1QipOnmwDjAWN2yN1hTlrD8vxdfCdbA0mcoF8CNFm0",
page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(s.dlDir), "https://photos.google.com/photo/AF1QipPNNMjO3KT58o52V2WVzATr0zMKbmTQ-I2PPGyf",
chromedp.Navigate("https://photos.google.com/"), }
chromedp.Sleep(5000*time.Millisecond),
// the `ERROR: unhandled page event *page.EventDownloadWillBegin` error does show up, but it does not actually prevent the download, so who cares?
chromedp.WaitReady("body", chromedp.ByQuery), var currentDir string
chromedp.ActionFunc(func(ctx context.Context) error { for _, v := range photosList {
log.Printf("body is ready") if err := chromedp.Run(ctx,
return nil // This one here works, so why not below??
}), // page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath("/Users/mpl/Downloads/pk-gphotos"),
chromedp.ActionFunc(func(ctx context.Context) error { // TODO(mpl): change dl dir for each photo, to detect it's finished downloading.
if err := firstNav(ctx); err != nil { // TODO(mpl): add policy func over photo URL, which decides what we do (with?)
return err /*
} page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(s.dlDir),
return download(ctx, s.dlDir) chromedp.Navigate("https://photos.google.com/"),
}), chromedp.Sleep(5000*time.Millisecond),
// the `ERROR: unhandled page event *page.EventDownloadWillBegin` error does show up, but it does not actually prevent the download, so who cares?
chromedp.ActionFunc(func(ctx context.Context) error { chromedp.WaitReady("body", chromedp.ByQuery),
dir, err := ioutil.TempDir(s.dlDir, "") chromedp.ActionFunc(func(ctx context.Context) error {
if err != nil { log.Printf("body is ready")
return err return nil
} }),
secondDir = dir chromedp.ActionFunc(func(ctx context.Context) error {
page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(dir) if err := firstNav(ctx); err != nil {
return nil return err
chromedp.KeyEvent(kb.ArrowRight).Do(ctx) }
chromedp.Sleep(500 * time.Millisecond).Do(ctx) return download(ctx, s.dlDir)
return download(ctx, dir) }),
}), */
chromedp.Navigate("https://photos.google.com/photo/AF1QipMtEd38o-lZxDOfME7fJKKjQuNEHTe0MbhJYAIO"),
chromedp.Sleep(5000*time.Millisecond),
chromedp.ActionFunc(func(ctx context.Context) error {
return download(ctx, secondDir)
}),
/*
chromedp.ActionFunc(func(ctx context.Context) error { chromedp.ActionFunc(func(ctx context.Context) error {
// TODO(mpl): instead of tempdir name, probably use dated name instead?
dir, err := ioutil.TempDir(s.dlDir, "") dir, err := ioutil.TempDir(s.dlDir, "")
if err != nil { if err != nil {
return err return err
} }
// TODO(mpl): that does not seem to be working here. maybe we need to do it before navigating? currentDir = dir
// Maybe if we put each nav+download into their own chromedp.Run ? return nil
page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(dir)
// TODO(mpl): cleanup dir
if err := firstNav(ctx); err != nil {
return err
}
return download(ctx, dir)
}), }),
navRightN(5, ctx), chromedp.ActionFunc(func(ctx context.Context) error {
*/ println("CURRENTDIR: ", currentDir)
); err != nil { page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(currentDir)
log.Fatal(err) return nil
}),
// WTF IS 2019/08/18 00:49:30 downloadPath not provided (-32000)
// maybe wrong chmod on the dir?? nope.
// page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(foo),
chromedp.Navigate(v),
chromedp.Sleep(5000*time.Millisecond),
chromedp.WaitReady("body", chromedp.ByQuery),
chromedp.ActionFunc(func(ctx context.Context) error {
return download(ctx, currentDir)
}),
/*
chromedp.ActionFunc(func(ctx context.Context) error {
// TODO(mpl): instead of tempdir name, probably use dated name instead?
dir, err := ioutil.TempDir(s.dlDir, "")
if err != nil {
return err
}
// TODO(mpl): that does not seem to be working here. maybe we need to do it before navigating?
// Maybe if we put each nav+download into their own chromedp.Run ?
page.SetDownloadBehavior(page.SetDownloadBehaviorBehaviorAllow).WithDownloadPath(dir)
// TODO(mpl): cleanup dir
if err := firstNav(ctx); err != nil {
return err
}
return download(ctx, dir)
}),
navRightN(5, ctx),
*/
); err != nil {
log.Fatal(err)
}
fmt.Println("OK")
} }
fmt.Println("OK")
// Next: keys // Next: keys
// https://github.com/chromedp/chromedp/issues/400 // https://github.com/chromedp/chromedp/issues/400

Loading…
Cancel
Save