bash_tv/common.sh

60 lines
852 B
Bash
Raw Normal View History

#!/bin/bash
if [ ! -f .env ]; then
cp default.env .env
fi
source .env
if [ ! -d "${INPUT}" ]; then
mkdir -p "${INPUT}"
fi
if [ ! -d "${VIDEOS}" ]; then
mkdir -p "${VIDEOS}"
fi
HISTORY_SETUP="CREATE TABLE IF NOT EXISTS history (
video VARCHAR PRIMARY KEY,
playcount INT DEFAULT 0,
last INT
)"
PLAYBACK_SETUP="CREATE TABLE IF NOT EXISTS playback (
video VARCHAR PRIMARY KEY
)"
SetupHistory () {
echo "${HISTORY_SETUP}" | sqlite3 "${HISTORY}"
}
WipeHistory () {
rm -f "${HISTORY}"
}
SetupPlayback () {
echo "${PLAYBACK_SETUP}" | sqlite3 "${PLAYBACK}"
}
WipePlayback () {
rm -f "${PLAYBACK}"
}
GetRandom () {
QUERY="SELECT video FROM playback ORDER BY RANDOM() LIMIT 1;"
sqlite3 "${HISTORY}" "${QUERY}"
}
UpdateHistory () {
QUERY="INSERT INTO"
}
PDB () {
sqlite3 "${PLAYBACK}" "${1}"
}
HDB () {
sqlite3 "${HISTORY}" "${1}"
}