I can get the filesizes of each file in a youtube playlist but how can I add all the individual filesizes together to get a total size in Megabytes or Gigabytes of all of them added together?
Example: Linux / Ubuntu commands
youtube-dl --get-filename -o "File size for %(id)s (%(format_id)s): %(filesize)s = 125*%(duration)s*%(tbr)s" -f "22/best" --ignore-config "https://www.youtube.com/watch?v=b26ZBgspv7M&list=PLLYQF5WvJdJXE-aP7oF5ucXcCfHmub34A" | (IFS='='; while read -r a b; do echo "$a = $(echo "$b" | bc)"; done)
File size for b26ZBgspv7M (22): NA = 632016.000
File size for nPr3qtZ5FVE (18): NA = 47577837.000
File size for 8FCsS6s1Z0k (18): NA = 67788616.500
File size for TZANoOWFX1M (18): 62402644 = 62393587.750
File size for XA5eobevGv8 (22): NA = 117960449.500
File size for lDplUpPoCcI (22): NA = 175676293.75
File size for a7TUIkn3qjY (22): NA = 299391049.125
File size for HFPObieGamg (22): NA = 270756696.875
File size for PiiDs8dzSXk (22): NA = 55946363.250
File size for tth0p7nK18A (22): NA = 31281180.00
File size for Z_xj9ZTV8ak (22): NA = 126366879.000
File size for Y_YHqM5nTHA (22): NA = 42328527.000
File size for BjV-fRCPgAM (22): NA = 42225633.375
CodePudding user response:
You aready seem to know how to split input - just sum it then.
youtube-dl ..... | (
sum=0
while IFS='=' read -r a b; do
sum=$(echo "$sum $b" | bc)
done
echo "The sum: $sum"
)
Interest yourself in awk
, it's a real handy tool. You can search "how to sum column in awk" for sure you'll get ton of examples.
CodePudding user response:
You've almost done it:
youtube-dl ...args... |
{ while IFS='=' read -r a b; do printf '%s ' "$b"; done; echo 0; } | bc