Меnu:


Download lyrics for the song is playing

How can I listen internet radio from the command line?

A piece of cake. You can use:

What we usually use is the radio.py script, we have added our favorite streams to it, also we have modified the mplayer invocation within the script for using pulse by default.

Why listening internet radio?

When we are learning a foreign language as the English is, it is good to improve our ear, what worked pretty well for us was listening english songs and follow them with the lyrics.

We have some time listening internet radio, it is clear for us that listening music while working could be distracting and inefficient, but sometimes we should sacrifice some efficiency for improving our performance with a foreign language. It was almost two years ago we realized the shoutcast streams started to show the name of the song and the artist2. At that moment we have the idea of doing the same Amarok that does, what Amarok does is using the id3 tag information from the playing song, Amarok fetches the lyrics from the internet. So that was the idea now we would need to get the song information from the stream, that was the difficult part after several try/error exercises we got our goal getting the song information from the stream3. Emacs has the emms-get-lyrics mode for getting the lyrics from the current song playing on emms emms]]. At the end we have coded a couple of functions for using the emms-get-lyrics mode as a backend for getting the lyrics for the song that is playing the stream.

How I should get the lyrics for the song the internet radio is playing?

For our script we have selected a couple of internet radio stations retro and telestereo, both from our country, both of them are not geo blocking so you can listen to them from around the world, the first station transmit from where the fatherland begins and the second one transmit from the capital. We have added a shorcut to our script4 on Openbox.

Using Emacs as an scripting language

This is going to be the second time we suggest using emacs5, this time is going to be easier because with are not going to interact with emacs. We are just going to use emacs as an scripting language.

Preparing the script

For running our script we should follow:

(defun elisp-cookbook/chomp (str)
  "Chomp leading and tailing whitespace from STR."
  (let ((s (if (symbolp str) (symbol-name str) str)))
    (replace-regexp-in-string "\\(^[[:space:]\n]*\\|[[:space:]\n]*$\\)" "" s)))

(defun kipuamutay/lyrics (icy_info)
  "get the lyrics, for use on lisp program"
  (interactive "r")
  (let* ( (artist_title               (split-string icy_info "-"))
         )
    (emms-get-lyrics (elisp-cookbook/chomp (downcase (car artist_title))) (elisp-cookbook/chomp (car (cdr artist_title))) 'emms-get-lyrics-w3m)
    )
  )

(defun kipuamutay/song ()
  "get telestereo playing song"
  (interactive)
  (let* ( (cmd "mplayer -endpos 0 -vo null -ao null  http://67.212.179.138:8300 2>&1 |grep Info")
          (cmd_output (shell-command-to-string cmd))
          (icy_info (replace-regexp-in-string "';StreamUrl='';" "" (replace-regexp-in-string "ICY Info: StreamTitle='" "" cmd_output) ))
          )
    (if icy_info
        (kipuamutay/lyrics icy_info))
    (if (not icy_info)
        (message "no Song-Lyric on stream"))
))

note: for saving the file press C-x C-s which is equivalent to save-buffer

note: for quitting emacs press C-x C-c which is equivalent to save-buffers-kill-emacs

Running the script

We can use the script form the N800 too

Firt of all we would need emacs on te n800. there is a nice article about installing emacs on n800 and moving the /usr/share/emacs folder to an sd card. For our purpose we have a couple of choices, run the script as a bash6 function which requires typing on the device, the second choice is run it from the n800 menu, we are going to detail the second choice below.

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=X Terminal song lyrics
Comment=Terminal Emulator
Exec=/usr/bin/xterm -hold -e emacs -Q -nw --batch -l
~/.emacs.d/my-configs/rc/.emacs-rc-defuns.el -l
   ~/.emacs.d/el-get/emms-get-lyrics/emms-get-lyrics.el --eval '(progn
   (kipuamutay/song)(princ (buffer-string)))'
Icon=terminal
Terminal=false
Type=Application
Categories=System;TerminalEmulator;
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable

Putting our ideas to work

This article is a big step forward from the times we were at the university buying the song books7 at the news stands. After that we move to organize the lyrics on text files and folders. Following with a small application on lotus-notes. Finally we have arrive here the lyric is a keyboard shorcut away. Put us on your news reader soon we are going an article about organizing our notes and ideas on emacs.


1. For configuring emms use el-get

2. Shoutcast, put an ICY prefix which means "I Can Yell", we are using the tag ICY Info

3. The command is mplayer -endpos 0 -vo null -ao null http://67.212.179.138:8300 2>&1 |grep Info

4. scripting language, this term comes from the actors who use the their script to do their performance.

5. The firs time was when we wrote Do your website Yourself with emacs-muse.

6. Install bash, edit the file .bashrc and put a function that refers the invocation script

7. Probably today you still can find it at the news stand.

acquaintances

Last change: 22.11.2011 22:14

blog comments powered by Disqus