xwem-devel
[Top] [All Lists]

"lyrics support" for mpd

From: Richard Klinda <ignotus@xxxxxxxxxxx>
Subject: "lyrics support" for mpd
Date: Fri, 29 Apr 2005 23:00:16 +0200
Organization: Who wants some OYSTERS with SEN-SEN an' COOL WHIP?
Sender: ignotus@xxxxxxxxxxx
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Security Through Obscurity, linux)
Hello XWEM hackers!

Song lyrics have always been a problem for me because I had no way to
collect them.  I mean googling it then copy/pasting the lyric into a
text file by hand isn't my style.  If it was easy to download the lyrics
of an entire album in pure text format then I may had done it, but it
isn't.  So until now, I always googled for the title of the track I was
interested in, every single time I wanted to read that particular
lyric.

But tonight an idea popped into my mind, which was followed by coding.
XEmacs knows which track is currently played, so I Google for the lyric,
select the text in my web browser (FYI: opera), press a single key,
XEmacs saves it somewhere, the title of the song on the XWEM dockapp
changes from yellowish to greenish, that means it has a lyric.  Now if I
play a song and the track title is greenish, I press a single button and
a XWEM frame pops up with the lyric, if it was yellowis (=> which means no 
lyric for
this particular song) then XEmacs launches a Google query (via
browse-URL) for "artist" + "songname" + lyrics.

That's what I call "lyrics support". :-)

================================================================

;; lyrics support
(defvar mpd-lyrics-dir "~/text/lyrics/")

(defun mpd-lyric-filename ()
  (when **mpd-var-file*
    (concat mpd-lyrics-dir (replace-in-string **mpd-var-file*
                                              "\/"
                                              " -- ")
                                              ".txt")))

(defun mpd-save-lyric ()
  (interactive)
  (let ((fn (mpd-lyric-filename))
        (text (get-selection-no-error)))
    (when (file-exists-p fn)
      (message "there is already a lyric for this song")
      (return))
    (unless text
      (message "you should have selected the lyric first!")
      (return))
    ;; everything is ok
    (find-file fn)
    (insert text)
    (save-buffer)
    (kill-buffer nil)))

(define-xwem-command mpd-show-lyric ()
  ""
  (xwem-interactive)
  (if (mpd-lyrics-check-lyric)
      (let ((b (find-file-noselect (mpd-lyric-filename))))
        (xwem-special-popup-frame b))
      (when (and **mpd-var-Artist*
                 **mpd-var-Title*)
        (browse-url (concat "http://www.google.com/search?q=";
                            (w3m-url-encode-string (concat "\"" 
**mpd-var-Artist* "\" "
                                                           "\"" 
**mpd-var-Title* "\" "
                                                           "lyrics")))))))

(xwem-global-set-key [(hyper alt f2)] 'mpd-show-lyric)

(defvar mpd-got-lyric-p nil)

(defun mpd-lyrics-check-lyric ()
  (setq mpd-got-lyric-p (file-exists-p (mpd-lyric-filename))))

================================================================

Modify existing function:

(defun mpd-process-filter (process output)
  (with-temp-buffer
    (insert output)
    (goto-char (point-min))
    (while (not (eobp))
      (when (looking-at "\\(.*?\\): \\(.*\\)")
        (set (intern (concat "**mpd-var-" (match-string 1) "*"))
             (match-string 2)))
      (forward-line 1)))
  (when mpd-status-update-p
    (xwem-mpd-osd-deferred-update) ;; MPD
    (setq mpd-status-update-p nil)
    (setq mpd-zero-vars-p nil)
    (mpd-lyrics-check-lyric)      ;;;;;;; <--- new line
    ))

Now use the functions mpd-save-lyric and mpd-show-lyric.

-- 
Richard Klinda  \/
                /\  Show me your init.el and I'll you tell who you are.

<Prev in Thread] Current Thread [Next in Thread>