summaryrefslogtreecommitdiffhomepage
path: root/media
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2020-11-23 03:16:35 +0000
committerjao <jao@gnu.org>2020-11-23 03:16:35 +0000
commitcb450eac9005d1945feb09052222b0cd4e139284 (patch)
tree1329a0e03484f1cc087cfc4027ca48888463f022 /media
parent6f5fc433b4b60f1b68dc407eef0b38dc8dc5d4ed (diff)
downloadelibs-cb450eac9005d1945feb09052222b0cd4e139284.tar.gz
elibs-cb450eac9005d1945feb09052222b0cd4e139284.tar.bz2
suffling around some files
Diffstat (limited to 'media')
-rw-r--r--media/jao-emms-info-track.el208
-rw-r--r--media/jao-emms-lyrics.el41
-rw-r--r--media/jao-emms-random-album.el118
-rw-r--r--media/jao-emms.el27
-rw-r--r--media/jao-mpris.el128
-rw-r--r--media/jao-random-album.el101
-rwxr-xr-xmedia/leoslyrics.py84
-rwxr-xr-xmedia/lyricwiki.rb52
8 files changed, 759 insertions, 0 deletions
diff --git a/media/jao-emms-info-track.el b/media/jao-emms-info-track.el
new file mode 100644
index 0000000..728666d
--- /dev/null
+++ b/media/jao-emms-info-track.el
@@ -0,0 +1,208 @@
+;; jao-emms-info-track.el -- utilities to show tracks -*- lexical-binding:t; -*-
+
+;; Copyright (C) 2009, 2010, 2013, 2017, 2020 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Start date: Sat Jul 04, 2009 13:47
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'emms)
+(require 'emms-tag-editor)
+(require 'emms-player-mpd)
+(require 'jao-osd)
+(require 'jao-emms)
+(require 'jao-minibuffer)
+
+(defgroup jao-emms-faces nil "Faces"
+ :group 'faces
+ :group 'jao-emms)
+
+(defface jao-emms-font-lock-album '((t (:foreground "lightgoldenrod2")))
+ "Album name in EMMS track message."
+ :group 'jao-emms-faces)
+
+(defface jao-emms-font-lock-track '((t (:bold t)))
+ "Track number in EMMS track message."
+ :group 'jao-emms-faces)
+
+(defface jao-emms-font-lock-title '((t (:foreground "dodgerblue2")))
+ "Track title in EMMS track message."
+ :group 'jao-emms-faces)
+
+(defface jao-emms-font-lock-artist '((t (:foreground "dodgerblue3")))
+ "Artist name in EMMS track message."
+ :group 'jao-emms-faces)
+
+(defcustom jao-emms-show-osd-p nil
+ "Whether to show osd notices on track change"
+ :group 'jao-emms)
+
+
+
+(defun jao-emms-info-track-stream (track)
+ "Return track info for streams"
+ (let ((name (emms-track-name track))
+ (title (or (emms-track-get track 'title nil)
+ (car (emms-track-get track 'metadata nil)))))
+ (format "♪ %s (%s)" title (if title (emms-track-type track) name))))
+
+(defsubst jao--put-face (str face)
+ (put-text-property 0 (length str) 'face face str)
+ str)
+
+(defun jao-emms--to-number (x)
+ (or (and (numberp x) x)
+ (and (stringp x)
+ (string-match "\\`\\(:?[0-9]+\\)" x)
+ (string-to-number (match-string 1 x)))))
+
+(defun jao-emms--fmt-time (x suffix)
+ (if x (format "%02d:%02d%s" (/ x 60) (mod x 60) (or suffix "")) ""))
+
+(defun jao-emms--fmt-song-times (track lapsed pre post)
+ (if lapsed
+ (let ((time (when track (emms-track-get track 'info-playing-time))))
+ (format "%s%s%s%s"
+ (or pre "")
+ (jao-emms--fmt-time lapsed (when time "/"))
+ (jao-emms--fmt-time time "")
+ (or post "")))
+ ""))
+
+(defun jao-emms-info-track-file (track &optional lapsed plen titlesep)
+ "Return a description of the current track."
+ (let* ((no (jao-emms--to-number (emms-track-get track 'info-tracknumber "0")))
+ (time (emms-track-get track 'info-playing-time))
+ (year (emms-track-get track 'info-year))
+ (year (if year (format " (%s)" year) ""))
+ (artist (emms-track-get track 'info-artist ""))
+ (composer (emms-track-get track 'info-composer nil))
+ (title (emms-track-get track 'info-title ""))
+ (album (emms-track-get track 'info-album))
+ (last-played (or (emms-track-get track 'last-played) '(0 0 0)))
+ (play-count (or (emms-track-get track 'play-count) 0))
+ (playlength (if plen (format "/%02d" (string-to-number plen)) "")))
+ (if (or (not title) (not album))
+ (emms-track-simple-description track)
+ (format "♪ %s%s%s%s%s%s%s"
+ (jao--put-face (if (zerop no) "" (format "%02d%s " no playlength))
+ 'jao-emms-font-lock-track)
+ (jao--put-face title
+ 'jao-emms-font-lock-title)
+ (or titlesep " ")
+ (jao-emms--fmt-song-times track lapsed "[" "] ")
+ (jao--put-face artist 'jao-emms-font-lock-artist)
+ (jao--put-face (if composer (format " [%s]" composer) "")
+ 'jao-emms-font-lock-artist)
+ (jao--put-face (if album
+ (format " (%s%s)" album year)
+ (format "%s *") year)
+ 'jao-emms-font-lock-album)))))
+
+;;;###autoload
+(defun jao-emms-info-track-description (track &optional lapsed plen tsep)
+ (if (memq (emms-track-type track) '(streamlist url))
+ (jao-emms-info-track-stream track)
+ (jao-emms-info-track-file track lapsed plen tsep)))
+
+;;;###autoload
+(defun jao-emms-toggle-osd ()
+ (interactive)
+ (setq jao-emms-show-osd-p (not jao-emms-show-osd-p))
+ (message "Emms OSD %s" (if jao-emms-show-osd-p "enabled" "disabled")))
+
+(defvar jao-emms-show-icon nil)
+
+(defun jao-emms--with-mpd-track (callback)
+ (emms-player-mpd-get-status
+ nil
+ (lambda (_ st)
+ (let* ((lapsed (jao-emms--to-number (cdr (assoc "time" st))))
+ (plen (cdr (assoc "playlistlength" st)))
+ (song (jao-emms--to-number (cdr (assoc "song" st))))
+ (track (emms-playlist-current-selected-track)))
+ (when (and track song)
+ (emms-track-set track 'info-tracknumber (format "%d" (1+ song))))
+ (funcall callback track lapsed plen)))))
+
+;;;###autoload
+(defun jao-emms-show-osd ()
+ (interactive)
+ (jao-emms--with-mpd-track
+ (lambda (track lapsed play-len)
+ (let* ((sep "~~~~~")
+ (s (jao-emms-info-track-description track lapsed play-len sep))
+ (s (substring-no-properties s 2))
+ (cs (split-string s sep)))
+ (jao-notify (car cs) (cadr cs) jao-emms-show-icon)))))
+
+(defun jao-emms-show-osd-hook ()
+ (interactive)
+ (when jao-emms-show-osd-p (jao-emms-show-osd)))
+
+(defun jao-emms-install-i3dv2 ()
+ (add-to-list 'emms-tag-editor-tagfile-functions
+ '("mp3" "id3v2" ((info-artist . "a")
+ (info-title . "t")
+ (info-album . "A")
+ (info-tracknumber . "T")
+ (info-year . "y")
+ (info-genre . "g")
+ (info-composer . "-TCOM")
+ (info-note . "c")))))
+
+(defvar jao-emms-echo-string "")
+(defun jao-emms-update-echo-string (&optional existing-track)
+ (if emms-player-playing-p
+ (jao-emms--with-mpd-track
+ (lambda (track lapsed play-len)
+ (setq jao-emms-echo-string
+ (if emms-player-paused-p
+ (if existing-track
+ (format "(%s/%s)"
+ (emms-track-get existing-track 'info-tracknumber)
+ play-len)
+ "")
+ (jao-emms-info-track-description track nil play-len)))
+ (jao-minibuffer-refresh)))
+ (setq jao-emms-echo-string "")
+ (jao-minibuffer-refresh)))
+
+(defun jao-emms-enable-minibuffer ()
+ (jao-minibuffer-add-variable 'jao-emms-echo-string t)
+ (dolist (h '(emms-track-updated-functions
+ emms-player-finished-hook
+ emms-player-stopped-hook
+ emms-player-started-hook
+ emms-player-paused-hook))
+ (add-hook h #'jao-emms-update-echo-string)))
+
+;;;###autoload
+(defun jao-emms-info-setup (&optional show-mini show-osd show-echo-line no-id3)
+ (setq emms-track-description-function 'jao-emms-info-track-description)
+ (setq jao-emms-show-osd-p show-osd)
+ (add-hook 'emms-player-started-hook 'jao-emms-show-osd-hook)
+ (when show-mini (jao-emms-enable-minibuffer))
+ (unless show-echo-line
+ (eval-after-load 'emms-player-mpd
+ '(remove-hook 'emms-player-started-hook 'emms-player-mpd-show)))
+ (unless no-id3 (jao-emms-install-i3dv2))
+ (ignore-errors (emms-player-mpd-connect)))
+
+
+(provide 'jao-emms-info-track)
+;;; jao-emms-info-track.el ends here
diff --git a/media/jao-emms-lyrics.el b/media/jao-emms-lyrics.el
new file mode 100644
index 0000000..0ea52e0
--- /dev/null
+++ b/media/jao-emms-lyrics.el
@@ -0,0 +1,41 @@
+;; jao-emms-lyrics.el -- simple show lyrics in emms
+
+;; Copyright (C) 2009, 2010, 2017, 2019, 2020 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Start date: Sat Jul 04, 2009 13:41
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'emms)
+(require 'jao-lyrics)
+
+;;;###autoload
+(defun jao-emms-lyrics-track-data ()
+ (let ((track (or (emms-playlist-current-selected-track)
+ (error "No playing track"))))
+ (cons (or (emms-track-get track 'info-artist nil)
+ (error "No artist"))
+ (or (emms-track-get track 'info-title nil)
+ (error "No artist")))))
+
+;;;###autoload
+(defun jao-emms-show-lyrics (&optional force)
+ (let ((jao-lyrics-info-function 'jao-emms-lyrics-track-data))
+ (jao-show-lyrics force)))
+
+(provide 'jao-emms-lyrics)
+;;; jao-emms-lyrics.el ends here
diff --git a/media/jao-emms-random-album.el b/media/jao-emms-random-album.el
new file mode 100644
index 0000000..72e056b
--- /dev/null
+++ b/media/jao-emms-random-album.el
@@ -0,0 +1,118 @@
+;; jao-emms-random-album.el -- play random albums in emms
+
+;; Copyright (C) 2009, 2010, 2017, 2018, 2020 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Start date: Sat Jul 04, 2009 13:06
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+(require 'emms)
+(require 'jao-minibuffer)
+
+(defvar jao-emms-random-album-p t)
+(defvar jao-emms-random-lines nil)
+(defvar jao-emms-random-lines-file
+ (expand-file-name "~/.emacs.d/random-lines"))
+(defvar jao-emms-random-album-notify-p t)
+(defvar jao-emms-random-album-notify-icon nil)
+
+(defun jao-emms-random-lines ()
+ (or jao-emms-random-lines
+ (and (file-exists-p jao-emms-random-lines-file)
+ (with-current-buffer
+ (find-file-noselect jao-emms-random-lines-file)
+ (goto-char (point-min))
+ (setq jao-emms-random-lines (read (current-buffer)))))
+ (dotimes (n (1- (line-number-at-pos (point-max)))
+ jao-emms-random-lines)
+ (push (1+ n) jao-emms-random-lines))))
+
+(defun jao-emms-random-lines-save ()
+ (with-current-buffer (find-file-noselect jao-emms-random-lines-file)
+ (delete-region (point-min) (point-max))
+ (insert (format "%s\n" jao-emms-random-lines))
+ (save-buffer)))
+
+(defun jao-emms-goto-random-album ()
+ (let* ((pos (random (length (jao-emms-random-lines))))
+ (line (nth pos jao-emms-random-lines)))
+ (setq jao-emms-random-lines (remove line jao-emms-random-lines))
+ (jao-emms-random-lines-save)
+ (goto-line line)))
+
+(defun jao-emms-next-noerror ()
+ (interactive)
+ (when emms-player-playing-p
+ (error "A track is already being played"))
+ (cond (emms-repeat-track
+ (emms-start))
+ ((condition-case nil
+ (progn
+ (emms-playlist-current-select-next)
+ t)
+ (error nil))
+ (emms-start))
+ (t
+ (if jao-emms-random-album-p
+ (jao-emms-random-album-next)
+ (message "No next track in playlist")))))
+
+
+;; User interface
+;;;###autoload
+(defun jao-emms-random-album-start ()
+ (interactive)
+ (setq jao-emms-random-album-p t)
+ (jao-emms-random-album-next))
+
+;;;###autoload
+(defun jao-emms-random-album-stop ()
+ (interactive)
+ (setq jao-emms-random-album-p nil)
+ (emms-stop))
+
+;;;###autoload
+(defun jao-emms-random-album-toggle ()
+ (interactive)
+ (setq jao-emms-random-album-p (not jao-emms-random-album-p))
+ (message "Random album %s"
+ (if jao-emms-random-album-p "enabled" "disabled")))
+
+;;;###autoload
+(defun jao-emms-random-album-next ()
+ (interactive)
+ (save-excursion
+ (ignore-errors (emms-browser-clear-playlist))
+ (emms-browse-by-album)
+ (jao-emms-goto-random-album)
+ (let ((album (substring-no-properties (thing-at-point 'line) 0 -1)))
+ (emms-browser-add-tracks-and-play)
+ (when jao-emms-random-album-notify-p
+ (jao-notify album "Next album" jao-emms-random-album-notify-icon)))
+ (emms-browser-bury-buffer)
+ (jao-minibuffer-refresh)))
+
+;;;###autoload
+(defun jao-emms-random-album-reset ()
+ (interactive)
+ (setq jao-emms-random-lines nil)
+ (jao-emms-random-lines-save))
+
+(setq emms-player-next-function 'jao-emms-next-noerror)
+
+
+(provide 'jao-emms-random-album)
+;;; jao-emms-random-album.el ends here
diff --git a/media/jao-emms.el b/media/jao-emms.el
new file mode 100644
index 0000000..53b3513
--- /dev/null
+++ b/media/jao-emms.el
@@ -0,0 +1,27 @@
+;; jao-emms.el -- shared bits
+
+;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Start date: Sat Jul 04, 2009 13:51
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(defgroup jao-emms nil "Emms extensions" :group 'emms)
+
+
+(provide 'jao-emms)
+;;; jao-emms.el ends here
diff --git a/media/jao-mpris.el b/media/jao-mpris.el
new file mode 100644
index 0000000..195ffce
--- /dev/null
+++ b/media/jao-mpris.el
@@ -0,0 +1,128 @@
+;;; jao-mpris.el --- mpris players control -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: multimedia
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; controlling and showing info on mpris players
+
+;;; Code:
+
+(require 'dbus)
+(require 'jao-minibuffer)
+(require 'jao-emms-info-track)
+
+(defun jao-mpris--playerctl (&rest args)
+ (shell-command-to-string (format "playerctl %s"
+ (mapconcat #'shell-quote-argument args " "))))
+
+(defmacro jao-playerctl--def (name &rest args)
+ `(defun ,name () (interactive) (jao-mpris--playerctl ,@args)))
+
+(jao-playerctl--def jao-mpris-play-pause "play-pause")
+(jao-playerctl--def jao-mpris-next "next")
+(jao-playerctl--def jao-mpris-previous "previous")
+
+(defun jao-playerctl--status (&optional sep)
+ (let* ((sep (or sep " ||| "))
+ (fmt (mapconcat 'identity
+ '("{{status}}"
+ "{{xesam:trackNumber}}"
+ "{{title}}"
+ "{{artist}}"
+ "{{album}}"
+ "{{duration(mpris:length)}}")
+ sep))
+ (m (jao-mpris--playerctl "metadata" "--format" fmt)))
+ (split-string (car (split-string m "\n")) sep)))
+
+;;;###autoload
+(defun jao-mpris-status-times ()
+ (interactive)
+ (let ((m (jao-mpris--playerctl "metadata" "--format"
+ (concat "{{duration(position)}}/"
+ "{{duration(mpris:length)}}"))))
+ (jao-notify (string-trim m) "Playing")))
+
+;;;###autoload
+(defun jao-mpris-show-osd ()
+ (interactive)
+ (jao-notify jao-spotify-track-string))
+
+;;;###autoload
+(defun jao-mpris-artist-title ()
+ (when-let (s (jao-mpris--playerctl "metadata"
+ "--format"
+ "{{artist}}|||{{title}}"))
+ (let ((s (split-string (string-trim s) "|||")))
+ (cons (car s) (cadr s)))))
+
+(defvar jao-mpris-track-string "")
+
+(defun jao-mpris--track (&rest info)
+ (let ((cs (or info (jao-playerctl--status))))
+ (if (string= "Playing" (or (elt cs 0) ""))
+ (let* ((track (format "%s" (elt cs 1)))
+ (title (elt cs 2))
+ (artist (elt cs 3))
+ (album (elt cs 4))
+ (length (elt cs 5))
+ (duration (cond ((stringp length) length)
+ ((numberp length)
+ (jao-emms--fmt-time (/ length 1e6) "")))))
+ (setq jao-mpris-track-string
+ (format "♪ %s %s %s%s%s"
+ (jao--put-face track 'jao-emms-font-lock-track)
+ (jao--put-face title 'jao-emms-font-lock-title)
+ (jao--put-face artist 'jao-emms-font-lock-artist)
+ (jao--put-face (if album (format " (%s)" album) "")
+ 'jao-emms-font-lock-album)
+ (if duration (format " [%s]" duration) ""))))
+ (setq jao-mpris-track-string "")))
+ (jao-minibuffer-refresh))
+
+(jao-minibuffer-add-variable 'jao-mpris-track-string t)
+
+(defun jao-mpris--handler (iname properties &rest args)
+ (when properties
+ (let ((st (caadr (assoc "PlaybackStatus" properties)))
+ (md (caadr (assoc "Metadata" properties))))
+ (cond ((and st (not (string= "Playing" st)))
+ (setq jao-spotify-track-string ""))
+ (md (let ((tno (caadr (assoc "xesam:trackNumber" md)))
+ (tlt (caadr (assoc "xesam:title" md)))
+ (art (caaadr (assoc "xesam:artist" md)))
+ (alb (caadr (assoc "xesam:album" md)))
+ (len (caadr (assoc "mpris:length" md))))
+ (setq jao-debug md)
+ (jao-mpris--track "Playing" tno tlt art alb len)))))))
+
+
+;;;###autoload
+(defun jao-mpris-minibuffer-register (name &optional bus)
+ (dbus-register-signal (or bus :session)
+ name
+ "/org/mpris/MediaPlayer2"
+ "org.freedesktop.DBus.Properties"
+ "PropertiesChanged"
+ 'jao-mpris--handler))
+
+
+(provide 'jao-mpris)
+;;; jao-mpris.el ends here
diff --git a/media/jao-random-album.el b/media/jao-random-album.el
new file mode 100644
index 0000000..7158417
--- /dev/null
+++ b/media/jao-random-album.el
@@ -0,0 +1,101 @@
+;; jao-random-album.el -- play random albums
+
+;; Copyright (C) 2009, 2010, 2017, 2018, 2019 Jose Antonio Ortega Ruiz
+
+;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
+;; Start date: Sat Jul 04, 2009 13:06
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(require 'jao-notify)
+
+(defvar jao-random-album-p t)
+(defvar jao-random-lines nil)
+(defvar jao-random-lines-file (expand-file-name "~/.emacs.d/random-lines"))
+(defvar jao-random-album-notify-p t)
+(defvar jao-random-album-notify-icon nil)
+(defvar jao-random-album-skip-lines 2)
+
+(defun jao-random-lines ()
+ (or jao-random-lines
+ (and (file-exists-p jao-random-lines-file)
+ (with-current-buffer
+ (find-file-noselect jao-random-lines-file)
+ (goto-char (point-min))
+ (setq jao-random-lines (read (current-buffer)))))
+ (dotimes (n (1- (line-number-at-pos (point-max)))
+ jao-random-lines)
+ (when (> n jao-random-album-skip-lines)
+ (push (1+ n) jao-random-lines)))))
+
+(defun jao-random-lines-save ()
+ (with-current-buffer (find-file-noselect jao-random-lines-file)
+ (delete-region (point-min) (point-max))
+ (insert (format "%s\n" jao-random-lines))
+ (save-buffer)))
+
+(defun jao-goto-random-album ()
+ (let* ((pos (random (length (jao-random-lines))))
+ (line (nth pos jao-random-lines)))
+ (setq jao-random-lines (remove line jao-random-lines))
+ (jao-random-lines-save)
+ (goto-line line)))
+
+
+;; User interface
+(defvar jao-random-album-buffer)
+(defvar jao-random-album-add-tracks-and-play)
+(defvar jao-random-album-stop)
+
+(defun jao-random-album-start ()
+ (interactive)
+ (setq jao-random-album-p t)
+ (jao-random-album-next))
+
+(defun jao-random-album-stop ()
+ (interactive)
+ (setq jao-random-album-p nil)
+ (funcall jao-random-album-stop))
+
+(defun jao-random-album-toggle ()
+ (interactive)
+ (setq jao-random-album-p (not jao-random-album-p))
+ (message "Random album %s"
+ (if jao-random-album-p "enabled" "disabled")))
+
+(defun jao-random-album-next ()
+ (interactive)
+ (with-current-buffer (get-buffer (funcall jao-random-album-buffer))
+ (save-excursion
+ (jao-goto-random-album)
+ (let ((album (string-trim
+ (substring-no-properties (thing-at-point 'line) 0 -1))))
+ (funcall jao-random-album-add-tracks-and-play)
+ (when jao-random-album-notify-p
+ (jao-notify album "Next album" jao-random-album-notify-icon))))))
+
+(defun jao-random-album-reset ()
+ (interactive)
+ (setq jao-random-lines nil)
+ (jao-random-lines-save))
+
+(defun jao-random-album-setup (album-buffer add-and-play stop &optional icon)
+ (setq jao-random-album-buffer album-buffer
+ jao-random-album-add-tracks-and-play add-and-play
+ jao-random-album-stop stop
+ jao-random-album-notify-icon icon))
+
+
+(provide 'jao-random-album)
+;;; jao-random-album.el ends here
diff --git a/media/leoslyrics.py b/media/leoslyrics.py
new file mode 100755
index 0000000..5e4f8c8
--- /dev/null
+++ b/media/leoslyrics.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+#
+# (c) 2004-2008 The Music Player Daemon Project
+# http://www.musicpd.org/
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+#
+# Load lyrics from leoslyrics.com
+#
+
+from sys import argv, exit
+from urllib import urlencode, urlopen
+from xml.sax import make_parser, SAXException
+from xml.sax.handler import ContentHandler
+
+class SearchContentHandler(ContentHandler):
+ def __init__(self):
+ self.code = None
+ self.hid = None
+
+ def startElement(self, name, attrs):
+ if name == 'response':
+ self.code = int(attrs['code'])
+ elif name == 'result':
+ if self.hid is None or attrs['exactMatch'] == 'true':
+ self.hid = attrs['hid']
+
+def search(artist, title):
+ query = urlencode({'auth': 'ncmpc',
+ 'artist': artist,
+ 'songtitle': title})
+ url = "http://api.leoslyrics.com/api_search.php?" + query
+ f = urlopen(url)
+ handler = SearchContentHandler()
+ parser = make_parser()
+ parser.setContentHandler(handler)
+ parser.parse(f)
+ return handler.hid
+
+class LyricsContentHandler(ContentHandler):
+ def __init__(self):
+ self.code = None
+ self.is_text = False
+ self.text = None
+
+ def startElement(self, name, attrs):
+ if name == 'text':
+ self.text = ''
+ self.is_text = True
+ else:
+ self.is_text = False
+
+ def characters(self, chars):
+ if self.is_text:
+ self.text += chars
+
+def lyrics(hid):
+ query = urlencode({'auth': 'ncmpc',
+ 'hid': hid})
+ url = "http://api.leoslyrics.com/api_lyrics.php?" + query
+ f = urlopen(url)
+ handler = LyricsContentHandler()
+ parser = make_parser()
+ parser.setContentHandler(handler)
+ parser.parse(f)
+ return handler.text
+
+hid = search(argv[1], argv[2])
+if hid is None:
+ exit(2)
+print lyrics(hid).encode('utf-8')
diff --git a/media/lyricwiki.rb b/media/lyricwiki.rb
new file mode 100755
index 0000000..f163fa4
--- /dev/null
+++ b/media/lyricwiki.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+#
+# (c) 2004-2008 The Music Player Daemon Project
+# http://www.musicpd.org/
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+#
+# Load lyrics from lyrics.wikia.com, formerly lyricwiki.org
+#
+
+require 'uri'
+require 'net/http'
+require 'cgi'
+
+url = "http://lyrics.wikia.com/api.php?action=lyrics&fmt=xml&func=getSong" + \
+ "&artist=#{URI.escape(ARGV[0])}&song=#{URI.escape(ARGV[1])}"
+response = Net::HTTP.get(URI.parse(url))
+
+if not response =~ /<url>\s*(.*?)\s*<\/url>/im
+ $stderr.puts "No URL in response!"
+ exit(1)
+end
+
+url = $1
+exit(69) if url =~ /action=edit$/
+
+response = Net::HTTP.get(URI.parse(url))
+if not response =~ /<div class='lyricbox'>\s*(.*?)\s*<!--/im
+ $stderr.puts "No <div class='lyricbox'> in lyrics page!\n"
+ exit(1)
+end
+
+# if not $1 =~ /^.*<\/div>(.*?)$/im
+if not $1 =~ /^.*<\/script>(.*?)$/im
+ $stderr.puts "Couldn't remove leading XML tags in lyricbox!\n"
+ exit(1)
+end
+
+puts CGI::unescapeHTML($1.gsub(/<br \/>/, "\n"))