bring imports to the top
[undvd.git] / vidstat
blob6c8848ae0ddb8cf3f191a39d6bb583df9730d4ba
1 #!/bin/bash
3 # Author: Martin Matusiak <numerodix@gmail.com>
4 # Licensed under the GNU Public License, version 3.
7 # load constants and functions
8 p=$(dirname $(readlink -f $0)); . $p/lib.sh
10 usage="Usage: ${b}${tool_name} ${r}[${bb}<file(s)>${r} | ${b}--dev ${bb}/dev/dvd${r} | ${b}--dir ${bb}/path${r} | ${b}--iso ${bb}disc.iso${r}]
11 <file(s)> files to read
12 -d --dev dvd device to read from (default is ${bb}/dev/dvd${r})
13 -q --dir dvd directory to read from
14 -i --iso dvd iso image to read from
15 --version show ${suite_name} version"
17 shorts="d:q:i:"
18 longs="dev:,dir:,iso:,version"
19 eval $(get_parsecmd "$tool_name" "$shorts" "$longs")
21 while true; do
22 case "$1" in
23 -d|--dev ) input_dvd_device="$2"; shift 2;; # str
24 -q|--dir ) input_dvd_device="$2"; shift 2;; # str
25 -i|--iso ) input_dvd_device="$2"; shift 2;; # str
26 --version ) print_version;;
27 -- ) shift ; break ;;
28 * ) break ;;
29 esac
30 done
32 display_tool_banner
35 if [[ ! "$input_dvd_device" && ! "$@" ]]; then
36 echo -e "$usage"
37 exit 2
41 # Build array either of dvd titles or files given as input
43 files=() ; i=0
44 if [[ "$input_dvd_device" ]]; then
45 titles=$(examine_dvd_for_titlecount "$input_dvd_device")
46 if [[ "$titles" ]]; then
47 for f in $($seq 1 $titles); do
48 files[$i]="$f"
49 i=$(( $i+1 ))
50 done
51 else
52 echo -e "${e}Could not read from ${bb}$input_dvd_device${e} dvd device${r}"
53 exit 1
55 else
56 for f in "$@"; do
57 files[$i]="$f"
58 i=$(( $i+1 ))
59 done
63 display_title_line "header"
64 for file in "${files[@]}"; do
65 if [[ ! "$input_dvd_device" && ! -e "$file" ]]; then
66 echo -e "${e}File ${bb}$file${e} does not exist"
67 exit 1
70 if [[ "$input_dvd_device" ]]; then
71 filename="$file"
72 filesize="-1"
73 info=($(examine_title "dvd://$file" "$input_dvd_device"))
74 else
75 filename=$(basename "$file")
77 filesize=$(stat "$file" | $grep "Size:" | $sed "s|.*Size: \([0-9]*\).*|\1|g")
78 filesize=$(echo "scale=0; $filesize/1024/1024" | $bc) # convert to mb
80 info=($(examine_title "$file"))
83 width=${info[0]}
85 height=${info[1]}
87 fps=${info[2]}
89 length=${info[3]}
91 abitrate=$( echo "scale=0; ${info[4]}/1024" | $bc ) # convert to kbps
93 aformat=${info[5]}
95 vbitrate=$( echo "scale=0; ${info[6]}/1024" | $bc ) # convert to kbps
96 if [[ "$vbitrate" ]]; then
97 bpp=$(compute_bpp "$width" "$height" "$fps" "$length" "" "$vbitrate")
100 vformat=${info[7]}
102 passes="0"
104 display_title "$width" "$height" "$fps" "$length" "$bpp" "$passes" "$vbitrate" "$vformat" "$abitrate" "$aformat" "$filesize" "$filename"
105 done