From 29e5c7216c187c1eaa7bd96c8f4e9ade5c5ca30c Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 27 Aug 2019 23:48:33 +0200 Subject: [PATCH] simplify jumping to last done --- main.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 7e66944..944f4d8 100644 --- a/main.go +++ b/main.go @@ -237,12 +237,19 @@ func main() { } firstNav := func(ctx context.Context) error { + // TODO(mpl): do these two special cases even before jumping to the oldest. if *startFlag != "" { chromedp.Navigate(*startFlag).Do(ctx) chromedp.WaitReady("body", chromedp.ByQuery).Do(ctx) chromedp.Sleep(5000 * time.Millisecond).Do(ctx) return nil } + if s.lastDone != "" { + chromedp.Navigate(s.lastDone).Do(ctx) + chromedp.WaitReady("body", chromedp.ByQuery).Do(ctx) + chromedp.Sleep(5000 * time.Millisecond).Do(ctx) + return nil + } chromedp.KeyEvent(kb.ArrowRight).Do(ctx) chromedp.Sleep(500 * time.Millisecond).Do(ctx) chromedp.KeyEvent("\n").Do(ctx) @@ -274,27 +281,16 @@ func main() { return nil } var location string - // TODO(mpl): navigate directly to lastdone. - lookingForLastDone := true - if s.lastDone == "" { - lookingForLastDone = false - } for { + // TODO(mpl): move the Location call to within download() ? if err := chromedp.Location(&location).Do(ctx); err != nil { return err } - if !lookingForLastDone { - // TODO(mpl): deal with getting the very last photo to properly exit that loop when N < 0. - if err := dlAndMove(ctx, location, true); err != nil { - return err - } - n++ - } else { - println(location, " ALREADY DONE") - if location == s.lastDone { - lookingForLastDone = false - } + // TODO(mpl): deal with getting the very last photo to properly exit that loop when N < 0. + if err := dlAndMove(ctx, location, true); err != nil { + return err } + n++ if N > 0 && n >= N { break }