[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

lookup の動画対応



白井です。

最近、おもむろに lookup 向けの環境整備をしていまして、現在、伊藤
さんの音声データ再生パッチ付き(*1)の eblook, lookup を使っていま
す。

(*1) http://green.ribbon.to/~ikazuhiro/lookup/lookup.html

そこで、せっかく動画が入った辞書を持っているので、動画対応の
eblook, lookup を作ってみました。よろしかったら使ってくださいま
せ。伊藤さんの音声パッチをあてたあとに、もう一丁添付のパッチをあ
てて下さい。Meadow ではなにも特別な設定をしなくても、動画部分で
クリックしたり、リターンを押すと fiber 経由で mpeg が再生される
と思います。

ぼく自身は 広辞苑第五版と PCサクセス版マイペディアを
http://www31.ocn.ne.jp/~h_ishida/paediatk.html で変換したもの
(*2) で動作を確認しています。「いるか」とか「まっこうくじら」と
か「うぐいす」とかなどなど。
     
が、しかし、実は動作確認したのは UNIX 上だけでして eblook の
Windows バイナリが作れないために Meadow では確認出来ていません。

eblook を cygwin で make して手入力での動作は確認したので大丈夫
だとは思うのですが、cygwin で make すると path の関係か、lookup
から eblook が動かないんですよねー。

(*2) UNIX では MYPAEDIA/MOVIE/ 以下のファイルをすべて
    mv AM000001 am000001 しないとだめでしたが。。。

で、結論としてなにが言いたいかというと、どなたかパッチをあてた
Windows native な eblook.exe いただけないでしょうか ^^;;;
あるいは、こうやると make できるよ、と教えていただけるととっても
うれしいです。

-- 
白井秀行 (mailto:shirai@xxxxxxxxxxx)
--- ChangeLog.orig	2006-06-27 14:31:27.270375000 +0900
+++ ChangeLog	2006-06-27 14:45:27.158775000 +0900
@@ -1,3 +1,10 @@
+2006-06-27  Hideyuki SHIRAI  <shirai@xxxxxxxxxxx>
+
+	* eblook.c (command_table[]): Add commands for movie.
+	(text_hooks[]): Add hooks for movie.
+	(command_mpeg): New function.
+	(hook_img): Handle movie hooks.
+
 2006-04-12  Kazuhiro Ito <kzhr@xxxxxxxxxxxxx>
 
 	* eblook.c: Recognize ebnet URL when DOS_FILE_PATH is defined.
--- eblook.c.orig	2006-06-27 14:31:01.760745000 +0900
+++ eblook.c	2006-06-27 12:46:19.083649000 +0900
@@ -164,6 +164,7 @@
 void command_jpeg (int, char *[]);
 void command_bmp (int, char *[]);
 void command_wav (int, char *[]);
+void command_mpeg (int, char *[]);
 void command_help (int, char *[]);
 
 void command_candidate (int, char *[]);
@@ -302,6 +303,10 @@
   {"wave", "entry_start entry_end file", command_wav, "dump wav sound into file.\n"},
   {"wav", "entry_start entry_end file", command_wav, "dump wav sound into file.\n"},
 #endif
+#ifdef EB_HOOK_BEGIN_MPEG
+  {"mpeg", "id0 id1 id2 id3 file", command_mpeg, "dump mpeg1 movie into file.\n"},
+  {"mpe", "id0 id1 id2 id3 file", command_mpeg, "dump mpeg1 movie into file.\n"},
+#endif
   {NULL, NULL, NULL, NULL}
 };
 
@@ -332,6 +337,10 @@
   {EB_HOOK_BEGIN_WAVE,     hook_img}, 
   {EB_HOOK_END_WAVE,       hook_img}, 
 #endif
+#ifdef EB_HOOK_BEGIN_MPEG
+  {EB_HOOK_BEGIN_MPEG,     hook_img}, 
+  {EB_HOOK_END_MPEG,       hook_img}, 
+#endif
   {EB_HOOK_BEGIN_REFERENCE, hook_tags},
   {EB_HOOK_END_REFERENCE,   hook_tags},
   {EB_HOOK_BEGIN_CANDIDATE, hook_tags},
@@ -1604,6 +1613,90 @@
 }
 #endif
 
+#ifdef EB_HOOK_BEGIN_MPEG
+/* command_mpeg id0 id1 id2 id3 file */
+void
+command_mpeg(argc, argv)
+    int argc;
+    char *argv[];
+{
+    unsigned char binary_data[EB_SIZE_PAGE];
+    EB_Error_Code error_code;
+    ssize_t read_length;
+    FILE *fp;
+    unsigned int mpegid[4];
+    int i;
+    char *mpeg_error = NULL;
+#ifdef DOS_FILE_PATH
+    char *path;
+#endif
+
+    if (argc != 6) {
+        printf("NG: parameter error\n");
+        return;
+    }
+    
+    i = 0;
+    while (i < 4) {
+      mpegid[i] = atoi(argv[i+1]);
+      ++i;
+    }
+    error_code = eb_set_binary_mpeg(&current_book, &mpegid[0]);
+    if (error_code != EB_SUCCESS) {
+        xprintf("NG: eb_set_binary_mpeg:  %s\n", 
+		eb_error_message(error_code));
+        return;
+    }
+
+#ifndef DOS_FILE_PATH
+    fp = fopen(argv[5], "w");
+#else	/* DOS_FILE_PATH */
+    path = strdup(argv[5]);
+    if (!path) {
+	xprintf ("NG: memory full\n");
+	return;
+    }
+    euc_to_sjis(path, path, strlen(path) + 1);
+    fp = fopen(path, "w");
+    free(path);
+#endif	/* !DOS_FILE_PATH */
+    if (fp == NULL) {
+	xprintf("NG: fopen %s: %s\n", argv[3], strerror(errno));
+	return;
+    }
+#if defined(HAVE_SETMODE) && defined(O_BINARY)
+    setmode(fileno(fp), O_BINARY);
+#endif
+
+    while (1) {
+	error_code = eb_read_binary(&current_book, EB_SIZE_PAGE, 
+				    (char *)binary_data, &read_length);
+	if (error_code != EB_SUCCESS) {
+	    mpeg_error = "MPEG read error";
+	    goto mpeg_fail;
+	}
+	if (read_length == 0) 
+	    break;
+	if (1 != fwrite((char *)binary_data, read_length, 1, fp)) {
+	    xprintf("NG: fwrite %s: %s\n", argv[3], strerror(errno));
+	    fclose(fp);
+	    return;
+	}
+    }
+    fclose(fp);
+    printf("OK\n");
+    return;
+
+ mpeg_fail:
+    fclose(fp);
+    if (mpeg_error != NULL) 
+        printf("NG: %s\n",mpeg_error);
+    else 
+        printf("NG\n");
+    return;
+}
+#endif
+
 void
 command_dump (argc, argv)
      int argc;
@@ -2648,7 +2741,7 @@
   case EB_HOOK_BEGIN_WAVE:
     if (argv[2] != 0 && argv[3] != 0) {
       sprintf (buff, "<snd=wav:%d:%d-%d:%d>", argv[2], argv[3], argv[4], argv[5]);
-	eb_write_text_string(book, buff);
+      eb_write_text_string(book, buff);
     }
     break;
   case EB_HOOK_END_WAVE:
@@ -2656,6 +2749,16 @@
     eb_write_text_string(book, buff);
     break;
 #endif
+#ifdef EB_HOOK_BEGIN_MPEG
+  case EB_HOOK_BEGIN_MPEG:
+    sprintf (buff, "<mov=mpg:%d,%d,%d,%d>", argv[2], argv[3], argv[4], argv[5]);
+    eb_write_text_string(book, buff);
+    break;
+  case EB_HOOK_END_MPEG:
+    strcpy (buff, "</mov>");
+    eb_write_text_string(book, buff);
+    break;
+#endif
   }
   return EB_SUCCESS;
 }
--- ChangeLog.orig	2006-06-27 17:29:03.234366000 +0900
+++ ChangeLog	2006-06-27 18:18:31.283508000 +0900
@@ -1,3 +1,28 @@
+2006-06-27  Hideyuki SHIRAI  <shirai@xxxxxxxxxxx>
+
+	* ndeb-binary.el (ndeb-binary-programs): Change default value for
+	Meadow.
+	(ndeb-binary-extensions): Add a extension for movie.
+	(ndeb-movie-default-caption): New option.
+	(ndeb-movie-caption-format): Ditto.
+	(ndeb-play-movie-from-entry): Ditto.
+	(ndeb-movie-caption-face): New face.
+	(ndeb): Put :movie-regexp.
+	(ndeb-binary-extract-commands): Add command for movie.
+	(ndeb-binary-format-caption): Support movie.
+	(ndeb-arrange-movie): New function.
+	(ndeb-binary-follow-link): Use `princ' when display message.
+	(ndeb-binary-follow-first-link): Rename form
+	`ndeb-binary-follow-first-sound' and modify.
+	(lookup-entry-play-ndeb-movie): New function.
+	(lookup-entry-play-ndeb-sound): Use
+	`ndeb-binary-follow-first-link' instead of `-first-sound'.
+	(ndeb-arrange-snd-autoplay): Ditto.
+	(top): Enable playing movie from Entry mode when
+	ndeb-play-movie-from-entry's value is non-nil.
+
+	* ndeb.el (ndeb): Put `ndeb-arrange-wave' to :arranges.
+
 2006-06-21 Kazuhiro Ito <kzhr@xxxxxxxxxxxxx>
 
 	* lookup-types.el:
--- ndeb-binary.el.orig	2006-06-27 14:49:59.385026000 +0900
+++ ndeb-binary.el	2006-06-27 18:18:45.243306000 +0900
@@ -35,8 +35,14 @@
 
 (defcustom ndeb-binary-programs
   (cond
-   ((functionp 'mw32-mci-send-string)
-    '((wave ndeb-binary-play-with-mci)))
+   ((featurep 'meadow)
+    `(,(if (functionp 'mw32-mci-send-string)
+	   '(wave ndeb-binary-play-with-mci)
+	 '(wave ("fiber" "-s")))
+      (movie ("fiber" "-s"))
+      (bmp ("fiber" "-s"))
+      (xbm ("fiber" "-s"))
+      (jpeg ("fiber" "-s"))))
    ((functionp 'play-sound-file)
     '((wave ndeb-binary-play-sound-file)))
    (t nil))
@@ -68,6 +74,7 @@
 		   (const bmp)
 		   (const jpeg)
 		   (const wave)
+		   (const movie)
 		   symbol)
 	   (cons :format "%v"
 		 (string :tag "Program")
@@ -94,7 +101,8 @@
     (bmp . "bmp")
     (tiff . "tif")
     (jpeg . "jpg")
-    (wave . "wav"))
+    (wave . "wav")
+    (movie . "mpg"))
   "Alist of binary type vs. filename extension used to create a
 temporary file. Each element looks like:
 
@@ -142,6 +150,24 @@
   :type '(choice (const nil) string)
   :group 'ndeb-binary)
 
+(defcustom ndeb-movie-default-caption "動画"
+  "Default string to be used when the caption of a movie is empty."
+  :type 'string
+  :group 'ndeb-binary)
+
+(defcustom ndeb-movie-caption-format "《%s》"
+  "Format string for the caption of a movie.
+This string is passed to `format' function with the original text."
+  :type '(choice (const nil) string)
+  :group 'ndeb-binary)
+
+(defcustom ndeb-play-movie-from-entry nil
+"A string or a vector of symbols and characters meaning a
+sequence of keystrokes and events for `lookup-entry-play-ndeb-movie'.
+If nil no keystrokes are assigned."
+  :type '(choice (const nil) string)
+  :group 'ndeb-binary)
+
 (defface ndeb-image-caption-face
   '((((class color) (background light)) (:foreground "Gray50"))
     (((class color) (background dark)) (:foreground "Gray75")))
@@ -162,6 +188,13 @@
   :group 'ndeb-binary
   :group 'lookup-faces)
 
+(defface ndeb-movie-caption-face
+  '((((class color) (background light)) (:foreground "Green4"))
+    (((class color) (background dark)) (:foreground "GreenYellow")))
+  "Face used to highlight the caption of a movie."
+  :group 'ndeb-binary
+  :group 'lookup-faces)
+
 ;;;
 ;;; Internal variables
 ;;;
@@ -181,6 +214,8 @@
      '("<img=jpeg>" . "</img=\\([^>]+\\)>"))
 (put 'ndeb :wave-regexp
      '("<snd=wav:\\([0-9]+:[0-9]+\\)-\\([0-9]+:[0-9]+\\)>" . "</snd>"))
+(put 'ndeb :movie-regexp
+     '("<mov=mpg:\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\)>" . "</mov>"))
 
 (defconst ndeb-binary-extract-commands
   ;; or should be set as dictionary options...??
@@ -188,7 +223,8 @@
     (bmp . "bmp %s %%s")
     (tiff . "bmp2tiff %s %%s")
     (jpeg . "jpeg %s %%s")
-    (wave . "wav %s %%s"))
+    (wave . "wav %s %%s")
+    (movie . "mpeg %s %%s"))
   "Alist of binary type vs. format string of an eblook command to
 extract the target entry.")
 
@@ -385,7 +421,8 @@
 		  (while (string-match "/" file)
 		    (setq file (replace-match sep t t file)))))
 	      (setq params (append params (list file)))
-	      (message (mapconcat (lambda (x) x) params " "))
+	      (princ (mapconcat 'identity params " "))
+	      (sit-for 3)
 	      (setq process (or (apply 'start-process
 				       "ndeb-binary"
 				       (get-buffer "*Messages*")
@@ -405,14 +442,15 @@
 	  (ndeb-binary-unbind-temporary-file dictionary target)
 	  (error (message "%s" err))))))))
 
-(defun ndeb-binary-follow-first-sound ()
+(defun ndeb-binary-follow-first-link (type)
   "Internal use. Call from beginning of buffer."
   (let (point)
-    (while (setq point (next-single-property-change (point) 'ndeb-binary))
-      (goto-char point)
-      (when (eq (lookup-assq-ref (ndeb-binary-get-link point) 'type) 'wave)
-	(ndeb-binary-follow-link)
-	(point-max)))))
+    (catch 'loop
+      (while (setq point (next-single-property-change (point) 'ndeb-binary))
+	(goto-char point)
+	(when (eq (lookup-assq-ref (ndeb-binary-get-link point) 'type) type)
+	  (ndeb-binary-follow-link)
+	  (throw 'loop t))))))
 
 (defun ndeb-binary-mouse-follow (event)
   "Play the binary you click on."
@@ -505,7 +543,23 @@
       (with-current-buffer lookup-content-buffer
 	(save-excursion
 	  (goto-char (point-min))
-	  (ndeb-binary-follow-first-sound))))
+	  (unless (ndeb-binary-follow-first-link 'wave)
+	    (message "No sound")))))
+    (error "Please set ndeb-binary-programs for wave")))
+
+(defun lookup-entry-play-ndeb-movie ()
+  "Play first movie link of ndeb contents."
+  (interactive)
+  (if (assq 'movie ndeb-binary-programs)
+      (let ((dictionary
+	     (lookup-entry-dictionary (lookup-entry-current-line-entry))))
+	(unless (lookup-entry-content-visible-p)
+	  (lookup-entry-display-content))
+	(with-current-buffer lookup-content-buffer
+	  (save-excursion
+	    (goto-char (point-min))
+	    (unless (ndeb-binary-follow-first-link 'movie)
+	      (message "No movie")))))
     (error "Please set ndeb-binary-programs for wave")))
 
 ;;;
@@ -515,13 +569,19 @@
 (defun ndeb-binary-format-caption (start end type target &rest params)
   "Format captions for binary links."
   (let (caption-format caption-face caption)
-    (if (eq type 'wave)
-	(setq caption ndeb-sound-default-caption
-	      caption-format ndeb-sound-caption-format
-	      caption-face 'ndeb-sound-caption-face)
+    (cond
+     ((eq type 'wave)
+      (setq caption ndeb-sound-default-caption
+	    caption-format ndeb-sound-caption-format
+	    caption-face 'ndeb-sound-caption-face))
+     ((eq type 'movie)
+      (setq caption ndeb-movie-default-caption
+	    caption-format ndeb-movie-caption-format
+	    caption-face 'ndeb-movie-caption-face))
+     (t
       (setq caption ndeb-image-default-caption
 	    caption-format ndeb-image-caption-format
-	    caption-face 'ndeb-image-caption-face))
+	    caption-face 'ndeb-image-caption-face)))
     (goto-char start)
     (unless (= start end)
       (setq caption (buffer-substring start end))
@@ -655,12 +715,32 @@
 						(concat pos_start " " pos_end)))
 	  (error (message "%s" err)))))))
 
+(defun ndeb-arrange-movie (entry)
+  "Arrange movie on an ndeb entry."
+  (let* ((dictionary (lookup-entry-dictionary entry))
+	 (regexp (lookup-dictionary-option dictionary :movie-regexp t)))
+    (while (re-search-forward (car regexp) nil t)
+      (let ((id1 (match-string 1))
+	    (id2 (match-string 2))
+	    (id3 (match-string 3))
+	    (id4 (match-string 4))
+	    (start (match-beginning 0)))
+	(replace-match "" t t)
+	(condition-case err
+	    (let (end)
+	      (re-search-forward (cdr regexp))
+	      (setq end (match-beginning 0))
+	      (replace-match "" t t)
+	      (ndeb-binary-format-caption start end 'movie
+					  (concat id1 " " id2 " " id3 " " id4)))
+	  (error (message "%s" err)))))))
+
 (defun ndeb-arrange-snd-autoplay (entry)
   "Arrange function for Lookup to play sound in an ndeb entry if option :snd-autoplay is non-nil."
   (when (and (lookup-dictionary-option (lookup-entry-dictionary entry)
 				       ':snd-autoplay nil)
 	     (assq 'wave ndeb-binary-programs))
-    (ndeb-binary-follow-first-sound)))
+    (ndeb-binary-follow-first-link 'wave)))
 
 ;;;
 ;;; Setup
@@ -673,6 +753,11 @@
     '(define-key lookup-entry-mode-map ndeb-play-sound-from-entry
        (function lookup-entry-play-ndeb-sound))))
 
+(when ndeb-play-movie-from-entry
+  (eval-after-load "lookup-entry"
+    '(define-key lookup-entry-mode-map ndeb-play-movie-from-entry
+       (function lookup-entry-play-ndeb-movie))))
+
 ;;;
 ;;; Cleanup
 ;;;
--- ndeb.el.orig	2006-06-27 14:49:59.425025000 +0900
+++ ndeb.el	2006-06-27 11:03:48.000000000 +0900
@@ -123,6 +123,7 @@
        ndeb-arrange-bmp
        ndeb-arrange-jpeg
        ndeb-arrange-wave
+       ndeb-arrange-movie
        ndeb-arrange-ignore
        ndeb-arrange-no-newline
        ndeb-arrange-prev-next