Skip to content

Commit

Permalink
speed display, and some other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzy committed Jul 7, 2024
1 parent 34c3133 commit 4e34fec
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 13 deletions.
17 changes: 13 additions & 4 deletions fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/dustin/go-humanize"
"github.com/fuzzy/subhuman"
)

func httpGet(uri string) string {
Expand Down Expand Up @@ -112,7 +112,15 @@ func fetchWorker(toFetch chan string) {
resp, _ := http.Head(val)
if stat.Size() == resp.ContentLength {
dload = false
debug(fmt.Sprintf("Skipping: %s", val))
if len(val) > 85 {
dfn = fmt.Sprintf("...%s", val[len(val)-85:])
} else if len(val) < 85 {
dfn = val
for i := 0; i < 85-len(val); i++ {
dfn += " "
}
}
debug(fmt.Sprintf("Skipping: %s", dfn))
fetched++
}
}
Expand All @@ -135,11 +143,12 @@ func fetchWorker(toFetch chan string) {
// and truncate the beginning of the filename if it's too long for display
// leaving room for 3 dots
dfn = ofn
if len(ofn) > 47 {
if len(ofn) > 67 {
dfn = fmt.Sprintf("...%s", ofn[len(ofn)-47:])
}
// and display the results
info(fmt.Sprintf("Fetched: %-50s [%-10s @ %10s/s]", dfn, humanize.Bytes(uint64(sz.Size())), humanize.Bytes(uint64(sp))))
info(fmt.Sprintf("Fetched: %-87s [%-10s @ %10s/s]", dfn, subhuman.HumanSize(int64(sz.Size())), subhuman.HumanSize(int64(sp))))
totalSize += int64(sz.Size())
fetched++
}
// and remove the lock file
Expand Down
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 21 additions & 9 deletions magicmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var programCopy = "2024"

var matched = 0
var fetched = 0
var totalSize = int64(0)

var opts struct {
Verbose []bool `short:"v" long:"verbose" description:"Show verbose information (twice for debug)"`
Expand Down Expand Up @@ -78,18 +79,29 @@ func main() {
// Wait for all workers to finish
for len(toParse) > 0 || len(toMatch) > 0 || len(toFetch) > 0 || fetched < matched {
if !opts.Quiet {
_q := fmt.Sprintf("toParse: %-10d || toMatch: %-10d || toFetch: %-10d", len(toParse), len(toMatch), len(toFetch))
_c := fmt.Sprintf("(%d/%d %6s%%", fetched, matched, fmt.Sprintf("%.02f", (float64(fetched)/float64(matched))*float64(100)))
_d := fmt.Sprintf(" in %s)", subhuman.HumanTimeColon(time.Now().Unix()-start))
fmt.Print(fmt.Sprintf("%s %s%s\r", _q, _c, _d))
_toParse := len(toParse)
_toMatch := len(toMatch)
_toFetch := len(toFetch)
_partOne := fmt.Sprintf("toParse: %-9d || toMatch: %-9d || toFetch: %-9d", _toParse, _toMatch, _toFetch)
_percent := float64(fetched) / float64(matched) * float64(100)
_partTwo := fmt.Sprintf("(%d/%d %6s%%", fetched, matched, fmt.Sprintf("%.02f", _percent))
_totalSize := subhuman.HumanSize(totalSize)
_speed := subhuman.HumanSize(int64(float64(totalSize) / (float64(time.Now().Unix() - start))))
_partThree := fmt.Sprintf("|| %s in %s @ %s)", _totalSize, subhuman.HumanTimeColon(time.Now().Unix()-start), _speed)
fmt.Print(fmt.Sprintf("%s %s %s\r", _partOne, _partTwo, _partThree))
}
time.Sleep(10 * time.Millisecond)
}
if !opts.Quiet {
_q := fmt.Sprintf("toParse: %-10d || toMatch: %-10d || toFetch: %-10d", len(toParse), len(toMatch), len(toFetch))
_c := fmt.Sprintf("(%d/%d %6s%%", fetched, matched, fmt.Sprintf("%.02f", (float64(fetched)/float64(matched))*float64(100)))
_d := fmt.Sprintf(" in %s)", subhuman.HumanTimeColon(time.Now().Unix()-start))
fmt.Print(fmt.Sprintf("%s %s%s\r", _q, _c, _d))
fmt.Println("")
_toParse := len(toParse)
_toMatch := len(toMatch)
_toFetch := len(toFetch)
_partOne := fmt.Sprintf("toParse: %-9d || toMatch: %-9d || toFetch: %-9d", _toParse, _toMatch, _toFetch)
_percent := float64(fetched) / float64(matched) * float64(100)
_partTwo := fmt.Sprintf("(%d/%d %6s%%", fetched, matched, fmt.Sprintf("%.02f", _percent))
_totalSize := subhuman.HumanSize(totalSize)
_speed := subhuman.HumanSize(int64(float64(totalSize) / (float64(time.Now().Unix() - start))))
_partThree := fmt.Sprintf("|| %s in %s @ %s)", _totalSize, subhuman.HumanTimeColon(time.Now().Unix()-start), _speed)
fmt.Print(fmt.Sprintf("%s %s %s\r", _partOne, _partTwo, _partThree))
}
}
2 changes: 2 additions & 0 deletions vendor/github.com/fuzzy/subhuman/.hound.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/fuzzy/subhuman/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/fuzzy/subhuman/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions vendor/github.com/fuzzy/subhuman/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vendor/github.com/fuzzy/subhuman/size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions vendor/github.com/fuzzy/subhuman/time.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e34fec

Please sign in to comment.