Finally a working dvdbackup parser

This commit is contained in:
Neale Pickett 2022-01-09 16:54:08 -07:00
parent f739a18c23
commit 5d0c35e78c
1 changed files with 20 additions and 42 deletions

View File

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