Pianobar: Setup Notification and get lyrics for now playing

Please look at my earlier post for install and configuring Pianobar.

I’m going to setup mac osx notification center to get notification of now playing song which will include Title, Artist and Album. Let’s go back to the Pianobar config file and add event_command as below. What we are doing here? get info from Pianobar of every event and run the specified script. In this case on every event it’s going launch the base script eventcommand.sh

event_command = /Users/yourusername/.config/pianobar/eventcommand.sh

Let’s create the file

touch ~/.config/pianobar/eventcommand.sh
nano ~/.config/pianobar/eventcommand.sh

Copy and the following in the editor and save it.

	#!/bin/bash

	fold="$HOME/.config/pianobar"
	ctlf="$fold/ctl"
	nowplaying="$fold/lyrics.sh"
	while read L; do
	        k="`echo "$L" | cut -d '=' -f 1`"
	        v="`echo "$L" | cut -d '=' -f 2`"
	        export "$k=$v"
	done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|songDuration\|songPlayed\|coverArt\|stationCount\|station[0-9]\+\)=' /dev/stdin)

	case "$1" in
	        songstart)
			/usr/bin/terminal-notifier -subtitle  "Artist: $artist" -message "Album: $album" -title "$title"
	;;
	esac

Make it executable

cd ~/.config/pianobar && chmod +x eventcommand.sh && mkfifo ctl

We have configured to get the notification but not yet lyrics. Move on further if you need lyrics.

Get lyrics

It’s hard to get lyrics directly from Pandora as I think that their API doesn’t support lyrics, but people wrote HTML extractor to get lyrics which can be found here. But I’m going to use glyr to do this job.

I followed the wiki page to compile glyr. I’ll walk the through steps that I worked well. You need to install libintl from here then follow the steps below.

In my case MacPorts always works

sudo port install sqlite3
install cmake
brew install glib

or do with Homebrew.

brew install sqlite3
brew link --force sqlite
brew install cmake
brew install glib

Download glyr from here and extract it.

cd glyr
cmake -DCMAKE_INSTALL_PREFIX=/usr .
make && sudo make install

Now you can launch glyr with glyrc and update eventcommand.sh file with the following which includes the above notification.

#!/bin/bash

fold="$HOME/.config/pianobar"
ctlf="$fold/ctl"
nowplaying="$fold/lyrics.sh"
while read L; do
        k="`echo "$L" | cut -d '=' -f 1`"
        v="`echo "$L" | cut -d '=' -f 2`"
        export "$k=$v"
done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|songDuration\|songPlayed\|coverArt\|stationCount\|station[0-9]\+\)=' /dev/stdin)

case "$1" in
        songstart)
        echo -e "glyrc lyrics -a \"$artist\" -t \"$title\" -b \"$album\" -w /tmp/" > "$nowplaying"
		/usr/bin/terminal-notifier -subtitle  "Artist: $artist" -message "Album: $album" -title "$title"
;;
esac

The above script writes out put as lyrics.sh on every event i.e., when ever new song plays. If you want to look at the lyrics of the “Now Playing Song” then open a new tap in your terminal and run the following.

sh ~/.config/pianobar/lyrics.sh

We all done.

Install pianobar and run it under proxy server “tor”

Why Pianobar

Well, do you know Pandora uses flash? if you open their web in your browser then your system is going to cry! and if you have less resource memory & CPU like then you won’t like flash in your browser.

There are more issues, like the web plays adds and audio has low bit-rate i.e., low quality. If you need high quality music i.e., 190 kbps and without any adds then you need a subsription.

But you can luckly get rid of adds and get high bit-rate audio via Pandora API. Here comes Pianobar, a free command line based client that does all you need.

Again, I followed few blogs to get it running, few of them are here; Instructables,

On linus

sudo apt-get install pianobar

on Mac

Easier way is to use either MacPorts or Homebrew. To install via MacPorts to the following

sudo port install pianobar

I’ll guide you to use Homebrew. first install Homebrew source

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
brew install pianobar

If you get error on the above installation then may be the link is dead and you need to get the updated URL. People also use different way to install them, here is another way. source

curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local

Compile manually; first install depenties and then Pianobar according to this soruce

sudo port install libao faad2 libmad cmake git-core
git clone git://github.com/PromyLOPh/pianobar.git
cd pianobar
cmake . && make && sudo make install

Now you can launch Pianobar with

pianobar

It’ll ask you to enter user name and password, following station name, like below

Welcome to pianobar! Press ? for a list of commands.
[?] Username:
[?] Password:
(i) Login… Ok.
(i) Get stations… Ok.
0) some name Radio
1) some name Radio
2) some name Radio
3) some name Radio

[?] Select station:

After the login you can press ? to view the action keys, like pressing n can choose next song.

Configure Pianobar

We can configure Pianobar with user name and password in a text file where we could also specify to use proxy and even more. By default Pianobar will look for a configuration file under ~/.config/pianobar/config, so all we have to do is to create a config file in that location.

Create .config under your home directory like below if you don’t have one.

mkdir -p ~/.config/pianobar
cd ~/.config/pianobar
touch config
nano config

Let’s add some details to the cofig file

tls_fingerprint = 2D0AFDAFA16F4B5C0A43F3CB1D4752F9535507C0
user = myemail@mail.com
password = mypassword

At this moment I don’t have more details on tls_fingerprint, but may be in future I’ll have some.

If you run pianobar on your terminal, it’s going login automatically, wow! that’s nice. Still we can do more here, let’s move on further.

Run under Proxy

If you are located outside of US then you want to use free/paid proxy server to get access to Pandora, look at my previous post deals with free proxie servers. Remember that Pianobar can handle http proxy but not the SOCKS.

Add the following at the bottem of your config file.

control_proxy = http://xxx.xxx.xxx.xxx:80

Replace xxx.xxx.xxx.xxx with the IP your found on free proxy sites and also the port number 80. Now you should able to use Pianobar from outside of US.

Ok, that looks fine, but hey! don’t you think it’s silly to edit config file on every launch?, yes it’s. There is work around for this, you can configure tor to automatically pickup the proxy.

Configure tor

For installing tor look at my earlier post, if you run it then you’ll see something like below on ~5-th line;

[notice] Opening Socks listener on 127.0.0.1:9050

So you could cofigure your Pianobar to listen to port 9050, you may expect it’s all done, but it’s not going to work because tor works on SOCKS and Pianobar doesn’t handle SOCKS and required http proxy. So what we are going to do? there are scripts around which does listen to SOCKS and forwards it to http proxy. It was very hard for me to get one working. I was trying pianobarproxy, delegate, Polipo and few more. None of them worked initially but I found a working method with Polipo and I’ll explain you here. It’s taken from different resources found here and in superuser.Install Polipo from Homebrew.

brew install Polipo

Now we need to configure Polipo to listen to tor’s port 9050 and forward it to localhost. Create a text file anywhere with the following info,

socksParentProxy = 127.0.0.1:9050
diskCacheRoot=""

Now we can tell Polipo to use this configuration file as belwo.

polipo -c ~/Downloads/config.txt

You can also add configuration file to the location /etc/polipo/config then you don’t need to specify the configuration file (source). You can also find a template here. You can do this as below.

cd /etc
sudo mkdir polipo
sudo touch config
sudo nano config

In nano editor copy and the paste the follwing and press ctrl+o and ctrl+x.

socksParentProxy = 127.0.0.1:9050
diskCacheRoot=""

Remember that Polipo default listening port is 8123 and we have add this port to Pianobar config file. Add this info.

control_proxy = http://127.0.0.1:8123

We all done, open three tabs on terminal, on one type tor, in the next one type the above Polipo command and in the last tab type pianobar, you must see Pianobar running.

Listen to Pandora from outside of US with proxy

Pandora: an internet radio can play music similar to the song or artist you like. Basically it creates a station based on your interest and plays similar songs, the more interesting part is you can say “I like this or don’t” even you can say “I tired of this” then Pandora puts on the shelf for a month. So Pandora helps you to find music of your interets.

I’m going to explain you the possible ways to access Pandora outside of US, more importantly the free approach.

Proxy servers

The best way is to use free proxy servers. Hidemyass is a good place for free proxies, but it’s tedious to configure your browser on each instance. Mediahint provides a browser plugin which automatically sets the proxy when you visit Pandora, so you don’t need search for free proxies and configure browser.

Use tor

Here I’ll walk through the installation and configuration of tor on mac and must be easier on Linux. On mac install tor from Homebrew (if you don’t have Homebrew then install it first).  I followed to OpenPandora to configure tor, this is a good place to keep eye on the discussion area.

brew install tor
cd /usr/local/Cellar/tor/0.2.3.25/etc/tor
touch torrc
nano torrc

The above method to use Homebrew sometime ends on error like couldn’t link libevent, so the alternative way to install tor is to use MacPorts as below.

sudo port install tor

Now we need to configure tor as above and the easier way to find the location for configuration file is to run tor and now you’ll see tor will say Configuration file"/opt/local/etc/tor/torrc" not present, so we got the location.

cd /opt/local/etc/tor/
sudo touch torrc
sudo nano torrc

Add the following to the nano editor and press ctrl+oenter and ctrl+x. note: I need exitnode to land in US.

StrictExitNodes 1
ExitNodes {US}

Exicute tor, now you can see tor starts running and look at nearly fifth line as below, it must be giving you output with local host (127.0.0.1) and port number on which tor is forwarding.

tor
......
......
[notice] Opening Socks listener on 127.0.0.1:9050

It’s important to note that it’s not a http proxy rather it’s socks, so you need to configure you browser to use socks proxy on port 9050, enjoy!

In the next post I’ll explaing you “how to configure pianobar to listen to Pandora.”

Nithila’s HDR image

Here’s my beautiful recent work on HDR, it’s my daughter Nithila.

This image processed from a single image ie., created three images with +1, 0, -1 exposures. My workflow includes Photomatrix for tonmapping, Topaz Denoise for denoising the tonmapped image, finally Nik siliver FX for converting into black&White image. Just compare the orginal unprocessed RAW image and the tonmapped one. It’s really awesome, yes?

Original Image

wpid-img_6029-version11-2011-12-30-17-12.jpg

Used Nik siliver FX for B&W conversion

wpid-img_6029-version10_1_2_tonemappedcopy_edited-2011-12-30-17-12.jpg

Tonemapped from three images

wpid-img_6029-version10_1_2_tonemappedcopy-2011-12-30-17-12.jpgwpid-img_6029-version10_1_2_tonemapped-2011-12-30-17-12.jpg

Port forwarding: ssh, Remote Desktop and afp

Until yesterday, It was very complicated for me to understand “what’s port forwarding? and how to setup a router to accept the incoming connections for ssh, ARD and afp”

Let me explain you my understanding here,

IP addres
there are two types of IP address
1. Static IP – permanent IP address (usually you have to pay for the provider)
2. Dynamic IP – IP changes every time you restart router (most usual one)

In general, every computer has two IP address, one is internal (private) another is external (public). Only your router knows your internal IP address and the computers that are connected to your router can communicate with your computer. In case any computer out side of your router wants to communicate your computer then it can approach you only via external IP address. For instance if you type ‘http://www.whatsmyip.org&#8217; in your web browser then it will reveal your external ip.

So whom ever has Dynamic IP address, they must have different internal (ex: 192.168.1.23) and external IP (ex: 35.129.112.111) address. However if you have a static IP address then both of them are same.

What’s the problem now? Most of the routers usually does not allow the external request to communicate the local computer via port number 22 (default ssh port) and also few other ports like 548 (afp). If you want to ssh your computer from outside then it is a problem.

Here comes port forwarding to solve this problem above. It is nothing but you will say to your router “hey forward the external port 22 request to my computer”. Now the internal IP address plays the important role. If your router connected to many computers then make sure that every computers has their unique internal IP address, if not then just change it to any.

1. Open your router configuration page in a web browser by entering http://192.168.1.1, upon requesting user name and pass, file with admin and admin. I hope most of the router has the same user name and pass, if you can’t login successfully then you must contact the manufacture.

2. Depends on router you can easily find the port forwarding page, more interestingly there’s an website which explains the port forwarding for several routers. If you are lucky then you can find your router configuration in their webiste; http://portforward.com/.

3. Here I’ll explain you the port forward configuration for SIEMENS SL2-141-I ADSL WLAN Router.

4. Open web browser, type in http://192.168.1.1 and hit enter.

5. Now the browser should ask you the user name and password. Don’t copy and paste the following username and password, it doesn’t work

username : alice@13184
passwort : hnto$mgmt@lice

3. Click on Advanced on the top of the page followed by Virtual server on the left side of the page.

4. Click on Add, choose User defined. Enter the name of the program into the User defined box. It doesn’t really matter what you put into this box, but something that will remind you why these ports are being forwarded would be a good idea. Select ALL from the From Internet Host IP Address drop down box. Enter the ip address to forward these ports to into the Forward to Internal Host IP Address box. If you are forwarding ports so you can run a program on your computer, you should enter your computer’s ip address into that box. Use the Protocol drop down box to select the protocol type of the ports you are forwarding. If you are forwarding a single port, enter that port number into the External Port Start, External Port End, Internal Port Start and Internal Port End boxes. If you are forwarding a range of ports, enter the lowest number of the range into the External Port Start and Internal Port Start boxes. Then enter the highest number of the range into the External Port End and Internal Port End boxes. When you are finished, click the Apply button.

Here’s the screen shot of my settings.

that’s all, hope it is your for you.

Useful links
http://portforward.com/
“Well known” TCP and UDP ports used by Apple software products

Other useful ARD links
“How to” access Macbook by ARD via Internet
Is there a simple/cheap way to connect to another Mac?
How to securely control another Mac over the internet Internet
Make remote tech support as simple as possible

Link_Back-Chemdraw_&_Nisus writer

&

As I’m a chemist as well as I had switch from windows to mac, I had and having few issues with mac OS. One of them is roundtrip editing of chemdraws in between word processor and chemdraw program. Also CPU and memory hook with MS-Word. I hope now this problem is solved with Nisus writer. I would say it’s an excellent word processor and I would suggest people to start using it rather than using MS-Word.

There is a pool on macresearch website (on bottom right corner) where you can pool as well as comment on the importance of this roundtrip editing as a chemist.

Tweak chemdraw tools with your favorite key

Being a advance user in chemdraw, our hands are always focusing to do less work and get more job done. Ofcourse many people already know about how to utilize the chemdraw shortcut keys (for those who is not familiar look at this link). I have modified the shortcut key script file in order to assign a key for a particular action. The interesting information for you is that we can assign a key to involve chemdraw tool, which could be one of the draw back of chemdraw.

It’s pretty easy to assign key, For example, I have assigned key “d” for Lasso and “q” for eraser tool. You can download my edited script file from here and look at them. Drop a message here, if you need more information.

Note: I did this only in mac chemdraw but not in microsoft windows and I don’t have answer about will it the same in windows or not. The hotkey.plist file can be found in /cschemdraw/chemdraw items/