File: cdtext.c

package info (click to toggle)
gmerlin 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,108 kB
  • sloc: ansic: 133,761; javascript: 6,967; makefile: 1,400; sh: 702; sed: 16
file content (134 lines) | stat: -rw-r--r-- 3,998 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*****************************************************************
 * gmerlin - a general purpose multimedia framework and applications
 *
 * Copyright (c) 2001 - 2024 Members of the Gmerlin project
 * http://github.com/bplaum
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * *****************************************************************/



#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <cdio/cdio.h>
#include <cdio/cdtext.h>
/* Stuff defined by cdio includes */
#undef PACKAGE
#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#undef VERSION


#include <gmerlin/utils.h>


#include <gavl/metatags.h>


#include "cdaudio.h"

#define GET_FIELD(dst, key, track)                    \
  field = cdtext_get_const(cdtext, key, track);

int bg_cdaudio_get_metadata_cdtext(CdIo_t * cdio,
                                   gavl_dictionary_t * info,
                                   bg_cdaudio_index_t* idx)
  {
  int i;
  const char * field;
    
  /* Global information */

  const char * title  = NULL;
  const char * artist  = NULL;
  const char * author  = NULL;
  const char * album   = NULL;
  const char * genre   = NULL;
  const char * comment = NULL;
  const cdtext_t * cdtext;

  gavl_dictionary_t * m;
  
  /* Get information for the whole disc */
  
  cdtext = cdio_get_cdtext (cdio);

  if(!cdtext)
    return 0;
  
  artist  = cdtext_get_const(cdtext, CDTEXT_FIELD_PERFORMER, 0);
  author  = cdtext_get_const(cdtext, CDTEXT_FIELD_COMPOSER, 0); /* Composer overwrites songwriter */

  if(!author)
    author  = cdtext_get_const(cdtext, CDTEXT_FIELD_SONGWRITER, 0);
  
  album  = cdtext_get_const(cdtext, CDTEXT_FIELD_TITLE, 0);
  genre  = cdtext_get_const(cdtext, CDTEXT_FIELD_GENRE, 0);
  comment  = cdtext_get_const(cdtext, CDTEXT_FIELD_MESSAGE, 0);
  
  for(i = 0; i < idx->num_tracks; i++)
    {
    if(idx->tracks[i].is_audio)
      {
      
      GET_FIELD(title, CDTEXT_FIELD_TITLE, i+1);
      
      if(!title)
        return 0;

      m = gavl_track_get_metadata_nc(&info[idx->tracks[i].index]);
      
      gavl_dictionary_set_string(m, GAVL_META_TITLE, title);

      if((field = cdtext_get_const(cdtext, CDTEXT_FIELD_PERFORMER, i+1)))
        gavl_dictionary_set_string(m, GAVL_META_ARTIST, field);
      else
        gavl_dictionary_set_string(m, GAVL_META_ARTIST, artist);


      if((field = cdtext_get_const(cdtext, CDTEXT_FIELD_COMPOSER, i+1)))
        gavl_dictionary_set_string(m, GAVL_META_AUTHOR, field);
      else if((field = cdtext_get_const(cdtext, CDTEXT_FIELD_SONGWRITER, i+1)))
        gavl_dictionary_set_string(m, GAVL_META_AUTHOR, field);
      else if(author)
        gavl_dictionary_set_string(m, GAVL_META_AUTHOR, author);
      
      
      if((field = cdtext_get_const(cdtext, CDTEXT_FIELD_GENRE, i+1)))
        gavl_dictionary_set_string(m, GAVL_META_GENRE, field);
      else
        gavl_dictionary_set_string(m, GAVL_META_GENRE, genre);
      
      if((field = cdtext_get_const(cdtext, CDTEXT_FIELD_MESSAGE, i+1)))
        gavl_dictionary_set_string(m, GAVL_META_COMMENT, field);
      else
        gavl_dictionary_set_string(m, GAVL_META_COMMENT, comment);
      
      
      gavl_dictionary_set_string(m, GAVL_META_ALBUM, album);
      gavl_dictionary_set_string(m, GAVL_META_ALBUMARTIST, artist);
      }
    }
  return 1;
  
  }

#undef GET_FIELD