2016/01/30

昔から Linux でも Windows でも mpd を使ってきてる。Windows 10 にしてから環境を作ってなかったので重い腰をあげた。

まずはサーバ、これはオフィシャルが配布している Windows バイナリのまま使った。ただし Windows にログインした後毎回起動するのもうざったいし、コンソールが見えたままになるのは嫌なので nssm を使ってNTサービス化する。nssm には GUI の設定画面があるので

nssm install mpd

を実行して mpd へのパスを設定する。また設定ファイル mpd.conf は %LOCALAPPDATA%\mpd\mpd.conf に置く。mp3 は id3v2 なので filesystem_charset だけ cp932 にする。

mpd1
mpd2

ここで気を付けないといけないのは、nssm でNTサービス化した場合、Administrator で実行されこの mpd.conf のパスが教えられないので nssm の設定画面で .\mattn の様にログインユーザを設定する。

mpd3

次にクライアント側。コマンドプロンプトで生きる人なのでそのまま mpc を使う。

master/mpc.git -

wiki | mailing list/newsgroup | bug tracker | request an account Thanks to Alexander Wirt for provid...

http://git.musicpd.org/cgit/master/mpc.git/

ただし mpc のバイナリは iconv で端末のエンコーディングに変換を行ってくれないので、パッチを当てる。

diff --git a/configure.ac b/configure.ac
index 9da26be..df1adaf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,18 +91,11 @@ AC_ARG_ENABLE(iconv,
 
 if test x$enable_iconv = xyes; then
    AC_CHECK_FUNC(iconv,
-       [ICONV_CFLAGS="" ICONV_LIBS=""],
-       [AC_CHECK_LIB(intl, iconv,
-           [ICONV_CFLAGS="" ICONV_LIBS="-lintl"],
-           [enable_iconv=no])])
+       [ICONV_CFLAGS="" ICONV_LIBS="-liconv"])
 fi
 
 if test x$enable_iconv = xyes; then
    AM_LANGINFO_CODESET
-   if test x$am_cv_langinfo_codeset != xyes; then
-       enable_iconv=no
-       AC_MSG_WARN(nl_langinfo and CODESET not available - disabling iconv)
-   fi
 fi
 
 if test x$enable_iconv = xyes; then
diff --git a/src/charset.c b/src/charset.c
index 2e34e47..a50096d 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -26,7 +26,11 @@
 #include <string.h>
 
 #include <locale.h>
+#ifdef _WIN32
+#include <windows.h>
+#else
 #include <langinfo.h>
+#endif
 #include <iconv.h>
 
 static bool charset_enable_input;
@@ -181,9 +185,17 @@ charset_init(bool enable_input, bool enable_output)
    if (original_locale == NULL)
        return;
 
+#ifdef _WIN32
+   if (ignore_invalid) {
+        char buf[16];
+        sprintf(buf, "cp%d", GetACP());
+       locale_charset = strdup(buf);
+    }
+#else
    const char *charset = nl_langinfo(CODESET);
    if (charset != NULL)
        locale_charset = strdup(charset);
+#endif
 
    setlocale(LC_CTYPE,original_locale);
 
diff --git a/src/charset.h b/src/charset.h
index 2eca94b..67a027c 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -25,7 +25,7 @@
 #include "Compiler.h"
 
 #include <stdbool.h>
-
+#if 0
 #ifdef HAVE_ICONV
 
 /**
@@ -74,5 +74,6 @@ charset_from_utf8(const char *from)
 }
 
 #endif
+#endif
 
 #endif

これで grep 等で絞り込む時は utf-8 だけど端末に表示される時は cp932 になる(ちょっとやっつけ)。ビルドには libmpdclient が必要。

mpc listall | grep "Taylor Swift" | mpc add

して再生していたら娘がテイラースウィフトを気に入った様だ。



/ (1970年01月01日)
 
発送可能時間:

Posted at 14:21 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.