|
|
media-stats.sh - bitreich-memestats - Bitreich meme statistics and graphs. |
|
|
 |
git clone git://bitreich.org/bitreich-memestats git://hg6vgqziawt5s4dj.onion/bitreich-memestats (git://bitreich.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
Tags |
|
|
 |
LICENSE |
|
|
|
--- |
|
|
|
media-stats.sh (2711B) |
|
|
|
--- |
|
|
|
1 #!/bin/sh |
|
|
|
2 # output formatted table with memecache media statistics |
|
|
|
3 |
|
|
|
4 # estimated average image viewing time [s] |
|
|
|
5 img_viewing_time=5 |
|
|
|
6 |
|
|
|
7 if [ $# -ne 1 ]; then |
|
|
|
8 printf 'usage: %s <memecache_path>\n' "$0" >&2 |
|
|
|
9 exit 1 |
|
|
|
10 fi |
|
|
|
11 |
|
|
|
12 oldpathfile="memecache_pathcache.txt.old" |
|
|
|
13 touch "${oldpathfile}" |
|
|
|
14 oldstatusfile="${oldpathfile}.status" |
|
|
|
15 todofile="memecache_pathcache.txt.todo" |
|
|
|
16 touch "${todofile}" |
|
|
|
17 pathfile="memecache_pathcache.txt" |
|
|
|
18 |
|
|
|
19 find "$1" \ |
|
|
|
20 -maxdepth 1 \ |
|
|
|
21 -type f \ |
|
|
|
22 \! \( -name '*.orig' \ |
|
|
|
23 -o -name '*.nochip' \ |
|
|
|
24 -o -name '*.txt' \ |
|
|
|
25 -o -name '*.meme' \ |
|
|
|
26 -o -name '*.pdf' \ |
|
|
|
27 \) \ |
|
|
|
28 | sort > "${pathfile}" |
|
|
|
29 comm -3 "${pathfile}" "${oldpathfile}" > "${todofile}" |
|
|
|
30 |
|
|
|
31 i=0 |
|
|
|
32 sum=0.0 |
|
|
|
33 # Get state. |
|
|
|
34 if [ -e "${oldstatusfile}" ]; then |
|
|
|
35 sum="$(head -n 1 "${oldstatusfile}")" |
|
|
|
36 i="$(tail -n 1 "${oldstatusfile}")" |
|
|
|
37 fi |
|
|
|
38 |
|
|
|
39 # Old work on diff. |
|
|
|
40 fifofile="$(mktemp -u media-stats.fifo.XXXXXX)" |
|
|
|
41 mkfifo ${fifofile} |
|
|
|
42 grep '.*mkv$\|.*mp4$\|.*webm$\|.*mp3$\|.*ogg$' "${todofile}" \ |
|
|
|
43 2>/dev/null >${fifofile} & |
|
|
|
44 while read -r f; do |
|
|
|
45 i=$((i+=1)) |
|
|
|
46 new_sum="$(printf '%f + %f\n' \ |
|
|
|
47 "$(ffprobe -v error -show_entries format=duration \ |
|
|
|
48 -of default=noprint_wrappers=1:nokey=1 "$f")" "$sum" 2>/dev/null | \ |
|
|
|
49 bc -l)" |
|
|
|
50 sum="$new_sum" |
|
|
|
51 done < ${fifofile} |
|
|
|
52 rm -f ${fifofile} |
|
|
|
53 |
|
|
|
54 # Store state. |
|
|
|
55 cp "${pathfile}" "${oldpathfile}" |
|
|
|
56 printf "%f\n%i\n" "${sum}" "${i}" > "${oldstatusfile}" |
|
|
|
57 |
|
|
|
58 n_img="$(grep '.*png$\|.*jpg$\|.*JPG$\|.*gif$' "${pathfile}" \ |
|
|
|
59 2>/dev/null | wc -l)" |
|
|
|
60 n_vid="$(grep '.*mkv$\|.*mp4$\|.*webm$\|.*mp3$|.*ogg$' "${pathfile}" \ |
|
|
|
61 2>/dev/null | wc -l)" |
|
|
|
62 n_emoji="$(find /br/gopher/emoji/ -maxdepth 1 -type f \! -name '*.orig' | wc -l)" |
|
|
|
63 n_filter="$(find /br/gopher/memecache/filter/ -maxdepth 1 -type f | wc -l)" |
|
|
|
64 |
|
|
|
65 printf '\n ' |
|
|
|
66 printf '+----- statistics (%s) ------+\n' "$(date '+%Y-%m-%d')" |
|
|
|
67 printf ' ' |
|
|
|
68 printf '| number of images: %8s |\n' "$n_img" |
|
|
|
69 printf ' ' |
|
|
|
70 printf '| number of movies: %8s |\n' "$n_vid" |
|
|
|
71 printf ' ' |
|
|
|
72 printf '| number of emojis: %8s |\n' "$n_emoji" |
|
|
|
73 printf ' ' |
|
|
|
74 printf '| number of filters: %8s |\n' "$n_filter" |
|
|
|
75 printf ' ' |
|
|
|
76 printf '| average movie length: %10.1f s |\n' \ |
|
|
|
77 "$(printf '%f/%f\n' "$sum" "$i" | bc -l)" |
|
|
|
78 printf ' ' |
|
|
|
79 printf '| total image viewing time: %6.1f h |\n' \ |
|
|
|
80 "$(printf '(%s+%s)*%f/3600\n' "$n_img" "$n_emoji" "$img_viewing_time" | bc -l)" |
|
|
|
81 printf ' ' |
|
|
|
82 printf '| (assuming %d s per image) |\n' "$img_viewing_time" |
|
|
|
83 printf ' ' |
|
|
|
84 printf '| total movie length: %10.1f h |\n' \ |
|
|
|
85 "$(printf '%s/3600\n' "$sum" | bc -l)" |
|
|
|
86 printf ' ' |
|
|
|
87 printf '+------------------------------------+\n' |
|
|
|
88 |
|