1 /* libxmms-flac - XMMS FLAC input plugin
2 * Copyright (C) 2000-2009 Josh Coalson
3 * Copyright (C) 2011-2013 Xiph.Org Foundation
4 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Daisuke Shimamura
6 * Based on FLAC plugin.c and mpg123 plugin
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program 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.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <xmms/plugin.h>
30 #include <xmms/util.h>
31 #include <xmms/configfile.h>
32 #include <xmms/titlestring.h>
34 #include "FLAC/metadata.h"
35 #include "plugin_common/tags.h"
37 #include "configure.h"
40 * Function local__extname (filename)
42 * Return pointer within filename to its extenstion, or NULL if
43 * filename has no extension.
46 static char *local__extname(const char *filename)
48 char *ext = strrchr(filename, '.');
56 static char *local__getstr(char* str)
58 if (str && strlen(str) > 0)
63 static int local__getnum(char* str)
65 if (str && strlen(str) > 0)
70 static char *local__getfield(const FLAC__StreamMetadata *tags, const char *name)
73 const char *utf8 = FLAC_plugin__tags_get_tag_utf8(tags, name);
75 if(flac_cfg.title.convert_char_set)
76 return convert_from_utf8_to_user(utf8);
85 static void local__safe_free(char *s)
92 * Function flac_format_song_title (tag, filename)
94 * Create song title according to `tag' and/or `filename' and
95 * return it. The title must be subsequently freed using g_free().
98 char *flac_format_song_title(char *filename)
101 TitleInput *input = NULL;
102 FLAC__StreamMetadata *tags;
103 char *title, *artist, *performer, *album, *date, *tracknumber, *genre, *description;
105 FLAC_plugin__tags_get(filename, &tags);
107 title = local__getfield(tags, "TITLE");
108 artist = local__getfield(tags, "ARTIST");
109 performer = local__getfield(tags, "PERFORMER");
110 album = local__getfield(tags, "ALBUM");
111 date = local__getfield(tags, "DATE");
112 tracknumber = local__getfield(tags, "TRACKNUMBER");
113 genre = local__getfield(tags, "GENRE");
114 description = local__getfield(tags, "DESCRIPTION");
116 XMMS_NEW_TITLEINPUT(input);
118 input->performer = local__getstr(artist);
119 if(!input->performer)
120 input->performer = local__getstr(performer);
121 input->album_name = local__getstr(album);
122 input->track_name = local__getstr(title);
123 input->track_number = local__getnum(tracknumber);
124 input->year = local__getnum(date);
125 input->genre = local__getstr(genre);
126 input->comment = local__getstr(description);
128 input->file_name = g_basename(filename);
129 input->file_path = filename;
130 input->file_ext = local__extname(filename);
131 ret = xmms_get_titlestring(flac_cfg.title.tag_override ? flac_cfg.title.tag_format : xmms_get_gentitle_format(), input);
136 * Format according to filename.
138 ret = g_strdup(g_basename(filename));
139 if (local__extname(ret) != NULL)
140 *(local__extname(ret) - 1) = '\0'; /* removes period */
143 FLAC_plugin__tags_destroy(&tags);
144 local__safe_free(title);
145 local__safe_free(artist);
146 local__safe_free(performer);
147 local__safe_free(album);
148 local__safe_free(date);
149 local__safe_free(tracknumber);
150 local__safe_free(genre);
151 local__safe_free(description);