;;;###autoload
(defun sqlite-file-p (filename)
"Return non-nil if FILENAME is actually SQLite format 3 file."
- ;; Unfortunately `magic:file-type' does not recognizes SQLite files,
- ;; so do it by hand
- (with-temp-buffer
- (insert-file-contents-literally filename nil 0 15)
- (string= (buffer-substring) "SQLite format 3")))
+ (string= (magic:file filename :mime-type)
+ "application/x-sqlite3"))
;;;###autoload
(defun sqlite-open (file)
(dllist-to-list result))))
-;;; FIXME: this isn't failsafe, use #'magic:file-type instead.
-(defvar taglib:extensions
- '("mp3" "mpc" "ogg" "flac" "spx" "wv" "tta")
- "List of file types that taglib supports.")
+
+(defvar taglib:mimetypes
+'("audio/aiff"
+ "audio/flac"
+ "audio/mp4"
+ "audio/mpeg"
+ "audio/ogg"
+ "audio/speex"
+ "audio/tta"
+ "audio/x-aiff"
+ "audio/x-m4a"
+ "audio/x-mp4a-latm"
+ "audio/x-musepack"
+ "audio/x-tta"
+ ;; Taglib supports some video types as well, who knew?! ATM
+ ;; ffi-taglib.el is single-mindedly audio focused. We should
+ ;; broaden its horizons. --SY.
+ ;; "video/mp4"
+ ;; "video/mpeg"
+ ;; "video/ogg"
+ ;; "video/x-ms-asf"
+)
+"List of MIME audio subtypes that taglib supports.")
(defvar taglib:editable-tagnames
'("album" "artist" "comment" "genre" "title" "track" "year")
(mapfam #'list taglib:tagnames) nil t)))
(when (string= tag "")
(error 'invalid-argument tag))
- ;; better done with #'magic:file-type
- (unless (member (file-name-extension (file-basename file))
- taglib:extensions)
- (error "Unsupported file type: %s" (file-name-extension
- (file-basename file))))
+ (let ((ftype (magic:file file :mime-type)))
+ (unless (member ftype taglib:mimetypes)
+ (error "Unsupported file type: %s" ftype)))
(let* ((fo (taglib:file-new (expand-file-name file)))
(to (taglib:file-tag fo))
tfun res)
;;;###autoload
(defun taglib:list-all-tags (file)
- "Display a buffer showing all the tags of FILE."
+ "Display a buffer showing all the tags of FILE.
+
+This function is for interactive use only."
(interactive "fFilename: ")
(unless (interactive-p)
(error 'invalid-operation "Interactive only function"))
+ (let ((ftype (magic:file file :mime-type)))
+ (unless (member ftype taglib:mimetypes)
+ (error "Unsupported file type: %s" ftype)))
(let ((buf (get-buffer-create "*taglib:tags*"))
(tags (taglib:properties file)))
(with-current-buffer buf
;;;###autoload
(defun Wand-file-supported-for-read-p (file)
"Return non-nil if Wand can decode FILE."
- ;; Try by extension first, then try heuristic method using
- ;; `magic:file-type'
- (let ((ext (file-name-extension file)))
- (or (and ext (Wand-format-supported-for-read-p ext))
-
- (multiple-value-bind (itype imagetext)
- (split-string (or (magic:file-type file) " ") " ")
- (and imagetext
- (string= (downcase imagetext) "image")
- (Wand-format-supported-for-read-p itype))))))
+ ;; Use `magic:file-image-p' first, fallback to file extension check
+ ;; if that fails.
+ (let ((itype (magic:file-image-p file))
+ (ext (file-name-extension file)))
+ (or (and itype (Wand-format-supported-for-read-p itype))
+ (and ext (Wand-format-supported-for-read-p ext)))))
(defun Wand-formats-list (fmt-regexp &optional mode)
"Return names of supported formats that matches FMT-REGEXP.