2
Interface to the taglib library for Ogg/FLAC file tags.
3
Copyright (C) 2007 Peter Randeu
5
This file is part of the GNOMAD package.
7
GNOMAD is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2, or (at your option)
12
You should have received a copy of the GNU General Public License
13
along with GNOMAD; see the file COPYING. If not, write to
14
the Free Software Foundation, 59 Temple Place - Suite 330,
15
Boston, MA 02111-1307, USA.
21
#include "filesystem.h"
22
#include <taglib/tag_c.h>
24
/*****************************************************************************
26
*****************************************************************************/
29
remove_tag_from_file(gchar *path)
31
gchar *tmppath = filename_fromutf8(path);
32
TagLib_File *file = taglib_file_new(tmppath);
33
// FIXME: taglib doesn't know how to strip all tags. That would be good
34
// because on our devices, metadata is sent with PDE/MTP commands, not
35
// stored in the tags.
38
g_printf("could not open file %s", tmppath);
43
// I introduced this to taglib by patch. Let's see if they accept it.
44
// taglib_mpeg_strip_tag(file);
45
taglib_tag_free_strings();
46
taglib_file_free(file);
50
get_tag_for_file (metadata_t *meta)
52
gchar *tmppath = filename_fromutf8(meta->path);
54
const TagLib_AudioProperties *properties;
55
TagLib_File *file = taglib_file_new(tmppath);
58
g_printf("could not open file %s", tmppath);
64
tag = taglib_file_tag(file);
65
properties = taglib_file_audioproperties(file);
67
gchar* artist = taglib_tag_artist(tag);
68
meta->artist = strlen(artist) ? g_strdup(artist) : NULL;
70
gchar* title = taglib_tag_title(tag);
71
meta->title = strlen(title) ? g_strdup(title) : NULL;
73
gchar* album = taglib_tag_album(tag);
74
meta->album = strlen(album) ? g_strdup(album) : NULL;
76
gchar* genre = taglib_tag_genre(tag);
77
meta->genre = strlen(genre) ? g_strdup(genre) : NULL;
79
meta->year = taglib_tag_year(tag);
80
meta->length = seconds_to_mmss(taglib_audioproperties_length(properties));
81
meta->trackno = taglib_tag_track(tag);
82
meta->filename = NULL;
84
taglib_tag_free_strings();
85
taglib_file_free(file);
91
set_tag_for_file (metadata_t *meta, gboolean override)
93
gchar *tmppath = filename_fromutf8(meta->path);
95
const TagLib_AudioProperties *properties;
96
TagLib_File *file = taglib_file_new(tmppath);
99
g_printf("could not open file %s", tmppath);
106
// taglib_id3v2_set_default_text_encoding(TagLib_ID3v2_UTF16);
108
tag = taglib_file_tag(file);
110
if (meta->artist != NULL &&
111
strcmp(meta->artist, "<Unknown>")) {
112
taglib_tag_set_artist(tag, meta->artist);
114
if (meta->title != NULL &&
115
strcmp(meta->title, "<Unknown>")) {
116
taglib_tag_set_title(tag, meta->title);
118
if (meta->album != NULL &&
119
strcmp(meta->album, "<Unknown>")) {
120
taglib_tag_set_album(tag, meta->album);
122
if (meta->year != 0) {
123
taglib_tag_set_year(tag, meta->year);
125
if (meta->genre != NULL &&
126
strcmp(meta->genre, "<Unknown>")) {
127
taglib_tag_set_genre(tag, meta->genre);
129
taglib_tag_set_track(tag, meta->trackno);
131
taglib_file_save(file);
132
taglib_tag_free_strings();
133
taglib_file_free(file);