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: Sun, 18 Oct 2015 23:25:01 +0300

New program emms-print-taglib-metadata uses TagLib's C++ interface to
extract track information.
---
 AUTHORS                            |  1 +
 Makefile                           |  5 ++
 lisp/emms-info.el                  | 14 +++++-
 src/emms-print-taglib-metadata.cpp | 96 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 114 insertions(+), 2 deletions(-)
 create mode 100644 src/emms-print-taglib-metadata.cpp

diff --git a/AUTHORS b/AUTHORS
index 3111770..e84c4ab 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -27,6 +27,7 @@ Ye Wenbin              <address@hidden>
 Yoni (Johnathan) Rabkin  <address@hidden>
 mathias.dahl            <mathias.dahl>
 Rasmus Pank Roulund      <address@hidden>
+Petteri Hintsanen        <address@hidden>
 
 ;; Local variables:
 ;; coding: utf-8
diff --git a/Makefile b/Makefile
index c0846d6..dda3640 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,8 @@ DOCDIR=doc/
 LISPDIR=lisp
 SRCDIR=src
 
+CXXFLAGS=-std=c++11
+
 ALLSOURCE=$(wildcard $(LISPDIR)/*.el)
 ALLCOMPILED=$(wildcard $(LISPDIR)/*.elc)
 
@@ -37,6 +39,9 @@ docs:
 emms-print-metadata: $(SRCDIR)/emms-print-metadata.c
        $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $(SRCDIR)/$@ $< 
`taglib-config --cflags --libs` -ltag_c
 
+emms-print-taglib-metadata: $(SRCDIR)/emms-print-taglib-metadata.cpp
+       $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $(SRCDIR)/$@ $< 
`taglib-config --cflags --libs`
+
 install:
        test -d $(SITELISP) || mkdir -p $(SITELISP)
        test -d $(INFODIR) || install -d $(INFODIR)
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-taglib-metadata.cpp 
b/src/emms-print-taglib-metadata.cpp
new file mode 100644
index 0000000..9e3f1d7
--- /dev/null
+++ b/src/emms-print-taglib-metadata.cpp
@@ -0,0 +1,96 @@
+/* emms-print-taglib-metadata.cpp --- Info function for TagLib
+   Copyright (C) 2015  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 std::vector<std::string> 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 << "Usage: emms-print-metadata file.{mp3,ogg,flac}\n"
+        "Other formats may work as well.\n";
+      return 1;
+    }
+
+  TagLib::FileRef file (argv[1]);
+  if (file.isNull ()) return 1;
+
+  const auto tags = file.file ()->properties ();
+
+  for (const auto& tag : tags_to_extract)
+    {
+      print_tag (tags, tag);
+    }
+
+  int length = 0;
+  if (file.audioProperties ())
+    {
+      auto 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 ())
+    {
+      // TODO: Extract all values, not only the first one.  EMMS needs
+      // to be extended to handle such values.
+      auto 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]