Merge branch 'toys'
* toys: Add --stats (overall format statistics)
This commit is contained in:
commit
c1c790442c
136
toys/createindex
136
toys/createindex
@ -70,6 +70,8 @@ do
|
|||||||
'-y') show+=(years) ;;
|
'-y') show+=(years) ;;
|
||||||
'-#') show+=(count) ;;
|
'-#') show+=(count) ;;
|
||||||
|
|
||||||
|
'--stats') stats=1 ;;
|
||||||
|
|
||||||
'-T') timeformat="$1"
|
'-T') timeformat="$1"
|
||||||
shift
|
shift
|
||||||
continue ;;
|
continue ;;
|
||||||
@ -110,6 +112,8 @@ done
|
|||||||
-t Title
|
-t Title
|
||||||
-y Year
|
-y Year
|
||||||
|
|
||||||
|
--stats
|
||||||
|
|
||||||
-T <format>: date-time format (see 'man date' for possible values)
|
-T <format>: date-time format (see 'man date' for possible values)
|
||||||
-o <file> : output file (path relative to Source)
|
-o <file> : output file (path relative to Source)
|
||||||
|
|
||||||
@ -561,3 +565,135 @@ do
|
|||||||
olddir="$dir"
|
olddir="$dir"
|
||||||
done
|
done
|
||||||
printline
|
printline
|
||||||
|
|
||||||
|
(( stats )) || exit 0
|
||||||
|
unset types counts counpcts sizes sizepcts
|
||||||
|
echo '
|
||||||
|
|
||||||
|
|
||||||
|
'
|
||||||
|
echo '
|
||||||
|
SELECT COUNT(*),SUM(size)
|
||||||
|
FROM source_files
|
||||||
|
INNER JOIN mime_types
|
||||||
|
ON source_files.mime_type=mime_types.id;' >&3
|
||||||
|
read -u4 line
|
||||||
|
totalcount="${line%%::AtOM:SQL:Sep::*}"
|
||||||
|
maxcountlen=$(printf "%'i" $totalcount)
|
||||||
|
maxcountlen=${#maxcountlen}
|
||||||
|
rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::"
|
||||||
|
totalsize="${line%%::AtOM:SQL:Sep::*}"
|
||||||
|
for format in \
|
||||||
|
audio/x-flac \
|
||||||
|
application/ogg\ vorbis \
|
||||||
|
application/ogg\ opus \
|
||||||
|
audio/mpeg \
|
||||||
|
audio/mp4 \
|
||||||
|
\
|
||||||
|
video/x-ms-asf \
|
||||||
|
video/webm \
|
||||||
|
video/mpeg \
|
||||||
|
video/x-flv \
|
||||||
|
video/x-msvideo \
|
||||||
|
\
|
||||||
|
'image/%' \
|
||||||
|
'text/%' \
|
||||||
|
'%'
|
||||||
|
do
|
||||||
|
echo '
|
||||||
|
SELECT COUNT(*),SUM(size)
|
||||||
|
FROM source_files
|
||||||
|
INNER JOIN mime_types
|
||||||
|
ON source_files.mime_type=mime_types.id
|
||||||
|
WHERE mime_text LIKE "'"$format"'";' >&3
|
||||||
|
read -u4 line
|
||||||
|
count="${line%%::AtOM:SQL:Sep::*}"
|
||||||
|
rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::"
|
||||||
|
size="${rest%%::AtOM:SQL:Sep::*}"
|
||||||
|
(( count )) || continue
|
||||||
|
case $format in
|
||||||
|
application/ogg\ opus) type=Opus ;;
|
||||||
|
application/ogg\ vorbis) type=Vorbis ;;
|
||||||
|
audio/mp4) type=MPEG4\ Audio ;;
|
||||||
|
audio/mpeg) type=MPEG\ Audio ;;
|
||||||
|
audio/x-flac) type=FLAC ;;
|
||||||
|
video/mpeg) type=MPEG\ Video ;;
|
||||||
|
video/webm) type=WebM ;;
|
||||||
|
video/x-flv) type=Flash\ Video ;;
|
||||||
|
video/x-ms-asf) type=Windows\ Media ;;
|
||||||
|
video/x-msvideo) type=AVI\ Video ;;
|
||||||
|
audio/%) type=Total\ Audio ;;
|
||||||
|
video/%) type=Total\ Video ;;
|
||||||
|
image/%) type=Images ;;
|
||||||
|
text/%) type=Texts ;;
|
||||||
|
%) type=Total ;;
|
||||||
|
esac
|
||||||
|
counts+=( "$count" )
|
||||||
|
types+=( "$type" )
|
||||||
|
maxtypelen=$(( ${#type} > maxtypelen ? ${#type} : maxtypelen ))
|
||||||
|
if (( size > 1073741823 ))
|
||||||
|
then
|
||||||
|
size=$(( (size * 1000) / 1073741824 ))
|
||||||
|
int=$(( size / 1000 ))
|
||||||
|
if (( ${#int} > 2 ))
|
||||||
|
then
|
||||||
|
sizes+=( "$(printf %4sG $int)" )
|
||||||
|
else
|
||||||
|
sizes+=( "$(
|
||||||
|
printf %2s.%.1sG\
|
||||||
|
$int \
|
||||||
|
${size#int}
|
||||||
|
)" )
|
||||||
|
fi
|
||||||
|
elif (( size > 1048575 ))
|
||||||
|
then
|
||||||
|
size=$(( (size * 1000) / 1048576 ))
|
||||||
|
int=$(( size / 1000 ))
|
||||||
|
if (( ${#int} > 2 ))
|
||||||
|
then
|
||||||
|
sizes+=( "$(printf %4sM $int)" )
|
||||||
|
else
|
||||||
|
sizes+=( "$(
|
||||||
|
printf %2s.%.1sM\
|
||||||
|
$int \
|
||||||
|
${size#int}
|
||||||
|
)" )
|
||||||
|
fi
|
||||||
|
suffix=M
|
||||||
|
elif (( size > 1023 ))
|
||||||
|
then
|
||||||
|
size=$(( (size * 1000) / 1024 ))
|
||||||
|
int=$(( size / 1000 ))
|
||||||
|
if (( ${#int} > 2 ))
|
||||||
|
then
|
||||||
|
sizes+=( "$(printf %4sk $int)" )
|
||||||
|
else
|
||||||
|
sizes+=( "$(
|
||||||
|
printf %2s.%.1sk\
|
||||||
|
$int \
|
||||||
|
${size#int}
|
||||||
|
)" )
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
size=$size
|
||||||
|
sizes+=( "$(printf "%4s " $size)" )
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
head=$(
|
||||||
|
printf "| %-${maxtypelen}s | %'${maxcountlen}s | %% | Size |"\
|
||||||
|
Format Count
|
||||||
|
)
|
||||||
|
sep=${head//[^|]/-}
|
||||||
|
sep=${sep//\|/+}
|
||||||
|
echo "$sep"
|
||||||
|
echo "$head"
|
||||||
|
echo "$sep"
|
||||||
|
for id in ${!types[@]}
|
||||||
|
do
|
||||||
|
printf "| %-${maxtypelen}s | %'${maxcountlen}i | %3i%% | %5s |\n"\
|
||||||
|
"${types[id]}" \
|
||||||
|
"${counts[id]}" \
|
||||||
|
$(( ${counts[id]} * 100 / totalcount )) \
|
||||||
|
"${sizes[id]}"
|
||||||
|
echo "$sep"
|
||||||
|
done
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user