make ogg and flac single-pass scanners like wma

This commit is contained in:
Ron Pedde 2005-04-17 21:41:42 +00:00
parent 1ffd741e50
commit b06aad7e49
3 changed files with 23 additions and 62 deletions

View File

@ -48,15 +48,27 @@
#include <FLAC/metadata.h>
int scan_get_flacfileinfo(char *filename, MP3FILE *pmp3)
{
#define GET_VORBIS_COMMENT(comment, name, len) \
(((strncasecmp(name, (comment).entry, strlen(name)) == 0) && \
((comment).entry[strlen(name)] == '=')) ? \
((*(len) = (comment).length - (strlen(name) + 1)), \
(&((comment).entry[strlen(name) + 1]))) : \
NULL)
int scan_get_flacinfo(char *filename, MP3FILE *pmp3) {
FLAC__Metadata_Chain *chain;
FLAC__Metadata_Iterator *iterator;
FLAC__StreamMetadata *block;
int rv = -1;
int found=0;
unsigned int sec, ms;
FILE *f;
int i;
char *val;
size_t len;
char tmp;
/* get file length */
if (!(f = fopen(filename, "rb"))) {
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n", filename);
return -1;
@ -98,59 +110,9 @@ int scan_get_flacfileinfo(char *filename, MP3FILE *pmp3)
pmp3->song_length = (sec * 1000) + ms;
pmp3->bitrate = (pmp3->file_size) / (((sec * 1000) + ms) / 8);
pmp3->samplerate = block->data.stream_info.sample_rate;
rv = 0;
found=1;
break;
}
} while (FLAC__metadata_iterator_next(iterator));
if (rv < 0) {
DPRINTF(E_WARN,L_SCAN,"Cannot find FLAC metadata in %s\n", filename);
}
FLAC__metadata_iterator_delete(iterator);
FLAC__metadata_chain_delete(chain);
return rv;
}
#define GET_VORBIS_COMMENT(comment, name, len) \
(((strncasecmp(name, (comment).entry, strlen(name)) == 0) && \
((comment).entry[strlen(name)] == '=')) ? \
((*(len) = (comment).length - (strlen(name) + 1)), \
(&((comment).entry[strlen(name) + 1]))) : \
NULL)
int scan_get_flactags(char *filename, MP3FILE *pmp3)
{
FLAC__Metadata_Chain *chain;
FLAC__Metadata_Iterator *iterator;
FLAC__StreamMetadata *block;
int i;
char *val;
size_t len;
char tmp;
int found = 0;
chain = FLAC__metadata_chain_new();
if (! chain) {
DPRINTF(E_WARN,L_SCAN,"Cannot allocate FLAC metadata chain\n");
return 0;
}
if (! FLAC__metadata_chain_read(chain, filename)) {
DPRINTF(E_WARN,L_SCAN,"Cannot read FLAC metadata from %s\n", filename);
FLAC__metadata_chain_delete(chain);
return 0;
}
iterator = FLAC__metadata_iterator_new();
if (! iterator) {
DPRINTF(E_WARN,L_SCAN,"Cannot allocate FLAC metadata iterator\n");
FLAC__metadata_chain_delete(chain);
return 0;
}
FLAC__metadata_iterator_init(iterator, chain);
do {
block = FLAC__metadata_iterator_get_block(iterator);
if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
{
for (i = 0; i < block->data.vorbis_comment.num_comments; i++) {
@ -204,7 +166,7 @@ int scan_get_flactags(char *filename, MP3FILE *pmp3)
}
} while (FLAC__metadata_iterator_next(iterator));
if (! found) {
if (!found) {
DPRINTF(E_WARN,L_SCAN,"Cannot find FLAC metadata in %s\n", filename);
}

View File

@ -304,12 +304,11 @@ static time_t mac_to_unix_time(int t);
static TAGHANDLER *scan_gethandler(char *type);
#ifdef OGGVORBIS
extern int scan_get_oggfileinfo(char *filename, MP3FILE *pmp3);
extern int scan_get_ogginfo(char *filename, MP3FILE *pmp3);
#endif
#ifdef FLAC
extern int scan_get_flacfileinfo(char *filename, MP3FILE *pmp3);
extern int scan_get_flactags(char *filename, MP3FILE *pmp3);
extern int scan_get_flacinfo(char *filename, MP3FILE *pmp3);
#endif
/** \see wma.c */
@ -347,11 +346,11 @@ static TAGHANDLER taghandlers[] = {
{ "url", scan_get_nultags, scan_get_urlfileinfo, "pls", NULL, "Playlist URL" },
{ "pls", scan_get_nultags, scan_get_urlfileinfo, "pls", NULL, "Playlist URL" },
#ifdef OGGVORBIS
{ "ogg", scan_get_nultags, scan_get_oggfileinfo, "ogg", "ogg", "Ogg Vorbis audio file" },
{ "ogg", scan_get_nultags, scan_get_ogginfo, "ogg", "ogg", "Ogg Vorbis audio file" },
#endif
#ifdef FLAC
{ "flac", scan_get_flactags, scan_get_flacfileinfo, "flac","flac", "FLAC audio file" },
{ "fla", scan_get_flactags, scan_get_flacfileinfo, "flac","flac", "FLAC audio file" },
{ "flac", scan_get_nulags, scan_get_flacinfo, "flac","flac", "FLAC audio file" },
{ "fla", scan_get_nultags, scan_get_flacinfo, "flac","flac", "FLAC audio file" },
#endif
{ NULL, NULL, NULL, NULL, NULL, NULL }
};

View File

@ -15,7 +15,7 @@
#include "err.h"
#include "mp3-scanner.h"
int scan_get_oggfileinfo(char *filename, MP3FILE *pmp3) {
int scan_get_ogginfo(char *filename, MP3FILE *pmp3) {
FILE *f;
OggVorbis_File vf;
vorbis_comment *comment = NULL;