Skip to content

Instantly share code, notes, and snippets.

@nperez0111
Last active May 16, 2020 21:11
Show Gist options
  • Save nperez0111/2ad48cf5bee2f10a8478 to your computer and use it in GitHub Desktop.
Save nperez0111/2ad48cf5bee2f10a8478 to your computer and use it in GitHub Desktop.
Pianobar configuration.

Pianobar Installer Scripts and Guide

====================================== These Scripts Help Install Pianobar (A Command Line Pandora Player) onto Windows and Mac OS X. For Mac I've written a bash script that can be copied and pasted into a terminal emulator of your choice to install pianobar and fix some settings.

The funtionality of the scripts are as follows:

  • Fixes a warning that comes up because of an out of date audio library (libao)
  • Sets up Auto Login to pianobar using your pandora account ( Otherwise you would have to provide your username and password on every instance of pianobar )
  • Sets up Auto Start Station which on start of pianobar will allow you to start a station you set automatically ( otherwise you would need to select the station on every restart of pianobar)
  • If you use the advanced installer it will allow for you to set up notifications on changing the song to mac os x banners. And even show album cover art so you know exactly what song is playing without having to go back into the console

Mac Install Simple (Shell Script)

This will install pianobar and setup autologin.

bash <(curl -s https://raw.githubusercontent.com/nperez0111/pianobar-installer/master/pianobar-Mac-Simple.sh)

Mac Install Advanced (Shell Script) - Adds Notifications

This will install pianobar, setup autologin and add notifications.

bash <(curl -s https://raw.githubusercontent.com/nperez0111/pianobar-installer/master/pianobar-Mac-Advanced.sh)

Windows Install

Make a file called pianobar.cfg in the same directory that pianobar.exe is in and copy these contents in. Changing as you please.

Setting Up Auto Start Station

  1. If you want a certain station to start every time you open pianobar open up the pandora web player( pandora.com ).
  2. Select a station you want to be as the auto starting station.
  3. Copy the URL it will look something like this http://www.pandora.com/station/play/3195239640586748282 take the mess of numbers at the end and copy that into the pianobar config and that station will now always start with pianobar.

Mac Install (Manually)

cd ~/.config && mkdir pianobar && cd pianobar && touch config && subl config

What this does is:

  1. cd into .config folder
  2. make a directory called pianobar if it does not exist and cd into it
  3. makes a file called config which stores the configuration
  4. uses sublime text to open the config file subl can be replaced with open to use any editor you like
  5. Copy and paste the contents of pianobar.cfg into the file and save. Change as you please.

Take out width and height lines as they dont apply in Mac OS

Extended Mac Install (Manually)

This section will add notifications to pianobar that come up through notification center. Letting you know when the next song is playing.

touch pianobarNotify.rb && subl pianobarNotify.rb && defaults write /usr/local/Cellar/terminal-notifier/1.6.3/terminal-notifier.app/Contents/Info.plist NSAppTransportSecurity '<dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>'

What this does:

  1. Create a file called pianobarNotify.rb.
  2. Sublime Text to edit the new file.
  3. All the crazy stuff at the end is just to change a setting to allow terminal notifications to include the cover art photo. If not run it will simply not show the cover art. What you need to do:
  4. Paste in the contents of pianobarNotify.rb into your sublime text window close and save
  5. open the config file you made prior (Located as:~/.config/pianobar/config or reopen it simply with subl ~/.config/pianobar/config)
  6. Add this Line event_command = ~/.config/pianobar/pianobarNotify.rb
  7. If you want a custom pandora icon change ~/.config/pianobar/PandoraIco.png to be the location of your icon in every occurence in the pianobarNotify.rb file
#!/bin/sh
# Advanced Version does use notifications
command_exists () {
type "$1" &> /dev/null ;
}
rmv () {
if [ -f $1 ]
then
rm -f $1
fi
}
read -p "Do you want to run the Simple Installer (This runs the installer for pianobar and fixes warnings and sets up auto login auto start station)? (Y/n)" answer
case ${answer:0:1} in
"n"|"N")
echo "Simple Installer will not run..."
;;
*)
echo "Running Simple Script..."
bash <(curl -s https://raw.githubusercontent.com/nperez0111/pianobar-installer/master/pianobar-Mac-Simple.sh)
echo "Simple Script Installed Pianobar Successfully."
;;
esac
if command_exists terminal-notifier; then
#Pianobar is fine so we do nothing and continue script
echo "Terminal-Notifier exists. Awesome..."
else
printf "Terminal-Notifier Installing..."
brew update >/dev/null
brew install terminal-notifier >/dev/null
printf "Successfully Installed\n"
fi
read -p "Do you want to make Notifications Last Longer? (Y/n)?" answer
case ${answer:0:1} in
"n"|"N")
defaults delete com.apple.notificationcenterui bannerTime
echo "Notification Timing Will not be set"
;;
*)
printf "Writing Notification time to 10 seconds..."
defaults write com.apple.notificationcenterui bannerTime 10
printf "OK\n"
;;
esac
#Handle Images
read -p "Do you want a specific image to show in each notification? (y/N)" answe
case ${answe:0:1} in
"y"|"Y")
printf "Please enter the file path of the image you would like as the icon of each notification: \n"
read imgFilePath
image="-appIcon \"${imgFilePath}\""
;;
*)
image=""
;;
esac
#Handle Terminal
read -p "Do you want pianobar to show on click of notification (Y/n)" answ
case ${answ:0:1} in
"y"|"Y")
echo "1)iTerm2"
echo "2)Terminal"
echo "3)HyperTerm"
read -p "Is your Terminal shown in this list? (Y/n)" answer
case ${answer:0:1} in
"y"|"Y")
#terminal is in list ask index
printf "Please enter the number of the terminal in the list above:\n"
read num
case ${num:0:1} in
1)
termApp="com.googlecode.iterm2"
echo "iTerm2 Selected"
;;
2)
termApp="com.apple.terminal"
echo "Terminal Selected"
;;
3)
termApp="co.zeit.hyperterm"
echo "HyperTerm Selected"
;;
*)
echo "Not valid value. Exiting..."
exit 1;
;;
esac
;;
*)
#terminal is not shown so must do a prompt for the bundle id
printf "Please enter the name of the terminal program you use.\n"
read termProgram
termApp="$(osascript -e "id of app \"${termProgram}\"")"
echo "The Bundle ID we found was:${termApp}"
;;
esac
showTerm="-activate \"${termApp}\""
;;
*)
showTerm=""
echo "No action will be performed on click of notification..."
;;
esac
cd ~/.config/pianobar
printf "Removing old Notification Script..."
rmv pianobarNotify.rb
printf "OK\n"
#Actually write file
printf "Writng Notification Script..."
cat <<EOT >> pianobarNotify.rb
#!/usr/bin/ruby
trigger = ARGV.shift
if trigger == 'songstart'
songinfo = {}
STDIN.each_line { |line| songinfo.store(*line.chomp.split('=', 2))}
\`terminal-notifier -title "#{songinfo['title']}" -subtitle "By: #{songinfo['artist']}" -group "Pianobar" ${image} ${showTerm} -message "Album: #{songinfo['album']} on #{songinfo['stationName']}" -contentImage "#{songinfo['coverArt']}"\`
elsif trigger == 'userlogin'
\`
rm "~/.config/pianobar/ctl" 2> /dev/null
mkfifo "~/.config/pianobar/ctl"
terminal-notifier -title "Pianobar Started" -message "Welcome back" -group "Pianobar" ${image}
\`
elsif trigger == 'stationfetchplaylist'
\`terminal-notifier -title "Fetching songs..." -message "Changing stations" -group "Pianobar" ${image}\`
end
EOT
printf "OK\n"
chmod +x pianobarNotify.rb
printf "Writing to config file..."
cat <<EOT >> config
event_command = ~/.config/pianobar/pianobarNotify.rb
fifo = ~/.config/pianobar/ctl
EOT
printf "OK\n"
printf "Writing setting to terminal-notifier..."
defaults write /usr/local/Cellar/terminal-notifier/1.6.3/terminal-notifier.app/Contents/Info.plist NSAppTransportSecurity '<dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>'
printf "OK\n"
echo "Success..."
read -p "Do you want to control Pianobar through shortcuts? (Y/n)" answe
case ${answe:0:1} in
"n"|"N")
echo "I thought it was pretty cool..."
;;
*)
echo "There will be a bunch of bubbles popping up asking you to be ok with installing various services. These Services run commands to control pianobar without being in the terminal window. And can be assigned to global shortcuts from Settings > KeyBoard > Shortcuts > Services."
;;
esac
read -p "Do you want to run pianobar now? (Y/n)" answe
case ${answe:0:1} in
"n"|"N")
exit 0;
;;
*)
echo "Pianobar Starting...."
echo ""
echo ""
pianobar
;;
esac
exit 0;
#!/bin/sh
# Simple Version does not use notifications
command_exists () {
type "$1" &> /dev/null ;
}
rmv () {
if [ -f $1 ]
then
rm -f $1
fi
}
fixLibao () {
rmv /usr/local/Library/Formula/libao.rb
cat <<EOT >> /usr/local/Library/Formula/libao.rb
class Libao < Formula
desc "Cross-platform Audio Library"
homepage "https://www.xiph.org/ao/"
url "https://git.xiph.org/?p=libao.git;a=snapshot;h=18dc25cd129a7e5a9669cbdd9b076f58063606a2;sf=tgz"
sha256 "c4a1c2caac8dff249003338e20df2b614cf59e9f5c3b33c663ef8b627a370062"
version "1.2.0-snapshot-18dc25c"
bottle do
revision 1
sha256 "159aa7704f0a3cd36bfdf659ca8ec9c399077274bff1b68aa0497fdda8b6da44" => :el_capitan
sha256 "08d568c4bed498b2920983d9b848213779164c15489c82cc61429533337d19f5" => :yosemite
sha256 "81b1d6c5d1920092fba0470db2840414eb99bba8ec63d6d22800e79090db8e4b" => :mavericks
sha256 "21aa15e92c5577a4a610de8fbb3f5a72638a0c37a40c4ebebc14826359932efa" => :mountain_lion
end
depends_on "pkg-config" => :build
depends_on "automake" => :build
depends_on "autoconf" => :build
depends_on "libtool" => :build
def install
system "AUTOMAKE_FLAGS=--include-deps ./autogen.sh"
system "./configure", "--disable-dependency-tracking",
"--prefix=#{prefix}",
"--enable-static"
system "make", "install"
end
end
EOT
brew remove libao >/dev/null
brew install libao >/dev/null
}
if command_exists pianobar; then
#Pianobar is fine so we do nothing and continue script
echo "Pianobar exists: Awesome..."
else
if command_exists brew; then
#Pianobar is not available but brew is so
printf "Installing Pianobar..."
brew install pianobar
printf "Successfully Installed\n"
else
#Neither Pianobar or Brew is installed so install both despite making the proccess longer
echo "Installing Homebrew"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Homebrew Installed Successfully"
printf "Updating Brew..."
brew update >/dev/null
printf "OK\n"
printf "Installing Pianobar..."
brew install pianobar >/dev/null
printf "Successfully Installed\n"
fi
fi
if command_exists pianobar; then
#Pianobar is fine so keep going
echo "If you have never run this program before please run this. Only not fix warnings if you know what you are doing!"
read -p "Do you want to fix audio warnings (Y/n)?" answer
case ${answer:0:1} in
"n"|"N")
echo "Not going to fix audio warnings..."
;;
*)
echo "Fixing audio Warnings..."
fixLibao
echo "Audio Warnings Fixed..."
;;
esac
else
echo "Something went wrong now exiting..."
echo "Check if Pianobar is Installed."
exit 1
fi
cd ~/.config
mkdir pianobar
cd pianobar
printf "\n The autostart station can be found by either: \n * Running pianobar pressing 's' to change the station to the station you would like to auto start.\n * Then note the number that shows next to said station. \n\n OR \n\n By going into the web player select the station you would like to autostart \n * note the numbers at the end of the URL?\n"
read -p "Do you have an autostart station ready (y/N)" answer
case ${answer:0:1} in
"y"|"Y")
echo "Please enter the autostart station you have prepared: "
read autostart
;;
*)
echo "Default Autostart Station will be applied"
autostart="814524665525141882"
;;
esac
echo "Please enter user name for pandora (For Auto-login): "
read username
echo "Please Enter pandora password (For Auto-Login): "
read password
rmv config
cat <<EOT >> config
user = ${username}
password = ${password}
autostart_station = ${autostart}
format_nowplaying_song = %t, by: %a on the album: %l %r%@%s
format_nowplaying_station = Now Playing "%n" (%i)
format_list_song = %i) %a - %t%r
format_msg_info = (i) %s
format_msg_nowplaying = > %s
format_msg_time = # %s
format_msg_err = /!\ %s
format_msg_question = [?] %s
format_msg_debug = %s
EOT
echo "Success..."
exit 0
user = nperez0111@gmail.com
password =
autostart_station = 814524665525141882
width = 200
height = 50
format_nowplaying_song = %t, by: %a on the album: %l %r%@%s
format_nowplaying_station = Now Playing "%n" (%i)
format_list_song = %i) %a - %t%r
format_msg_info = (i) %s
format_msg_nowplaying = > %s
format_msg_time = # %s
format_msg_err = /!\ %s
format_msg_question = [?] %s
format_msg_debug = %s
#!/usr/bin/ruby
trigger = ARGV.shift
appIcon = "~/.config/pianobar/PandoraIco.png"
defaultTerminal = "com.apple.terminal"
#com.googlecode.iterm2 for iterm2
songinfo = {}
STDIN.each_line { |line| songinfo.store(*line.chomp.split('=', 2))}
if trigger == 'songstart'
`terminal-notifier -title "#{songinfo['title']}" -subtitle "By:#{songinfo['artist']}" -group "Pianobar" -appIcon "#{appIcon}" -activate "#{defaultTerminal}" -message "Album:#{songinfo['album']} on #{songinfo['stationName']}" -contentImage "#{songinfo['coverArt']}"`
elsif trigger == 'userlogin'
`terminal-notifier -title "Pianobar Started" -message "Welcome back" -group "Pianobar" -appIcon "#{appIcon}"`
elsif trigger == 'stationfetchplaylist'
`terminal-notifier -title "Fetching songs..." -message "Changing stations" -group "Pianobar" -appIcon "#{appIcon}"`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment