youtube-urls-feed/scripts/collect-vids.sh
Eliezer Croitoru 4eac4f6df1 3
2024-08-18 08:24:46 +03:00

34 lines
681 B
Bash

#!/usr/bin/env bash
function collect () {
PREFIX="$1"
VID_TEMPLATE_FILE="templates/vid-template.txt"
TMP_FILE=$( mktemp )
echo "${TMP_FILE}"
cat ${PREFIX}-videoids/*.txt | xargs -I{} sed -e "s@###VID###@{}@g" "${VID_TEMPLATE_FILE}" >> "${TMP_FILE}"
cat ${PREFIX}-channels/*.txt | xargs -I{} sed -e "s@###VID###@{}@g" "${VID_TEMPLATE_FILE}" >> "${TMP_FILE}"
diff "${PREFIX}.txt" "${TMP_FILE}" >/dev/null
RES="$?"
if [ "${RES}" -gt "0" ]
then
mv -vf "${PREFIX}.txt" "${PREFIX}.txt.old" && \
cp -vf "${TMP_FILE}" "${PREFIX}.txt" && \
rm -vf "${PREFIX}.txt.old"
fi
rm -vf "${TMP_FILE}"
}
arr=("allowed" "blocked")
for i in "${arr[@]}"
do
collect "$i"
done