refactor: extract ignored player sources to array
This commit is contained in:
+24
-9
@@ -3,34 +3,49 @@
|
|||||||
# Separator variable
|
# Separator variable
|
||||||
separator="␟"
|
separator="␟"
|
||||||
|
|
||||||
|
# Ignored player sources for music
|
||||||
|
ignored_players=(
|
||||||
|
"chromium"
|
||||||
|
"firefox"
|
||||||
|
"kdeconnect"
|
||||||
|
"haruna"
|
||||||
|
"plasma-browser-integration"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Convert array to a comma-separated string with no spaces
|
||||||
|
ignored_sources=$(
|
||||||
|
IFS=,
|
||||||
|
echo "${ignored_players[*]}"
|
||||||
|
)
|
||||||
|
|
||||||
# Lock file path
|
# Lock file path
|
||||||
lock_file="/tmp/music_wakatime_update.lock"
|
lock_file="/tmp/music_wakatime_update.lock"
|
||||||
|
|
||||||
# Create a lock file to ensure only one instance of the script runs
|
# Create a lock file to ensure only one instance of the script runs
|
||||||
if [[ -e $lock_file ]]; then
|
if [[ -e $lock_file ]]; then
|
||||||
echo "Another instance of this script is already running."
|
echo "Another instance of this script is already running."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# Create the lock file
|
# Create the lock file
|
||||||
touch "$lock_file"
|
touch "$lock_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to clean up lock file on exit
|
# Function to clean up lock file on exit
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -f "$lock_file"
|
rm -f "$lock_file"
|
||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
# Update the music cache file every second
|
# Update the music cache file every second
|
||||||
while true; do
|
while true; do
|
||||||
playerctl --ignore-player firefox,kdeconnect,haruna,plasma-browser-integration metadata --format "{{ artist }}${separator}{{ title }}${separator}{{ album }}${separator}{{ status }}${separator}{{ volume }}${separator}{{ loop }}${separator}{{ shuffle }}" >~/.cache/music_cache.txt
|
playerctl --ignore-player ${ignored_sources} metadata --format "{{ artist }}${separator}{{ title }}${separator}{{ album }}${separator}{{ status }}${separator}{{ volume }}${separator}{{ loop }}${separator}{{ shuffle }}" >~/.cache/music_cache.txt
|
||||||
sleep 1
|
sleep 1
|
||||||
done & # Run this loop in the background
|
done & # Run this loop in the background
|
||||||
|
|
||||||
# Update the Wakatime cache file every 60 seconds
|
# Update the Wakatime cache file every 60 seconds
|
||||||
while true; do
|
while true; do
|
||||||
~/.wakatime/wakatime-cli --today >~/.cache/wakatime_cache.txt 2>/dev/null
|
~/.wakatime/wakatime-cli --today >~/.cache/wakatime_cache.txt 2>/dev/null
|
||||||
sleep 60
|
sleep 60
|
||||||
done & # Run this loop in the background
|
done & # Run this loop in the background
|
||||||
|
|
||||||
# Wait for all background processes to finish
|
# Wait for all background processes to finish
|
||||||
|
|||||||
Reference in New Issue
Block a user