Mercurial > audlegacy
annotate Plugins/General/scrobbler/tags/cdaudio.c @ 1176:6549a4c58e15 trunk
[svn] - grr
author | nenolod |
---|---|
date | Sun, 11 Jun 2006 20:29:00 -0700 |
parents | 99382cddf771 |
children |
rev | line source |
---|---|
688 | 1 /* |
2 * libmetatag - A media file tag-reader library | |
3 * Copyright (C) 2003, 2004 Pipian | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2.1 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 * | |
19 */ | |
20 | |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 #include <musicbrainz/mb_c.h> | |
25 #include "include/cdaudio.h" | |
26 #include "include/endian.h" | |
27 #include "../fmt.h" | |
28 #include "../config.h" | |
29 #include "include/unicode.h" | |
30 #define BUFFER_SIZE 4096 | |
31 | |
32 #ifdef MAKE_BMP | |
33 #include <libaudacious/vfs.h> | |
34 #define vfs_fopen vfs_fopen | |
35 #define vfs_fclose vfs_fclose | |
36 #define vfs_fread vfs_fread | |
37 #define vfs_fseek vfs_fseek | |
38 #define ftell vfs_ftell | |
39 #define VFSFile VFSFile | |
40 #endif | |
41 | |
42 /* | |
43 * Determining if a CD is being played is left up to the reader. | |
44 * | |
45 | |
46 int cdaudio_find(char *filename) | |
47 { | |
48 We've got to find a way to ensure this works on all platforms. | |
49 | |
50 return !(fmt_strcasecmp(strrchr(filename, '.') + 1, "cda")); | |
51 } | |
52 */ | |
53 | |
54 cdaudio_t *readCDAudio(char *filename, char track) | |
55 { | |
56 int retVal; | |
57 musicbrainz_t mb; | |
58 char *tmp; | |
59 cdaudio_t *musicbrainz = calloc(sizeof(cdaudio_t), 1); | |
60 | |
61 memset(musicbrainz, 0, sizeof(cdaudio_t)); | |
62 | |
63 tmp = malloc(BUFFER_SIZE / 4 + 1); | |
64 mb = mb_New(); | |
65 mb_SetDevice(mb, filename); | |
66 pdebug("Submitting query to MusicBrainz...", META_DEBUG); | |
67 retVal = mb_Query(mb, MBQ_GetCDInfo); | |
68 if(retVal == 0) | |
69 { | |
70 #ifdef META_DEBUG | |
71 char error[129] = ""; | |
72 pdebug("ERROR: Query failed.", META_DEBUG); | |
73 mb_GetQueryError(mb, error, 128); | |
74 pdebug(fmt_vastr("REASON: %s", error), META_DEBUG); | |
75 #endif | |
76 mb_Delete(mb); | |
77 free(tmp); | |
78 free(musicbrainz); | |
79 return NULL; | |
80 } | |
81 pdebug("Selecting result...", META_DEBUG); | |
82 retVal = mb_Select1(mb, MBS_SelectAlbum, 1); | |
83 if(retVal == 0) | |
84 { | |
85 pdebug("ERROR: Album select failed.", META_DEBUG); | |
86 mb_Delete(mb); | |
87 free(tmp); | |
88 free(musicbrainz); | |
89 return NULL; | |
90 } | |
91 pdebug("Extracting MusicBrainz data from result...", META_DEBUG); | |
92 memset(tmp, '\0', BUFFER_SIZE / 4 + 1); | |
93 retVal = mb_GetResultData(mb, MBE_AlbumGetAlbumName, tmp, BUFFER_SIZE / 4); | |
94 if(retVal == 0) | |
95 { | |
96 pdebug("ERROR: Album title not found.", META_DEBUG); | |
97 musicbrainz->album = calloc(1, 1); | |
98 } | |
99 else | |
100 { | |
700
99382cddf771
[svn] Fixes for all warnings (except 3 spurious GCC 4.0 ones, upgrade to 4.1 if you see them) and a performance increase. By external contributor Diego "FlameEyes" Petteno (Gentoo).
chainsaw
parents:
688
diff
changeset
|
101 musicbrainz->album = (unsigned char*)strdup(tmp); |
688 | 102 } |
103 memset(tmp, '\0', BUFFER_SIZE / 4 + 1); | |
104 retVal = mb_GetResultData1(mb, MBE_AlbumGetArtistName, tmp, BUFFER_SIZE / 4, track); | |
105 if(retVal == 0) | |
106 { | |
107 pdebug("ERROR: Artist name not found.", META_DEBUG); | |
108 musicbrainz->artist = calloc(1, 1); | |
109 } | |
110 else | |
111 { | |
700
99382cddf771
[svn] Fixes for all warnings (except 3 spurious GCC 4.0 ones, upgrade to 4.1 if you see them) and a performance increase. By external contributor Diego "FlameEyes" Petteno (Gentoo).
chainsaw
parents:
688
diff
changeset
|
112 musicbrainz->artist = (unsigned char*)strdup(tmp); |
688 | 113 } |
114 memset(tmp, '\0', BUFFER_SIZE / 4 + 1); | |
115 retVal = mb_GetResultData1(mb, MBE_AlbumGetTrackName, tmp, BUFFER_SIZE / 4, track); | |
116 if(retVal == 0) | |
117 { | |
118 pdebug("ERROR: Track title not found.", META_DEBUG); | |
119 musicbrainz->title = calloc(1, 1); | |
120 } | |
121 else | |
122 { | |
700
99382cddf771
[svn] Fixes for all warnings (except 3 spurious GCC 4.0 ones, upgrade to 4.1 if you see them) and a performance increase. By external contributor Diego "FlameEyes" Petteno (Gentoo).
chainsaw
parents:
688
diff
changeset
|
123 musicbrainz->title = (unsigned char*)strdup(tmp); |
688 | 124 } |
125 memset(tmp, '\0', BUFFER_SIZE / 4 + 1); | |
126 retVal = mb_GetResultData1(mb, MBE_AlbumGetTrackId, tmp, BUFFER_SIZE / 4, track); | |
127 if(retVal == 0) | |
128 { | |
129 pdebug("ERROR: MBID not found.", META_DEBUG); | |
130 musicbrainz->mbid = calloc(1, 1); | |
131 } | |
132 else | |
133 { | |
134 musicbrainz->mbid = malloc(64); | |
700
99382cddf771
[svn] Fixes for all warnings (except 3 spurious GCC 4.0 ones, upgrade to 4.1 if you see them) and a performance increase. By external contributor Diego "FlameEyes" Petteno (Gentoo).
chainsaw
parents:
688
diff
changeset
|
135 mb_GetIDFromURL(mb, tmp, (char*)musicbrainz->mbid, 64); |
688 | 136 } |
137 mb_Delete(mb); | |
138 free(tmp); | |
139 | |
140 return musicbrainz; | |
141 } | |
142 | |
143 void freeCDAudio(cdaudio_t *musicbrainz) | |
144 { | |
145 free(musicbrainz->mbid); | |
146 free(musicbrainz->title); | |
147 free(musicbrainz->artist); | |
148 free(musicbrainz->album); | |
149 free(musicbrainz); | |
150 } |