1 /* libxmms-flac - XMMS FLAC input plugin
2 * Copyright (C) 2000,2001,2002 Josh Coalson
3 * Copyright (C) 2002 Daisuke Shimamura
5 * Based on FLAC plugin.c and mpg123 plugin
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <xmms/plugin.h>
27 #include <xmms/util.h>
28 #include <xmms/configfile.h>
29 #include <xmms/titlestring.h>
31 #include "FLAC/metadata.h"
32 #include "plugin_common/id3v1.h"
33 #include "plugin_common/id3v2.h"
35 #include "configure.h"
38 * Function local__extname (filename)
40 * Return pointer within filename to its extenstion, or NULL if
41 * filename has no extension.
44 static char *local__extname(const char *filename)
46 char *ext = strrchr(filename, '.');
54 static char *local__getstr(char* str)
56 if (str && strlen(str) > 0)
61 static int local__getnum(char* str)
63 if (str && strlen(str) > 0)
69 * Function flac_format_song_title (tag, filename)
71 * Create song title according to `tag' and/or `filename' and
72 * return it. The title must be subsequently freed using g_free().
75 char *flac_format_song_title(char *filename)
78 TitleInput *input = NULL;
79 FLAC_Plugin__CanonicalTag tag;
81 FLAC_plugin__canonical_tag_init(&tag);
83 FLAC_plugin__canonical_tag_get_combined(filename, &tag);
85 if(flac_cfg.title.convert_char_set) {
86 convert_from_file_to_user_in_place(&tag.title);
87 convert_from_file_to_user_in_place(&tag.composer);
88 convert_from_file_to_user_in_place(&tag.performer);
89 convert_from_file_to_user_in_place(&tag.album);
90 convert_from_file_to_user_in_place(&tag.year_recorded);
91 convert_from_file_to_user_in_place(&tag.year_performed);
92 convert_from_file_to_user_in_place(&tag.track_number);
93 convert_from_file_to_user_in_place(&tag.tracks_in_album);
94 convert_from_file_to_user_in_place(&tag.genre);
95 convert_from_file_to_user_in_place(&tag.comment);
98 XMMS_NEW_TITLEINPUT(input);
100 input->performer = local__getstr(tag.performer);
101 if(!input->performer)
102 input->performer = local__getstr(tag.composer);
103 input->album_name = local__getstr(tag.album);
104 input->track_name = local__getstr(tag.title);
105 input->track_number = local__getnum(tag.track_number);
106 input->year = local__getnum(tag.year_performed);
107 input->genre = local__getstr(tag.genre);
108 input->comment = local__getstr(tag.comment);
110 input->file_name = g_basename(filename);
111 input->file_path = filename;
112 input->file_ext = local__extname(filename);
113 ret = xmms_get_titlestring(flac_cfg.title.tag_override ? flac_cfg.title.tag_format : xmms_get_gentitle_format(), input);
118 * Format according to filename.
120 ret = g_strdup(g_basename(filename));
121 if (local__extname(ret) != NULL)
122 *(local__extname(ret) - 1) = '\0'; /* removes period */
125 FLAC_plugin__canonical_tag_clear(&tag);