emms-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emms-help] [PATCH] New metadata extraction program


From: Petteri Hintsanen
Subject: [emms-help] [PATCH] New metadata extraction program
Date: Sat, 10 Dec 2016 18:43:33 +0200

Rewrite emms-print-metadata to use TagLib's C++ interface.
---
 Makefile                    |   4 +-
 doc/emms.texinfo            |   6 +--
 emms-print-metadata.1       |  39 +++++----------
 lisp/emms-info.el           |  14 +++++-
 src/emms-print-metadata.c   |  77 ------------------------------
 src/emms-print-metadata.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 140 insertions(+), 112 deletions(-)
 delete mode 100644 src/emms-print-metadata.c
 create mode 100644 src/emms-print-metadata.cpp

diff --git a/Makefile b/Makefile
index 1b896dd..4e4584c 100644
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,8 @@ lisp:
 docs:
        $(MAKE) -C $(DOCDIR)
 
-emms-print-metadata: $(SRCDIR)/emms-print-metadata.c
-       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(SRCDIR)/$@ $< 
`taglib-config --cflags --libs` -ltag_c
+emms-print-metadata: $(SRCDIR)/emms-print-metadata.cpp
+       $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(SRCDIR)/$@ $< 
`taglib-config --cflags --libs`
 
 install:
        test -d $(SITELISP) || mkdir -p $(SITELISP)
diff --git a/doc/emms.texinfo b/doc/emms.texinfo
index 60a8957..99576ed 100644
--- a/doc/emms.texinfo
+++ b/doc/emms.texinfo
@@ -882,8 +882,8 @@ software. Likewise, mp3 track information is available using
 @uref{http://www.ibiblio.org/mp3info/, mp3info}. @file{emms-cue.el}
 retrieves tracks information for ape/flac files by parsing a cue sheet
 file, which is plain text. Finally, @file{emms-info-libtag.el} uses a
-tiny C shim (included in the src/ directory) program to take advantage
-of @uref{http://taglib.github.io/, TagLib}.
+tiny C++ shim (included in the src/ directory) program to take advantage
+of @uref{http://taglib.org/, TagLib}.
 
 Automatic track information retrieval is enabled by default in the
 `emms-all' setup level provided by @file{emms-setup.el}. For more
@@ -922,7 +922,7 @@ track as argument.
 @cindex using taglib
 
 The communication with the TagLib library is done via a tiny program
-written in C @file{emms-print-metadata.c}. To compile
+written in C++ @file{emms-print-metadata.cpp}. To compile
 @file{emms-print-metadata} invoke:
 
 @command{make emms-print-metadata}
diff --git a/emms-print-metadata.1 b/emms-print-metadata.1
index cd1149f..5a07cf3 100644
--- a/emms-print-metadata.1
+++ b/emms-print-metadata.1
@@ -1,34 +1,17 @@
 .\"                                      Hey, EMACS: -*- nroff -*-
-.\" First parameter, NAME, should be all caps
-.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
-.\" other parameters are allowed: see man(7), man(1)
-.TH EMMS-PRINT-METADATA 1 "April 29, 2006" EMMS
-.\" Please adjust this date whenever revising the manpage.
-.\"
-.\" Some roff macros, for reference:
-.\" .nh        disable hyphenation
-.\" .hy        enable hyphenation
-.\" .ad l      left justify
-.\" .ad b      justify to both left and right margins
-.\" .nf        disable filling
-.\" .fi        enable filling
-.\" .br        insert line break
-.\" .sp <n>    insert n+1 empty lines
-.\" for manpage-specific macros, see man(7)
+.TH EMMS-PRINT-METADATA 1 2016-12-10 "EMMS"
 .SH NAME
-emms-print-metadata \- Print information about music files
+emms-print-metadata \- extract metadata from audio files
 .SH SYNOPSIS
-.B emms-print-metadata
-.RI file.ext
-.br
+.BI "emms-print-metadata " FILE
 .SH DESCRIPTION
-.\" TeX users may be more comfortable with the \fB<whatever>\fP and
-.\" \fI<whatever>\fP escape sequences to invoke bold face and italics,
-.\" respectively.
-\fBemms-print-metadata\fP will print metadata about music files to
-stdout, to be used primarily by EMMS, the Emacs MultiMedia System.
+.B emms-print-metadata
+extracts and prints metadata information about
+.IR FILE .
+The output format is specific to EMMS, the Emacs Multimedia System:
+.B emms-print-metadata
+is designed to be invoked by EMMS instead of the user.
+.SH EXIT STATUS
+The exit status is normally\ 0.  If an error occurs, the exit status is\ 1.
 .SH SEE ALSO
 .BR emms (info)
-.br
-.SH AUTHOR
-emms-print-metadata was written by Trent Buck.
diff --git a/lisp/emms-info.el b/lisp/emms-info.el
index cfc206b..46b8cd9 100644
--- a/lisp/emms-info.el
+++ b/lisp/emms-info.el
@@ -1,6 +1,6 @@
 ;;; emms-info.el --- Retrieving track information
 
-;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation 
Inc.
+;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2015  Free Software 
Foundation Inc.
 
 ;; Author: Jorgen Schaefer <address@hidden>
 
@@ -29,16 +29,26 @@
 ;; The code will add info symbols to the track. The following symbols
 ;; are defined:
 
-;; info-artist - string naming the artist
+;; info-albumartist - string naming the album artist
+;; info-albumartistsort - string key for album artist collation
+;; info-artist - string naming the track artist
+;; info-artistsort - string key for artist collation
 ;; info-composer - string naming the composer
+;; info-composersort - string key for composer collation
 ;; info-performer - string naming the performer
 ;; info-title - string naming the title of the song
+;; info-titlesort - string key for title collation
 ;; info-album - string naming the album
+;; info-albumsort - string key for album collation
 ;; info-tracknumber - string(?) naming the track number
 ;; info-discnumber - string naming the disc number
 ;; info-year - string naming the year
+;; info-originalyear - string naming the original release year
+;; info-date - string naming the release date
+;; info-originaldate - string naming the original release date
 ;; info-note - string of free-form entry
 ;; info-genre - string naming the genre
+;; info-label - string for the record label
 ;; info-playing-time - number giving the seconds of playtime
 
 ;;; Code:
diff --git a/src/emms-print-metadata.c b/src/emms-print-metadata.c
deleted file mode 100644
index 48f4904..0000000
--- a/src/emms-print-metadata.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/* emms-print-metadata.c --- Info function for libtag
-   Copyright (C) 2005, 2006, 2007, 2008, 2009  Free Software Foundation, Inc.
-
-Author: Trent Buck <address@hidden>
-
-This file is part of EMMS.
-
-EMMS is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
-
-EMMS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with EMMS; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <tag_c.h>
-
-int
-main (int argc, char **argv)
-{
-  TagLib_File *file;
-  TagLib_Tag *tag;
-  const TagLib_AudioProperties *properties;
-
-  if (argc != 2)
-    {
-      fprintf (stderr, "usage: emms-print-metadata file.{mp3,ogg,flac}\nother 
formats may work as well.\n");
-      exit (1);
-    }
-
-  file = taglib_file_new (argv[1]);
-
-  if (!file)
-    {
-      fprintf (stderr, "%s: File does not exist or is of an unknown type\n", 
argv[1]);
-      exit (1);
-    }
-
-  tag = taglib_file_tag (file);
-
-  /* Apparently, if the file is named foo.mp3 or similar, the library
-     still can open it, for whatever reason.
-  */
-  if (!tag)
-    {
-      fprintf (stderr, "%s: File does not exist or is of an unknown type\n", 
argv[1]);
-      exit (1);
-    }
-
-  printf ("info-artist=%s\n", taglib_tag_artist (tag));
-  printf ("info-title=%s\n", taglib_tag_title (tag));
-  printf ("info-album=%s\n", taglib_tag_album (tag));
-  printf ("info-tracknumber=%d\n", taglib_tag_track (tag));
-  printf ("info-year=%d\n", taglib_tag_year (tag));
-  printf ("info-genre=%s\n", taglib_tag_genre (tag));
-  printf ("info-note=%s\n", taglib_tag_comment (tag));
-
-  properties = taglib_file_audioproperties (file);
-  printf ("info-playing-time=%d\n",
-         properties ? taglib_audioproperties_length (properties) : 0);
-
-  taglib_tag_free_strings ();
-  taglib_file_free (file);
-
-  return 0;
-}
-
-/* emms-print-metadata.c ends here. */
diff --git a/src/emms-print-metadata.cpp b/src/emms-print-metadata.cpp
new file mode 100644
index 0000000..2e7f4a3
--- /dev/null
+++ b/src/emms-print-metadata.cpp
@@ -0,0 +1,112 @@
+/* emms-print-metadata.cpp --- Info function for TagLib
+   Copyright (C) 2016  Free Software Foundation, Inc.
+
+Author: Petteri Hintsanen <address@hidden>
+
+This file is part of EMMS.
+
+EMMS is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+EMMS is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with EMMS; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+#include <taglib/fileref.h>
+#include <taglib/tag.h>
+#include <taglib/tpropertymap.h>
+#include <iostream>
+
+static const char* const tags_to_extract[] = {
+  "album",
+  "albumsort",
+  "albumartist",
+  "albumartistsort",
+  "artist",
+  "artistsort",
+  "composer",
+  "composersort",
+  "performer",
+  "year",
+  "originalyear",
+  "date",
+  "originaldate",
+  "genre",
+  "label",
+  "title",
+  "titlesort",
+  "tracknumber",
+  "discnumber"
+};
+
+void print_tag (const TagLib::PropertyMap& tags, const std::string& tag);
+
+int
+main (int argc, char* argv[])
+{
+  if (argc != 2)
+    {
+      std::cerr << argv[0] << ": "
+                << "usage: emms-print-metadata FILENAME"
+                << std::endl
+                << "FILENAME must end to one of these extensions: "
+                << TagLib::FileRef::defaultFileExtensions ()
+                << std::endl;
+      return 1;
+    }
+
+  TagLib::FileRef file (argv[1]);
+  if (file.isNull ()) {
+      std::cerr << argv[0] << ": "
+                << argv[1] << ": "
+                << "file does not exist or is of an unknown type"
+                << std::endl;
+      return 1;
+  }
+
+  const TagLib::PropertyMap tags = file.file ()->properties ();
+  if (tags.isEmpty ()) {
+      std::cerr << argv[0] << ": "
+                << argv[1] << ": "
+                << "file does not have tags or is of an unknown type"
+                << std::endl;
+      return 1;
+  }
+
+  for (unsigned int i = 0; i < sizeof (tags_to_extract) / sizeof (char*);
+       i++)
+    {
+      print_tag (tags, tags_to_extract[i]);
+    }
+
+  int length = 0;
+  if (file.audioProperties ())
+    {
+      const TagLib::AudioProperties* properties = file.audioProperties ();
+      length = properties->length ();
+    }
+  std::cout << "info-playing-time=" << length << std::endl;
+
+  return 0;
+}
+
+void
+print_tag (const TagLib::PropertyMap& tags, const std::string& tag)
+{
+  TagLib::StringList values = tags[tag];
+  if (!values.isEmpty ())
+    {
+      const TagLib::String& value = values.front ();
+      std::cout << "info-" << tag << "=" << value.to8Bit (true) << std::endl;
+    }
+}
+
+/* emms-print-taglib-metadata.cpp ends here. */
-- 
2.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]