File: cdaudio_xml.c

package info (click to toggle)
gmerlin 0.4.3-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,268 kB
  • ctags: 10,598
  • sloc: ansic: 112,902; sh: 11,111; makefile: 1,425; xml: 72; sed: 16
file content (89 lines) | stat: -rw-r--r-- 2,419 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
/*****************************************************************
 * gmerlin - a general purpose multimedia framework and applications
 *
 * Copyright (c) 2001 - 2010 Members of the Gmerlin project
 * gmerlin-general@lists.sourceforge.net
 * http://gmerlin.sourceforge.net
 *
 * 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 <string.h>
#include <gmerlin/utils.h>
#include <gmerlin/xmlutils.h>

#include "cdaudio.h"

int bg_cdaudio_load(bg_track_info_t * tracks, const char * filename)
  {
  int index;
  xmlDocPtr xml_doc;
  xmlNodePtr node;

  xml_doc = xmlParseFile(filename);
  if(!xml_doc)
    return 0;

  node = xml_doc->children;

  if(BG_XML_STRCMP(node->name, "CD"))
    {
    xmlFreeDoc(xml_doc);
    return 0;
    }

  node = node->children;

  index = 0;

  while(node)
    {
    if(node->name && !BG_XML_STRCMP(node->name, "TRACK"))
      {
      bg_xml_2_metadata(xml_doc, node,
                        &(tracks[index].metadata));
      index++;
      }
    node = node->next;
    }

  
  return 1;
  }

void bg_cdaudio_save(bg_track_info_t * tracks, int num_tracks,
                     const char * filename)
  {
  xmlDocPtr  xml_doc;
  int i;

  xmlNodePtr xml_cd, child;
    
  xml_doc = xmlNewDoc((xmlChar*)"1.0");
  xml_cd = xmlNewDocRawNode(xml_doc, NULL, (xmlChar*)"CD", NULL);
  xmlDocSetRootElement(xml_doc, xml_cd);
  xmlAddChild(xml_cd, BG_XML_NEW_TEXT("\n"));

  for(i = 0; i < num_tracks; i++)
    {
    child = xmlNewTextChild(xml_cd, (xmlNsPtr)0, (xmlChar*)"TRACK", NULL);
    xmlAddChild(child, BG_XML_NEW_TEXT("\n"));
    bg_metadata_2_xml(child,
                      &(tracks[i].metadata));
    xmlAddChild(xml_cd, BG_XML_NEW_TEXT("\n"));
    }

  xmlSaveFile(filename, xml_doc);
  xmlFreeDoc(xml_doc);
  }