Mercurial > audlegacy
annotate Plugins/Input/flac/tag.c @ 1458:f12d7e208b43 trunk
[svn] Update FSF address in copyright notices. Update autotools templates.
author | chainsaw |
---|---|
date | Wed, 02 Aug 2006 15:44:07 -0700 |
parents | c81735c068c6 |
children | 705d4c089fce |
rev | line source |
---|---|
61 | 1 /* libxmms-flac - XMMS FLAC input plugin |
2 * Copyright (C) 2000,2001,2002,2003,2004,2005 Josh Coalson | |
3 * Copyright (C) 2002,2003,2004,2005 Daisuke Shimamura | |
4 * | |
5 * Based on FLAC plugin.c and mpg123 plugin | |
6 * | |
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. | |
11 * | |
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. | |
16 * | |
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 | |
1458
f12d7e208b43
[svn] Update FSF address in copyright notices. Update autotools templates.
chainsaw
parents:
1305
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. |
61 | 20 */ |
21 | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 #include <stdio.h> | |
25 #include <glib.h> | |
26 #include <audacious/plugin.h> | |
27 #include <audacious/util.h> | |
28 #include <libaudacious/titlestring.h> | |
29 | |
30 #include "FLAC/metadata.h" | |
31 #include "plugin_common/tags.h" | |
32 #include "charset.h" | |
33 #include "configure.h" | |
34 | |
35 /* | |
36 * Function local__extname (filename) | |
37 * | |
38 * Return pointer within filename to its extenstion, or NULL if | |
39 * filename has no extension. | |
40 * | |
41 */ | |
42 static char *local__extname(const char *filename) | |
43 { | |
44 char *ext = strrchr(filename, '.'); | |
45 | |
46 if (ext != NULL) | |
47 ++ext; | |
48 | |
49 return ext; | |
50 } | |
51 | |
52 static char *local__getstr(char* str) | |
53 { | |
54 if (str && strlen(str) > 0) | |
1244 | 55 return g_strdup(str); |
61 | 56 return NULL; |
57 } | |
58 | |
59 static int local__getnum(char* str) | |
60 { | |
61 if (str && strlen(str) > 0) | |
62 return atoi(str); | |
63 return 0; | |
64 } | |
65 | |
66 static char *local__getfield(const FLAC__StreamMetadata *tags, const char *name) | |
67 { | |
68 if (0 != tags) { | |
69 const char *utf8 = FLAC_plugin__tags_get_tag_utf8(tags, name); | |
70 if (0 != utf8) { | |
71 if(flac_cfg.title.convert_char_set) | |
72 return convert_from_utf8_to_user(utf8); | |
73 else | |
74 return strdup(utf8); | |
75 } | |
76 } | |
77 | |
78 return 0; | |
79 } | |
80 | |
81 /* | |
82 * Function flac_format_song_title (tag, filename) | |
83 * | |
84 * Create song title according to `tag' and/or `filename' and | |
85 * return it. The title must be subsequently freed using g_free(). | |
86 * | |
87 */ | |
1241 | 88 TitleInput *flac_get_tuple(char *filename) |
61 | 89 { |
90 TitleInput *input = NULL; | |
91 FLAC__StreamMetadata *tags; | |
1259 | 92 FLAC__StreamMetadata info; |
61 | 93 char *title, *artist, *performer, *album, *date, *tracknumber, *genre, *description; |
1244 | 94 gchar *filename_proxy = g_strdup(filename); |
61 | 95 |
1244 | 96 FLAC_plugin__tags_get(filename_proxy, &tags); |
61 | 97 |
98 title = local__getfield(tags, "TITLE"); | |
99 artist = local__getfield(tags, "ARTIST"); | |
100 performer = local__getfield(tags, "PERFORMER"); | |
101 album = local__getfield(tags, "ALBUM"); | |
102 date = local__getfield(tags, "DATE"); | |
103 tracknumber = local__getfield(tags, "TRACKNUMBER"); | |
104 genre = local__getfield(tags, "GENRE"); | |
105 description = local__getfield(tags, "DESCRIPTION"); | |
106 | |
1241 | 107 input = bmp_title_input_new(); |
61 | 108 |
109 input->performer = local__getstr(performer); | |
110 if(!input->performer) | |
111 input->performer = local__getstr(artist); | |
112 input->album_name = local__getstr(album); | |
113 input->track_name = local__getstr(title); | |
114 input->track_number = local__getnum(tracknumber); | |
115 input->year = local__getnum(date); | |
116 input->genre = local__getstr(genre); | |
117 input->comment = local__getstr(description); | |
118 | |
1244 | 119 input->file_name = g_path_get_basename(filename_proxy); |
1305 | 120 input->file_path = g_path_get_dirname(filename_proxy); |
1244 | 121 input->file_ext = local__extname(filename_proxy); |
1259 | 122 |
123 FLAC__metadata_get_streaminfo(filename, &info); | |
124 | |
125 input->length = (unsigned)((double)info.data.stream_info.total_samples / (double)info.data.stream_info.sample_rate * 1000.0 + 0.5); | |
1241 | 126 |
127 return input; | |
128 } | |
129 | |
130 gchar *flac_format_song_title(gchar *filename) | |
131 { | |
132 gchar *ret = NULL; | |
133 TitleInput *tuple = flac_get_tuple(filename); | |
134 | |
135 ret = xmms_get_titlestring(flac_cfg.title.tag_override ? flac_cfg.title.tag_format : xmms_get_gentitle_format(), tuple); | |
61 | 136 |
137 if (!ret) { | |
138 /* | |
139 * Format according to filename. | |
140 */ | |
141 ret = g_strdup(g_basename(filename)); | |
142 if (local__extname(ret) != NULL) | |
143 *(local__extname(ret) - 1) = '\0'; /* removes period */ | |
144 } | |
145 | |
1241 | 146 bmp_title_input_free(tuple); |
147 | |
61 | 148 return ret; |
149 } |