diff --git a/scripts/dvd.video.read.sh b/scripts/dvd.video.read.sh index a30f486..f39bd09 100755 --- a/scripts/dvd.video.read.sh +++ b/scripts/dvd.video.read.sh @@ -13,52 +13,30 @@ totalSize=$(dvdbackup -I | awk '/[MK]iB$/ { b += $2 } END { print b }') dvdbackup -p -F -n DVD \ | tr '\r' '\n' \ -| awk -F '[ /:]+' ' - function update() { - print "% " pct; - fflush(); +| awk -v total=$totalSize -F '[ /:()]+' ' + function update(bytes) { + pct = 100 * bytes / total + if (pct >= nextpct) { + print pct + fflush() + nextpct = pct + 0.5 + } } - /Found [0-9]+ VTS/ { - numTitles = $3; - title = 1; - pct = 0; - print "# I found " numTitles " titles" - update() - } - /Copying menu:/ { - # Not sure how to know in advance how many of these there will be. - print "# We are reading the menu: " $0 - update(); - } - /Copying Title,/ { - # Copying Title, part 1/5: 23% done (239/1024 MiB) - part = $4 - parts = $5 - done = $6 - print "# Title " part " of " parts " pct " done - titleDone = (part * 100 - 100 + done) / parts; - if (titleDone < titleLast) { - title += 1; + /[MK]iB.$/ { + read = $(NF-3) * 1024 + if ($(NF-1) == "MiB") { + read *= 1024 } - titleLast = titleDone; - pct = (title * 100 - 100 + pctDone) / numTitles; - update(); - } - { - print "## " $0; - update(); + if (read < last) { + totalRead += last + } + update(totalRead + read) + last = read } ' \ -| while read t val; do - case "$t" in - "%") - setenv complete "$val" - echo "Complete: $val" - ;; - *) - echo "$t $val" - ;; - esac +| while read val; do + setenv complete "$val" + echo "Complete: $val" done