Add robust error handling.

This commit is contained in:
Emre AKYÜZ 2023-11-19 02:37:42 +03:00 committed by GitHub
parent e15f5ee6df
commit 3ba7e6da11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,9 +4,18 @@ while ! ping -c 1 9.9.9.9 > /dev/null 2>&1; do sleep 0.5; done
DATA_DIR="$HOME/.cache/youtube_channels"
CHANNEL_LIST="$HOME/.local/share/channels.txt"
mkdir -p "$DATA_DIR"; touch $CHANNEL_LIST
mkdir -p "$DATA_DIR" && touch "$CHANNEL_LIST"
[ ! -s $CHANNEL_LIST ] && notify-send "You don't have any channels in "channels.txt". Refer to documentation."
error_handling() {
[ -s "$CHANNEL_LIST" ] || {
notify-send "You don't have any channels in 'channels.txt'."
exit 1
}
grep -q "^.*=https://www.youtube.com/@[[:alnum:]]*/videos$" "$CHANNEL_LIST" || {
notify-send "'channels.txt' formatting is wrong."
exit 1
}
}
compare_data() {
local channel_name="$1"
@ -49,4 +58,5 @@ update_all_channels() {
done < "$CHANNEL_LIST"
}
error_handling
update_all_channels