| 1 | /* emms-print-metadata.c --- Info function for libtag |
| 2 | Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
| 3 | |
| 4 | Author: Trent Buck <trentbuck@gmail.com> |
| 5 | |
| 6 | This file is part of EMMS. |
| 7 | |
| 8 | EMMS is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 3, or (at your option) |
| 11 | any later version. |
| 12 | |
| 13 | EMMS is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with EMMS; see the file COPYING. If not, write to |
| 20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | Boston, MA 02110-1301, USA. */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
| 25 | #include <tag_c.h> |
| 26 | |
| 27 | int |
| 28 | main (int argc, char **argv) |
| 29 | { |
| 30 | TagLib_File *file; |
| 31 | TagLib_Tag *tag; |
| 32 | const TagLib_AudioProperties *properties; |
| 33 | |
| 34 | if (argc != 2) |
| 35 | { |
| 36 | fprintf (stderr, "usage: emms-print-metadata file.{mp3,ogg,flac}\nother formats may work as well.\n"); |
| 37 | exit (1); |
| 38 | } |
| 39 | |
| 40 | file = taglib_file_new (argv[1]); |
| 41 | |
| 42 | if (!file) |
| 43 | { |
| 44 | fprintf (stderr, "%s: File does not exist or is of an unknown type\n", argv[1]); |
| 45 | exit (1); |
| 46 | } |
| 47 | |
| 48 | tag = taglib_file_tag (file); |
| 49 | |
| 50 | /* Apparently, if the file is named foo.mp3 or similar, the library |
| 51 | still can open it, for whatever reason. |
| 52 | */ |
| 53 | if (!tag) |
| 54 | { |
| 55 | fprintf (stderr, "%s: File does not exist or is of an unknown type\n", argv[1]); |
| 56 | exit (1); |
| 57 | } |
| 58 | |
| 59 | printf ("info-artist=%s\n", taglib_tag_artist (tag)); |
| 60 | printf ("info-title=%s\n", taglib_tag_title (tag)); |
| 61 | printf ("info-album=%s\n", taglib_tag_album (tag)); |
| 62 | printf ("info-tracknumber=%d\n", taglib_tag_track (tag)); |
| 63 | printf ("info-year=%d\n", taglib_tag_year (tag)); |
| 64 | printf ("info-genre=%s\n", taglib_tag_genre (tag)); |
| 65 | printf ("info-note=%s\n", taglib_tag_comment (tag)); |
| 66 | |
| 67 | properties = taglib_file_audioproperties (file); |
| 68 | printf ("info-playing-time=%d\n", |
| 69 | properties ? taglib_audioproperties_length (properties) : 0); |
| 70 | |
| 71 | taglib_tag_free_strings (); |
| 72 | taglib_file_free (file); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | /* emms-print-metadata.c ends here. */ |