(defconst mp3player-scores-version "1.9")
(defvar mp3player-current-mood "happy")
(defvar mp3player-min-score 0)
(defcustom mp3player-scoresfiles-directory "~/.emacs-mpg123/scores"
"*Directory to store scoresfiles."
(defvar mp3player-default-score 0)
(defun mp3player-save-scores ()
(find-file (concat mp3player-scoresfiles-directory "/" mp3player-current-mood ".sco"))
(defun mp3player-load-scores ()
(let ((scores-file (concat mp3player-scoresfiles-directory "/" mp3player-current-mood ".sco")))
(if (file-exists-p scores-file)
(if (not mp3player-scores-list) (setq mp3player-scores-list (mp3player-load-scores)))
(defun mp3player-change-mood (mood)
"Change the current MOOD. if called interactively, confirm saving
of the score file."
(interactive "sMood: ")
(if (or (not (interactive-p))
(y-or-n-p (concat "Save " mp3player-current-mood " scores to file? ")))
(if mp3player-scores-list (mp3player-save-scores)))
(setq mp3player-current-mood (downcase mood))
(defun mp3player-assoc-delete-all (key alist)
"Delete from ALIST all elements whose car is KEY.
Return the modified alist."
(let ((tail alist))
(if (equal (car (car tail)) key)
(setq alist (delete (car tail) alist)))
(setq tail (cdr tail)))
(defun mp3player-score (score mp3)
(let ((sc (or (cdr (assoc mp3 mp3player-scores-list)) 0))
(mp3i (intern mp3)))
(setq mp3player-scores-list (mp3player-assoc-delete-all mp3i mp3player-scores-list))
(setq mp3player-scores-list (cons (cons mp3i (+ score sc))
(message "New score is %s" (+ score sc))))
(defun mp3player-score-up-current ()
(mp3player-score 1 mp3player-now-playing-filename))
(defun mp3player-score-down-current ()
(mp3player-score -1 mp3player-now-playing-filename))
(defun mp3player-skip (noscoring)
"Stop playing the current song and skip to the next in memory playlist."
(if (not noscoring)
(if mp3player-scores-list (mp3player-score-down-current)))
(if (equal mp3player-program-id 'winamp)
(shell-command (concat mp3player-command-line-winamp-interface " -n")))
(let ((lst mp3player-queued-files))
(if lst (mp3player-play-files-or-urls lst)))))
(defadvice mp3player-quit (after mp3player-save-score-on-quit)
(if (y-or-n-p (concat "Save " mp3player-current-mood " scores to file? "))
(if mp3player-scores-list (mp3player-save-scores))))
(defun mp3player-get-score (f)
(or (cdr (assoc (intern f) mp3player-scores-list)) mp3player-default-score))
(defun mp3player-check-score (f)
(if (>= (mp3player-get-score f) mp3player-min-score)
(progn (message "File %s score too low, skipping" (file-name-nondirectory f))
(defun mp3player-score-lower-tolerance ()
"Only play mp3 with a higher score"
(setq mp3player-min-score (+ mp3player-min-score 1)))
(defun mp3player-score-be-more-tolerant ()
"Allow playing of mp3 with a lower score"
(setq mp3player-min-score (- mp3player-min-score 1)))
(global-set-key [C-M-kp-up] 'mp3player-score-up-current)
(global-set-key [C-M-kp-down] 'mp3player-score-down-current)
(defun mp3player-convert-scores-list ()
(let ((a (car x))
(d (cdr x)))
(cons (if (stringp a)