Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active August 18, 2023 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AfroThundr3007730/126c3c56b69526cbe93acbcdb8a9f0ca to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/126c3c56b69526cbe93acbcdb8a9f0ca to your computer and use it in GitHub Desktop.
Parses chatterino logs to get stream income from bits and subscriptions
#!/bin/bash
# Parses chatterino logs to get stream income from bits and subscriptions
get_stream_stats() {
local f=${1##*/}; f=${f%.*}
printf 'Channel: %s Date: %s\n' "${f%%-*}" "${f#*-}"
awk '/[Cc]heer/ {
for (i = 1; i <= NF; i++) {
if ($i ~ /^[Cc]heer$/) {
j = i + 1
token = $i $j
} else { token = $i }
match(token, /[Cc]heer([0-9]+)/, bit)
bits += bit[1]
}
} /subscribed/ {
match($0, /subscribed at Tier ([1-3])|subscribed with (Prime)/, tier)
subs[tier[1]]++
} /gifting/ {
match($0, /is gifting ([0-9]+) Tier ([1-3]) Subs to/, gift)
gifts[gift[2]] += gift[1]
} $2 ~ /streamelements:/ && /just tipped/ {
match($0, /just tipped \$([0-9\.]+)/, tip)
tips++
tipi += (tip[1] - .3) * .97
} $2 ~ /soundalerts:/ && /play/ {
match($0, /played .+ for ([0-9]+) Bits|used ([0-9]+) Bits to play/, abit)
alerts++
abits += abit[1] + abit[2]
} END {
printf("\nStream statistics:\n")
printf("%13s %\47-5d\t%14s %\47-8d\n",
"Prime Subs:", subs[""], "Cheered Bits:", bits)
for (i = 1; i <= 3; i++) {
printf("%13s %\47-5d\t%14s %\47-5d\n",
"Tier " i " Subs:", subs[i], "Tier " i " Gifted:", gifts[i])
}
printf("%13s %\47-5d\t%14s %\47-5d\n",
"SE Tips:", tips, "Sound Alerts:", alerts)
biti = bits / 100
subi = (subs[""] * 5 + subs[1] * 5 + subs[2] * 10 + subs[3] * 25) * .5
gifti = (gifts[1] * 5 + gifts[2] * 10 + gifts[3] * 25) * .5
abiti = abits / 100 * .8
printf("\nEstimated stream income:\n")
printf("%15s\t$%\47 10.2f\n", "Bit Cheers:", biti)
printf("%15s\t$%\47 10.2f\n", "Subscriptions:", subi)
printf("%15s\t$%\47 10.2f\n", "Gifted Subs:", gifti)
printf("%15s\t$%\47 10.2f\n", "SE Tips:", tipi)
printf("%15s\t$%\47 10.2f\n", "Sound Alerts:", abiti)
printf("%15s\t$%\47 10.2f\n",
"Total Income:", biti + subi + gifti + tipi + abiti)
}' "$1"
printf '\nUsing rates:\n\tBits: 1.0, Subs: 0.5, Tips: 0.97, Alerts: 0.8\n'
}
# Only execute if not being sourced
[[ ${BASH_SOURCE[0]} == "$0" ]] && get_stream_stats "$@"
@AfroThundr3007730
Copy link
Author

AfroThundr3007730 commented Sep 18, 2022

Usage: get_stream_stats ~/.local/share/chatterino/Logs/Twitch/Channel/<channel>/<channel-yyyy-mm-dd>.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment