~ubuntu-branches/ubuntu/intrepid/gnomad2/intrepid

« back to all changes in this revision

Viewing changes to src/tagfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Manuel Garcia
  • Date: 2008-02-08 18:35:32 UTC
  • mfrom: (1.1.7 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080208183532-mgook399gmuo1gml
Tags: 2.9.1-1
New upstream release. Closes: #446812.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* tagfile.c
 
2
   Interface to the taglib library for Ogg/FLAC file tags.
 
3
   Copyright (C) 2007  Peter Randeu
 
4
 
 
5
This file is part of the GNOMAD package.
 
6
 
 
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)
 
10
any later version.
 
11
 
 
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. 
 
16
 
 
17
*/
 
18
#include "common.h"
 
19
#include "metadata.h"
 
20
#include "util.h"
 
21
#include "filesystem.h"
 
22
#include <taglib/tag_c.h>
 
23
 
 
24
/*****************************************************************************
 
25
 * EXPORTED FUNCTIONS
 
26
 *****************************************************************************/
 
27
 
 
28
void
 
29
remove_tag_from_file(gchar *path)
 
30
{
 
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.
 
36
 
 
37
  if(file == NULL) {
 
38
    g_printf("could not open file %s", tmppath);
 
39
    g_free(tmppath);
 
40
    return;      
 
41
  }
 
42
  g_free(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);
 
47
}
 
48
 
 
49
void
 
50
get_tag_for_file (metadata_t *meta)
 
51
{
 
52
  gchar *tmppath = filename_fromutf8(meta->path);
 
53
  TagLib_Tag *tag;
 
54
  const TagLib_AudioProperties *properties;
 
55
  TagLib_File *file = taglib_file_new(tmppath);
 
56
  
 
57
  if(file == NULL) {
 
58
    g_printf("could not open file %s", tmppath);
 
59
    g_free(tmppath);
 
60
    return;      
 
61
  }
 
62
  g_free(tmppath);
 
63
  
 
64
  tag = taglib_file_tag(file);
 
65
  properties = taglib_file_audioproperties(file);
 
66
  
 
67
  gchar* artist = taglib_tag_artist(tag);
 
68
  meta->artist = strlen(artist) ? g_strdup(artist) : NULL;
 
69
  
 
70
  gchar* title = taglib_tag_title(tag);
 
71
  meta->title = strlen(title) ? g_strdup(title) : NULL;
 
72
  
 
73
  gchar* album = taglib_tag_album(tag);
 
74
  meta->album = strlen(album) ? g_strdup(album) : NULL;
 
75
  
 
76
  gchar* genre = taglib_tag_genre(tag);
 
77
  meta->genre = strlen(genre) ? g_strdup(genre) : NULL;
 
78
 
 
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;
 
83
  
 
84
  taglib_tag_free_strings();
 
85
  taglib_file_free(file);
 
86
}
 
87
 
 
88
 
 
89
 
 
90
void
 
91
set_tag_for_file (metadata_t *meta, gboolean override)
 
92
{
 
93
  gchar *tmppath = filename_fromutf8(meta->path);
 
94
  TagLib_Tag *tag;
 
95
  const TagLib_AudioProperties *properties;
 
96
  TagLib_File *file = taglib_file_new(tmppath);
 
97
  
 
98
  if(file == NULL) {
 
99
    g_printf("could not open file %s", tmppath);
 
100
    g_free(tmppath);
 
101
    return;      
 
102
  }
 
103
  g_free(tmppath);
 
104
 
 
105
  // If taglib >= 1.5
 
106
  // taglib_id3v2_set_default_text_encoding(TagLib_ID3v2_UTF16);
 
107
 
 
108
  tag = taglib_file_tag(file);  
 
109
  
 
110
  if (meta->artist != NULL &&
 
111
      strcmp(meta->artist, "<Unknown>")) {
 
112
      taglib_tag_set_artist(tag, meta->artist);
 
113
  }
 
114
  if (meta->title != NULL &&
 
115
      strcmp(meta->title, "<Unknown>")) {
 
116
      taglib_tag_set_title(tag, meta->title);
 
117
  }
 
118
  if (meta->album != NULL &&
 
119
      strcmp(meta->album, "<Unknown>")) {
 
120
    taglib_tag_set_album(tag, meta->album);
 
121
  }
 
122
  if (meta->year != 0) {
 
123
    taglib_tag_set_year(tag, meta->year);
 
124
  }
 
125
  if (meta->genre != NULL &&
 
126
      strcmp(meta->genre, "<Unknown>")) {
 
127
    taglib_tag_set_genre(tag, meta->genre);
 
128
  }
 
129
  taglib_tag_set_track(tag, meta->trackno);
 
130
  
 
131
  taglib_file_save(file);
 
132
  taglib_tag_free_strings();
 
133
  taglib_file_free(file);
 
134
}