-
-
Save glutanimate/413c7e0a61b826d687a1 to your computer and use it in GitHub Desktop.
MoodyRain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# MoodyRain by Glutanimate | |
# License: GNU GPLv3 | |
# Dependencies: yad, vlc | |
# | |
# All streams linked to in this script are the property of their respective owners. | |
# | |
# Using a different audio player: | |
# | |
# Replace the cvlc command-line with one of the following | |
# - mpv --loop=inf --vo null --volume="$Volume" --gapless-audio=yes "$i" #> /dev/null 2>&1 & | |
# - avplay -loop 0 -nodisp -autoexit "$i" > /dev/null 2>&1 & | |
# | |
# Using local files: | |
# | |
# place files with the same name as the streams in 'ambient_sounds' directory next to script | |
# (e.g. ./ambient_sounds/RainyMood.ogg) | |
# Variables | |
Executable="$(readlink -f "$0")" | |
ProgDir="${Executable%/*}" | |
SoundDir="$ProgDir/ambient_sounds" | |
StreamUrl=("http://174.36.223.28/audio1110/RainyMood.ogg" \ | |
"http://st2.asoftmurmur.com/beta/main-thunder.mp4" \ | |
"http://st3.asoftmurmur.com/beta/main-sbowl.mp4" \ | |
"http://st1.asoftmurmur.com/beta/main-birds.mp4" \ | |
"http://st3.asoftmurmur.com/beta/main-wind.mp4" \ | |
"http://st1.asoftmurmur.com/beta/main-whitenoise.mp4" \ | |
"http://st3.asoftmurmur.com/beta/main-waves.mp4" \ | |
"http://st1.asoftmurmur.com/beta/main-rain.mp4" \ | |
"http://st2.asoftmurmur.com/beta/main-people.mp4" \ | |
"http://st3.asoftmurmur.com/beta/main-fire.mp4" \ | |
"http://st2.asoftmurmur.com/beta/main-crickets.mp4" \ | |
"http://augustambience.com/night.mp3" \ | |
"http://www.soundrown.com/Audio/Final%20Normalized/mp33/FireFinal15.mp3" \ | |
"http://coffitivity.com/sounds/audio/mp3/morningMurmur_mp3.mp3" \ | |
"http://coffitivity.com/sounds/audio/mp3/lunchtimeLounge_mp3.mp3" \ | |
"http://coffitivity.com/sounds/audio/mp3/universityUndertones_mp3.mp3") | |
StreamName=("rainymood.com - Rainy Mood" \ | |
"A Soft Murmur - Thunder" \ | |
"A Soft Murmur - Singing Bowl" \ | |
"A Soft Murmur - Birds" \ | |
"A Soft Murmur - Wind (short)" \ | |
"A Soft Murmur - White Noise (short)" \ | |
"A Soft Murmur - Waves (short)" \ | |
"A Soft Murmur - Rain (short)" \ | |
"A Soft Murmur - People (short)" \ | |
"A Soft Murmur - Fire (short)" \ | |
"A Soft Murmur - Crickets (short)" \ | |
"August ambience - August Night" \ | |
"Soundrown - Fire" \ | |
"Coffitivity - Morning Murmur" \ | |
"Coffitivity - Lunchtime Lounge"\ | |
"Coffitivity - University Undertones") | |
Volume="100" | |
# Gui | |
YadTitle="MoodyRain" | |
TrayIcon="rhythmbox-panel" | |
GuiTxtDescr="Please select one or multiple ambient sounds. Internet connection required!" | |
GuiTxtPlay="Play selected streams" | |
GuiTxtCancel="Cancel and quit" | |
WmIcon="gnome-audio" | |
ThumbIcon="gnome-audio" | |
# Functions | |
gui_streamsel () { | |
YadChoices="$(\ | |
for i in "${!StreamUrl[@]}"; do | |
echo "FALSE" | |
echo "${StreamName[$i]}" | |
echo "${StreamUrl[$i]}" | |
done | \ | |
yad --list --checklist \ | |
--title="$YadTitle" \ | |
--class="$WmClass" \ | |
--text="$GuiTxtDescr" \ | |
--window-icon="$WmIcon" \ | |
--image="$ThumbIcon" \ | |
--print-all --multiple \ | |
--width=800 --height=400 --center \ | |
--button="_Play!gtk-media-play-ltr!$GuiTxtPlay":2 \ | |
--button="_Cancel!gtk-close!$GuiTxtCancel":1 \ | |
--column="Choose" \ | |
--column="Stream":TEXT --column="Stream URL":TEXT \ | |
)" | |
YadChoicesRet="$?" | |
Playlist=($(echo "$YadChoices" | grep "TRUE" | cut -d '|' -f 3)) | |
Sounds=($(echo "$YadChoices" | grep "TRUE" | cut -d '|' -f 2 | awk -F '\n' '{print $1", "}')) | |
if [[ "$YadChoicesRet" != "2" || -z "$Playlist" ]]; then | |
echo "Aborted." | |
exit 1 | |
fi | |
} | |
gui_systray () { | |
yad --notification \ | |
--text="MoodyRain" \ | |
--image="$TrayIcon" \ | |
--command="notify-send -i $ThumbIcon 'MoodyRain' 'Ambient sounds: ${Sounds[*]}'" \ | |
--menu="Stream selection!bash -c gui_systray_onclick!$ThumbIcon|Exit!kill -s TERM $TopPid!exit"& | |
YadPid="$!" | |
} | |
gui_systray_onclick(){ | |
kill -s TERM "$TopPid" | |
"$TopScript" > /dev/null 2>&1 & | |
} | |
player(){ | |
for i in "${Playlist[@]}"; do | |
# prefer local data | |
if [[ -f "$SoundDir/${i##*/}" ]]; then | |
PlaylistItem="$SoundDir/${i##*/}" | |
echo "Playing local file $PlaylistItem" | |
else | |
PlaylistItem="$i" | |
echo "Playing remote stream $PlaylistItem" | |
fi | |
cvlc --repeat --volume=$((256*Volume/100)) --play-and-exit "$PlaylistItem" > /dev/null 2>&1 & | |
PlayerPids+=("$!") | |
done | |
wait "${PlayerPids[0]}" | |
} | |
cleanup(){ | |
for i in "${PlayerPids[@]}"; do | |
kill -s TERM "$i" | |
done | |
kill -s TERM "$YadPid" | |
kill -s TERM "$TopPid" | |
} | |
# Preamble | |
export -f gui_systray_onclick | |
export TopScript="$0" | |
export TopPid=$$ | |
PlayerPids=() | |
trap "cleanup; exit" EXIT | |
# Main | |
gui_streamsel | |
gui_systray | |
player |
Yeah, you did a fantastic job with the edits. So far I've only been able to discern a repetitive pattern in the thunderstorm sample.
I'm not really happy with that one, I'll try to find a long and nice rolling thunder sound when I have the time.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Huh, I must say I am quite surprised that
file
behaves differently on Arch. Thanks for the pointer! It should be fixed nowYeah, you did a fantastic job with the edits. So far I've only been able to discern a repetitive pattern in the thunderstorm sample.