# musicfox 不會用到,任意設定即可。music_directory "~/Music"playlist_directory "~/.mpd/playlists"db_file "~/.mpd/mpd.db"log_file "~/.mpd/mpd.log"pid_file "~/.mpd/mpd.pid"state_file "~/.mpd/mpdstate"bind_to_address "~/.mpd/socket"# 音量平衡volume_normalization "yes"audio_output {type "osx"name "My Mac Device"mixer_type "software"}# wyy return Content-Type: audio/mpeg; for flac files!!# just disable mad and fallback to ffmpeg; and ffmpeg will do the correct jobdecoder {plugin "mad"enabled "no"}
(require'vterm)(defvarmusicfox-mode-map(let((map(make-sparse-keymap)))(define-keymap"]"#'musicfox-next)map)"MusicFox Keymap")(defvarmusicfox-buffer-name"*MusicFox*")(define-minor-modemusicfox-mode"MusicFox")(defunmusicfox()(interactive)(let*((vterm-buffer-name-stringnil)(vterm-buffer-namemusicfox-buffer-name)(b(get-buffervterm-buffer-name)))(ifb(if(eq(current-buffer)b)(bury-buffer)(pop-to-buffer-same-windowb))(vterm)(setq-localvterm-buffer-namevterm-buffer-name)(setq-localvterm-buffer-name-stringvterm-buffer-name-string)(local-unset-key(kbd"<f11>"));; should match the key in init.el(local-unset-key(kbd"C-SPC"))(local-set-key"]"#'musicfox-next)(vterm-insert"musicfox\n")(musicfox-mode))))(defmacrowith-musicfox(body)`(with-current-buffermusicfox-buffer-name,body))(defunmusicfox-next()(interactive)(with-musicfox(vterm-insert"]")))(defunmusicfox-prev()(interactive)(with-musicfox(vterm-insert"[")))(defunmusicfox-playpause()(interactive)(with-musicfox(vterm-insert(kbd"SPC"))))(defunmusicfox-favorite()(interactive)(with-musicfox(vterm-insert(kbd","))))(defunmusicfox-download()(interactive)(with-musicfox(vterm-insert(kbd"d"))))(defunmusicfox-volumn-decrease()(interactive)(with-musicfox(vterm-insert(kbd"-"))))(defunmusicfox-volumn-increase()(interactive)(with-musicfox(vterm-insert(kbd"="))))(spacemacs/declare-prefix"am""music");; TODO popup log file with read-only(defunmusixfox-popup-log()(interactive))(defunmusixfox-config()(interactive)(find-file"~/Library/Application Support/go-musicfox/go-musicfox.ini"));; replicate keybindings and some custom aliases(spacemacs/set-leader-keys"amn"'musicfox-next"am]"'musicfox-next"amb"'musicfox-prev"am["'musicfox-prev"amp"'musicfox-playpause"am SPC"'musicfox-playpause"amf"'musicfox-favorite"am,"'musicfox-favorite"amd"'musicfox-download"am-"'musicfox-volumn-decrease"am="'musicfox-volumn-increase"aml"'musixfox-popup-log)(provide'init-musicfox)
localmodule={}CLI_PATH='/Users/fuyu0425/bin/musicfox-cli'functioncallback(exitCode,stdOut,stdErr)-- do something when the task is completedifexitCode==0thenprint('Task succeeded')print('Output:',stdOut)elseprint('Task failed with exit code',exitCode)print('Error:',stdErr)endendfunctionmodule.playpause()hs.task.new(CLI_PATH,nil,{'playpause'}):start()endfunctionmodule.next()hs.task.new(CLI_PATH,nil,{'next'}):start()endfunctionmodule.prev()hs.task.new(CLI_PATH,nil,{'prev'}):start()endreturnmodule
music.lua
建立一個 Menu bar toggle 來決定目前要控制 iTunes (Apple Music) 還是 musicfox.
musicfox=require('musicfox')ITUNES='iTunes'MUSICFOX='MusicFox'-- Choose your default value to be ITUNES or MUSICFOX-- CURRENT_MUSIC_APP = ITUNESCURRENT_MUSIC_APP=MUSICFOXmusicAppMenu=hs.menubar.new()-- Define statestate=CURRENT_MUSIC_APP-- Function to toggle statefunctiontoggleMusicAppState()ifstate==ITUNESthenstate=MUSICFOXCURRENT_MUSIC_APP=MUSICFOXelsestate=ITUNESCURRENT_MUSIC_APP=ITUNESend-- Update the menu titlemusicAppMenu:setTitle(state)end-- Set initial statemusicAppMenu:setTitle(state)-- Set the menu to be our toggle functionmusicAppMenu:setClickCallback(toggleMusicAppState)hs.hotkey.bind({"alt","ctrl"},"p",nil,function()ifCURRENT_MUSIC_APP==ITUNESthenhs.itunes.playpause()elsemusicfox.playpause()endend)hs.hotkey.bind({"alt","ctrl"},"n",nil,function()ifCURRENT_MUSIC_APP==ITUNESthenhs.itunes.next()elsemusicfox.next()endend)hs.hotkey.bind({"alt","ctrl"},"b",nil,function()ifCURRENT_MUSIC_APP==ITUNESthenhs.itunes.previous()elsemusicfox.prev()endend)