More scanning restructuring -- return TRUE on success, get rid of dual scanners

This commit is contained in:
Ron Pedde 2005-06-02 02:26:04 +00:00
parent 35af7991d9
commit 8623fecab9
10 changed files with 135 additions and 129 deletions

View File

@ -65,8 +65,7 @@
typedef struct {
char *suffix;
int (*tags)(char* file, MP3FILE* pmp3);
int (*files)(char* file, MP3FILE* pmp3);
int (*scanner)(char* file, MP3FILE* pmp3);
char *type; /* daap.songformat */
char *codectype; /* song.codectype */
char *description; /* daap.songdescription */
@ -79,12 +78,9 @@ typedef struct {
* Forwards
*/
static int scan_path(char *path);
static int scan_gettags(char *file, MP3FILE *pmp3);
static int scan_get_nultags(char *file, MP3FILE *pmp3) { return 0; };
static int scan_get_fileinfo(char *file, MP3FILE *pmp3);
static int scan_get_info(char *file, MP3FILE *pmp3);
static int scan_freetags(MP3FILE *pmp3);
static void scan_static_playlist(char *path);
static int scan_static_playlist(char *path);
static void scan_music_file(char *path, struct dirent *pde, struct stat *psb);
static TAGHANDLER *scan_gethandler(char *type);
@ -131,23 +127,23 @@ int scan_xml_playlist(char *filename);
* This system is broken, and won't work with something like a .cue file
*/
static TAGHANDLER taghandlers[] = {
{ "aac", scan_get_nultags, scan_get_aacinfo, "m4a", "mp4a", "AAC audio file" },
{ "mp4", scan_get_nultags, scan_get_aacinfo, "m4a", "mp4a", "AAC audio file" },
{ "m4a", scan_get_nultags, scan_get_aacinfo, "m4a", "mp4a", "AAC audio file" },
{ "m4p", scan_get_nultags, scan_get_aacinfo, "m4p", "mp4a", "AAC audio file" },
{ "mp3", scan_get_nultags, scan_get_mp3info, "mp3", "mpeg", "MPEG audio file" },
{ "wav", scan_get_nultags, scan_get_wavinfo, "wav", "wav", "WAV audio file" },
{ "wma", scan_get_nultags, scan_get_wmainfo, "wma", "wma", "WMA audio file" },
{ "url", scan_get_nultags, scan_get_urlinfo, "pls", NULL, "Playlist URL" },
{ "pls", scan_get_nultags, scan_get_urlinfo, "pls", NULL, "Playlist URL" },
{ "aac", scan_get_aacinfo, "m4a", "mp4a", "AAC audio file" },
{ "mp4", scan_get_aacinfo, "m4a", "mp4a", "AAC audio file" },
{ "m4a", scan_get_aacinfo, "m4a", "mp4a", "AAC audio file" },
{ "m4p", scan_get_aacinfo, "m4p", "mp4a", "AAC audio file" },
{ "mp3", scan_get_mp3info, "mp3", "mpeg", "MPEG audio file" },
{ "wav", scan_get_wavinfo, "wav", "wav", "WAV audio file" },
{ "wma", scan_get_wmainfo, "wma", "wma", "WMA audio file" },
{ "url", scan_get_urlinfo, "pls", NULL, "Playlist URL" },
{ "pls", scan_get_urlinfo, "pls", NULL, "Playlist URL" },
#ifdef OGGVORBIS
{ "ogg", scan_get_nultags, scan_get_ogginfo, "ogg", "ogg", "Ogg Vorbis audio file" },
{ "ogg", scan_get_ogginfo, "ogg", "ogg", "Ogg Vorbis audio file" },
#endif
#ifdef FLAC
{ "flac", scan_get_nultags, scan_get_flacinfo, "flac","flac", "FLAC audio file" },
{ "fla", scan_get_nultags, scan_get_flacinfo, "flac","flac", "FLAC audio file" },
{ "flac", scan_get_flacinfo, "flac","flac", "FLAC audio file" },
{ "fla", scan_get_flacinfo, "flac","flac", "FLAC audio file" },
#endif
{ NULL, NULL, NULL, NULL, NULL, NULL }
{ NULL, NULL, NULL, NULL, NULL }
};
typedef struct tag_playlistlist {
@ -334,13 +330,13 @@ int scan_path(char *path) {
return 0;
}
/*
* scan_static_playlist
*
/**
* Scan a file as a static playlist
*
* @param path path to playlist
*/
void scan_static_playlist(char *path) {
int scan_static_playlist(char *path) {
char base_path[PATH_MAX];
char file_path[PATH_MAX];
char real_path[PATH_MAX];
@ -355,7 +351,7 @@ void scan_static_playlist(char *path) {
DPRINTF(E_WARN,L_SCAN|L_PL,"Processing static playlist: %s\n",path);
if(stat(path,&sb)) {
DPRINTF(E_WARN,L_SCAN,"Error statting %s: %s\n",path,strerror(errno));
return;
return FALSE;
}
if((current=strrchr(path,'/')) == NULL) {
@ -374,7 +370,7 @@ void scan_static_playlist(char *path) {
if(pm3u && (pm3u->db_timestamp > sb.st_mtime)) {
/* already up-to-date */
db_dispose_playlist(pm3u);
return;
return TRUE;
}
if(pm3u)
@ -385,7 +381,7 @@ void scan_static_playlist(char *path) {
if(db_add_playlist(base_path,PL_STATICFILE,NULL,path,0,&playlistid) != DB_E_SUCCESS) {
DPRINTF(E_LOG,L_SCAN,"Error adding m3u playlist %s\n",path);
db_dispose_playlist(pm3u);
return;
return FALSE;
}
/* now get the *real* base_path */
strcpy(base_path,path);
@ -430,6 +426,7 @@ void scan_static_playlist(char *path) {
db_dispose_playlist(pm3u);
DPRINTF(E_WARN,L_SCAN|L_PL,"Done processing playlist\n");
return TRUE;
}
@ -488,8 +485,7 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) {
}
/* Do the tag lookup here */
if(!scan_gettags(mp3file.path,&mp3file) &&
!scan_get_fileinfo(mp3file.path,&mp3file)) {
if(scan_get_info(mp3file.path,&mp3file)) {
make_composite_tags(&mp3file);
/* fill in the time_added. I'm not sure of the logic in this.
My thinking is to use time created, but what is that? Best
@ -506,7 +502,7 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) {
db_add(&mp3file);
} else {
DPRINTF(E_WARN,L_SCAN,"Skipping %s - scan_gettags failed\n",pde->d_name);
DPRINTF(E_WARN,L_SCAN,"Skipping %s - scan failed\n",mp3file.path);
}
scan_freetags(&mp3file);
@ -527,25 +523,6 @@ TAGHANDLER *scan_gethandler(char *type) {
return NULL;
}
/**
* Dispatch the appropriate handler to get specific tag metainfomation
*
* \param file file to get tag info for
* \param pmp3 mp3 file struct to fill info into
*/
int scan_gettags(char *file, MP3FILE *pmp3) {
TAGHANDLER *hdl;
/* dispatch to appropriate tag handler */
hdl = scan_gethandler(pmp3->type);
if(hdl && hdl->tags)
return hdl->tags(file,pmp3);
/* otherwise, it's a file type we don't understand yet */
return 0;
}
/*
* scan_freetags
*
@ -574,10 +551,10 @@ int scan_freetags(MP3FILE *pmp3) {
/**
* Dispatch to actual file info handlers
*
* \param file file to read file metainfo for
* \param pmp3 struct to stuff with info gleaned
* @param file file to read file metainfo for
* @param pmp3 struct to stuff with info gleaned
*/
int scan_get_fileinfo(char *file, MP3FILE *pmp3) {
int scan_get_info(char *file, MP3FILE *pmp3) {
FILE *infile;
off_t file_size;
@ -585,13 +562,13 @@ int scan_get_fileinfo(char *file, MP3FILE *pmp3) {
/* dispatch to appropriate tag handler */
hdl = scan_gethandler(pmp3->type);
if(hdl && hdl->files)
return hdl->files(file,pmp3);
if(hdl && hdl->scanner)
return hdl->scanner(file,pmp3);
/* a file we don't know anything about... ogg or aiff maybe */
if(!(infile=fopen(file,"rb"))) {
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",file);
return -1;
return FALSE;
}
/* we can at least get this */
@ -602,7 +579,7 @@ int scan_get_fileinfo(char *file, MP3FILE *pmp3) {
pmp3->file_size=file_size;
fclose(infile);
return 0;
return TRUE;
}

View File

@ -94,4 +94,10 @@ extern char *scan_winamp_genre[];
extern int scan_init(char *path);
extern void make_composite_tags(MP3FILE *song);
#ifndef TRUE
# define TRUE 1
# define FALSE 0
#endif
#endif /* _MP3_SCANNER_H_ */

View File

@ -157,7 +157,7 @@ long scan_aac_findatom(FILE *fin, long max_offset,
*
* @param filename file to scan
* @param pmp3 pointer to the MP3FILE to fill with data
* @returns -1 if file should not be added to database, 0 otherwise
* @returns FALSE if file should not be added to database, TRUE otherwise
*/
int scan_get_aacinfo(char *filename, MP3FILE *pmp3) {
FILE *fin;
@ -182,7 +182,7 @@ int scan_get_aacinfo(char *filename, MP3FILE *pmp3) {
if(!(fin=fopen(filename,"rb"))) {
DPRINTF(E_INF,L_SCAN,"Cannot open file %s for reading\n",filename);
return -1;
return FALSE;
}
fseek(fin,0,SEEK_END);
@ -374,5 +374,5 @@ int scan_get_aacinfo(char *filename, MP3FILE *pmp3) {
}
fclose(fin);
return 0; /* we'll return as much as we got. */
return TRUE; /* we'll return as much as we got. */
}

View File

@ -56,6 +56,13 @@
(&((comment).entry[strlen(name) + 1]))) : \
NULL)
/**
* scan a flac file for metainfo.
*
* @param filename file to read metainfo for
* @param pmp3 MP3FILE structure to fill
* @returns TRUE if file should be added to DB, FALSE otherwise
*/
int scan_get_flacinfo(char *filename, MP3FILE *pmp3) {
FLAC__Metadata_Chain *chain;
FLAC__Metadata_Iterator *iterator;
@ -71,7 +78,7 @@ int scan_get_flacinfo(char *filename, MP3FILE *pmp3) {
/* get file length */
if (!(f = fopen(filename, "rb"))) {
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n", filename);
return -1;
return FALSE;
}
fseek(f, 0, SEEK_END);
pmp3->file_size = ftell(f);
@ -81,19 +88,19 @@ int scan_get_flacinfo(char *filename, MP3FILE *pmp3) {
chain = FLAC__metadata_chain_new();
if (! chain) {
DPRINTF(E_WARN,L_SCAN,"Cannot allocate FLAC metadata chain\n");
return -1;
return FALSE;
}
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 -1;
return FALSE;
}
iterator = FLAC__metadata_iterator_new();
if (! iterator) {
DPRINTF(E_WARN,L_SCAN,"Cannot allocate FLAC metadata iterator\n");
FLAC__metadata_chain_delete(chain);
return -1;
return FALSE;
}
FLAC__metadata_iterator_init(iterator, chain);
@ -181,5 +188,5 @@ int scan_get_flacinfo(char *filename, MP3FILE *pmp3) {
FLAC__metadata_iterator_delete(iterator);
FLAC__metadata_chain_delete(chain);
return 0;
return TRUE;
}

View File

@ -250,11 +250,12 @@ static void scan_mp3_get_frame_count(FILE *infile, SCAN_FRAMEINFO *pfi);
*
* @param filename file to scan
* @param pmp3 MP3FILE structure to fill
* @returns TRUE if file should be added to DB, FALSE otherwise
*/
int scan_get_mp3info(char *filename, MP3FILE *pmp3) {
if(!scan_mp3_get_mp3tags(filename, pmp3))
if(scan_mp3_get_mp3tags(filename, pmp3))
return scan_mp3_get_mp3fileinfo(filename,pmp3);
return -1;
return FALSE;
}
/**
@ -292,7 +293,7 @@ int scan_mp3_get_mp3tags(char *file, MP3FILE *pmp3) {
pid3file=id3_file_open(file,ID3_FILE_MODE_READONLY);
if(!pid3file) {
DPRINTF(E_WARN,L_SCAN,"Cannot open %s\n",file);
return -1;
return FALSE;
}
pid3tag=id3_file_tag(pid3file);
@ -302,7 +303,7 @@ int scan_mp3_get_mp3tags(char *file, MP3FILE *pmp3) {
id3_file_close(pid3file);
errno=err;
DPRINTF(E_WARN,L_SCAN,"Cannot get ID3 tag for %s\n",file);
return -1;
return FALSE;
}
index=0;
@ -472,7 +473,7 @@ int scan_mp3_get_mp3tags(char *file, MP3FILE *pmp3) {
id3_file_close(pid3file);
DPRINTF(E_DBG,L_SCAN,"Got id3 tag successfully\n");
return 0;
return TRUE;
}
/**
@ -781,7 +782,7 @@ int scan_mp3_get_mp3fileinfo(char *file, MP3FILE *pmp3) {
if(!(infile=fopen(file,"rb"))) {
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",file);
return -1;
return FALSE;
}
memset((void*)&fi,0x00,sizeof(fi));
@ -799,7 +800,7 @@ int scan_mp3_get_mp3fileinfo(char *file, MP3FILE *pmp3) {
DPRINTF(E_LOG,L_SCAN,"Short file: %s\n",file);
}
fclose(infile);
return -1;
return FALSE;
}
pid3=(SCAN_ID3HEADER*)buffer;
@ -829,7 +830,7 @@ int scan_mp3_get_mp3fileinfo(char *file, MP3FILE *pmp3) {
if(fread(buffer,1,sizeof(buffer),infile) < sizeof(buffer)) {
DPRINTF(E_LOG,L_SCAN,"Short read: %s\n",file);
fclose(infile);
return 0;
return TRUE;
}
index=0;
@ -905,7 +906,7 @@ int scan_mp3_get_mp3fileinfo(char *file, MP3FILE *pmp3) {
DPRINTF(E_LOG,L_SCAN,"If this is a valid mp3 file that plays in "
"other applications, please email me at rpedde@users.sourceforge.net "
"and tell me you got this error. Thanks");
return 0;
return TRUE;
}
DPRINTF(E_DBG,L_SCAN," MPEG Version: %0.1g\n",fi.version);
@ -963,6 +964,6 @@ int scan_mp3_get_mp3fileinfo(char *file, MP3FILE *pmp3) {
DPRINTF(E_DBG,L_SCAN," Song Length: %d\n",pmp3->song_length);
fclose(infile);
return 0;
return TRUE;
}

View File

@ -15,6 +15,14 @@
#include "err.h"
#include "mp3-scanner.h"
/**
* get ogg metainfo
*
* @param filename file to read metainfo for
* @param pmp3 MP3FILE struct to fill with metainfo
* @returns TRUE if file should be added to DB, FALSE otherwise
*/
int scan_get_ogginfo(char *filename, MP3FILE *pmp3) {
FILE *f;
OggVorbis_File vf;
@ -27,7 +35,7 @@ int scan_get_ogginfo(char *filename, MP3FILE *pmp3) {
DPRINTF(E_FATAL, L_SCAN,
"Error opening input file \"%s\": %s\n", filename,
strerror(errno));
return 0;
return FALSE;
}
if(!fseek(f,0,SEEK_END)) {
@ -39,7 +47,7 @@ int scan_get_ogginfo(char *filename, MP3FILE *pmp3) {
fclose(f);
DPRINTF(E_FATAL, L_SCAN,
"Error opening Vorbis stream in \"%s\"\n", filename);
return 0;
return FALSE;
}
vi=ov_info(&vf,-1);
@ -83,5 +91,5 @@ int scan_get_ogginfo(char *filename, MP3FILE *pmp3) {
}
ov_clear(&vf);
/*fclose(f);*/
return 0;
return TRUE;
}

View File

@ -37,6 +37,7 @@
*
* @param filename .url file to process
* @param pmp3 MP3FILE structure that must be filled
* @returns TRUE if file should be added to db, FALSE otherwise
*/
int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
FILE *infile;
@ -47,7 +48,7 @@ int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
if(!(infile=fopen(filename,"rb"))) {
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",filename);
return -1;
return FALSE;
}
fgets(linebuffer,sizeof(linebuffer),infile);
@ -61,7 +62,7 @@ int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
if(!tail) {
DPRINTF(E_LOG,L_SCAN,"Badly formatted .url file - must be bitrate,descr,url\n");
fclose(infile);
return -1;
return FALSE;
}
pmp3->bitrate=atoi(head);
@ -70,7 +71,7 @@ int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
if(!tail) {
DPRINTF(E_LOG,L_SCAN,"Badly formatted .url file - must be bitrate,descr,url\n");
fclose(infile);
return -1;
return FALSE;
}
*tail++='\0';
@ -83,6 +84,6 @@ int scan_get_urlinfo(char *filename, MP3FILE *pmp3) {
DPRINTF(E_DBG,L_SCAN," Bitrate: %d\n",pmp3->bitrate);
DPRINTF(E_DBG,L_SCAN," URL: %s\n",pmp3->url);
return 0;
return TRUE;
}

View File

@ -45,6 +45,7 @@
*
* @param filename file to scan
* @param pmp3 MP3FILE struct to be filled
* @returns TRUE if song should be added to database, FALSE otherwise
*/
int scan_get_wavinfo(char *filename, MP3FILE *pmp3) {
FILE *infile;
@ -64,7 +65,7 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) {
if(!(infile=fopen(filename,"rb"))) {
DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",filename);
return -1;
return FALSE;
}
fseek(infile,0,SEEK_END);
@ -75,7 +76,7 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) {
fclose(infile);
if (rl != 44) {
DPRINTF(E_WARN,L_SCAN,"Could not read wav header from %s\n",filename);
return -1;
return FALSE;
}
if (strncmp((char*)hdr + 0, "RIFF", 4) ||
@ -83,7 +84,7 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) {
strncmp((char*)hdr + 12, "fmt ", 4) ||
strncmp((char*)hdr + 36, "data", 4)) {
DPRINTF(E_WARN,L_SCAN,"Invalid wav header in %s\n",filename);
return -1;
return FALSE;
}
chunk_data_length = GET_WAV_INT32(hdr + 4);
@ -98,7 +99,7 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) {
(compression_code != 1) ||
(channel_count < 1)) {
DPRINTF(E_WARN,L_SCAN,"Invalid wav header in %s\n",filename);
return -1;
return FALSE;
}
bit_rate = sample_rate * channel_count * ((sample_bit_length + 7) / 8) * 8;
@ -108,6 +109,6 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) {
ms = ((data_length % (bit_rate / 8)) * 1000) / (bit_rate / 8);
pmp3->song_length = (sec * 1000) + ms;
return 0;
return TRUE;
}

View File

@ -323,9 +323,9 @@ int wma_file_read_bytes(int fd,int len, unsigned char **data) {
* parse the extended content description object. this is an object that
* has ad-hoc tags, basically.
*
* \param fd fd of the file we are reading from -- positioned at start
* \param size size of the content description block
* \param pmp3 the mp3 struct we are filling with gleaned data
* @param fd fd of the file we are reading from -- positioned at start
* @param size size of the content description block
* @param pmp3 the mp3 struct we are filling with gleaned data
*/
int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3) {
unsigned short descriptor_count;
@ -344,18 +344,18 @@ int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3) {
DPRINTF(E_DBG,L_SCAN,"Reading extended content description object\n");
if(!wma_file_read_short(fd, &descriptor_count))
return -1;
return FALSE;
for(index = 0; index < descriptor_count; index++) {
if(!wma_file_read_short(fd,&descriptor_name_len)) return -1;
if(!wma_file_read_utf16(fd,descriptor_name_len,&descriptor_name)) return -1;
if(!wma_file_read_short(fd,&descriptor_value_type)) {
free(descriptor_name);
return -1;
return FALSE;
}
if(!wma_file_read_short(fd,&descriptor_value_len)) {
free(descriptor_name);
return -1;
return FALSE;
}
DPRINTF(E_DBG,L_SCAN,"Found descriptor: %s\n", descriptor_name);
@ -393,7 +393,7 @@ int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3) {
if(fail) {
free(descriptor_name);
return -1;
return FALSE;
}
/* do stuff with what we found */
@ -438,7 +438,7 @@ int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3) {
free(descriptor_name);
}
return 0;
return TRUE;
}
/**
@ -446,9 +446,9 @@ int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3) {
* contains lengths of title, author, copyright, descr, and rating
* then the utf-16le strings for each.
*
* \param fd fd of the file we are reading from -- positioned at start
* \param size size of the content description block
* \param pmp3 the mp3 struct we are filling with gleaned data
* @param fd fd of the file we are reading from -- positioned at start
* @param size size of the content description block
* @param pmp3 the mp3 struct we are filling with gleaned data
*/
int wma_parse_content_description(int fd,int size, MP3FILE *pmp3) {
unsigned short sizes[5];
@ -456,17 +456,17 @@ int wma_parse_content_description(int fd,int size, MP3FILE *pmp3) {
char *utf8;
if(size < 10) /* must be at least enough room for the size block */
return -1;
return FALSE;
for(index=0; index < 5; index++) {
if(!wma_file_read_short(fd,&sizes[index]))
return -1;
return FALSE;
}
for(index=0;index<5;index++) {
if(sizes[index]) {
if(!wma_file_read_utf16(fd,sizes[index],&utf8))
return -1;
return FALSE;
DPRINTF(E_DBG,L_SCAN,"Got item of length %d: %s\n",sizes[index],utf8);
@ -499,16 +499,16 @@ int wma_parse_content_description(int fd,int size, MP3FILE *pmp3) {
}
}
return 0;
return TRUE;
}
/**
* parse the file properties object. this is an object that
* contains playtime and bitrate, primarily.
*
* \param fd fd of the file we are reading from -- positioned at start
* \param size size of the content description block
* \param pmp3 the mp3 struct we are filling with gleaned data
* @param fd fd of the file we are reading from -- positioned at start
* @param size size of the content description block
* @param pmp3 the mp3 struct we are filling with gleaned data
*/
int wma_parse_file_properties(int fd,int size, MP3FILE *pmp3) {
unsigned long long play_duration;
@ -523,13 +523,13 @@ int wma_parse_file_properties(int fd,int size, MP3FILE *pmp3) {
lseek(fd,40,SEEK_CUR);
if(!wma_file_read_ll(fd, &play_duration))
return -1;
return FALSE;
if(!wma_file_read_ll(fd, &send_duration))
return -1;
return FALSE;
if(!wma_file_read_ll(fd, &preroll))
return -1;
return FALSE;
/* I'm not entirely certain what preroll is, but it seems
* to make it match up with what windows thinks is the song
@ -543,11 +543,11 @@ int wma_parse_file_properties(int fd,int size, MP3FILE *pmp3) {
lseek(fd,12,SEEK_CUR);
if(!wma_file_read_int(fd,&max_bitrate))
return -1;
return FALSE;
pmp3->bitrate = max_bitrate/1000;
return 0;
return TRUE;
}
/**
@ -562,8 +562,8 @@ int wma_parse_file_properties(int fd,int size, MP3FILE *pmp3) {
*
* We assume this is utf-16LE, as it comes from windows
*
* \param utf16 utf-16 to convert
* \param len length of utf-16 string
* @param utf16 utf-16 to convert
* @param len length of utf-16 string
*/
char *wma_utf16toutf8(unsigned char *utf16, int len) {
char *utf8;
@ -634,7 +634,7 @@ char *wma_utf16toutf8(unsigned char *utf16, int len) {
/**
* lookup a guid by character
*
* \param guid 16 byte guid to look up
* @param guid 16 byte guid to look up
*/
WMA_GUID *wma_find_guid(unsigned char *guid) {
WMA_GUID *pguid = wma_guidlist;
@ -652,7 +652,7 @@ WMA_GUID *wma_find_guid(unsigned char *guid) {
/**
* convert a short int in wrong-endian format to host-endian
*
* \param src pointer to 16-bit wrong-endian int
* @param src pointer to 16-bit wrong-endian int
*/
unsigned short wma_convert_short(unsigned char *src) {
return src[1] << 8 |
@ -662,7 +662,7 @@ unsigned short wma_convert_short(unsigned char *src) {
/**
* convert an int in wrong-endian format to host-endian
*
* \param src pointer to 32-bit wrong-endian int
* @param src pointer to 32-bit wrong-endian int
*/
unsigned int wma_convert_int(unsigned char *src) {
return src[3] << 24 |
@ -674,7 +674,7 @@ unsigned int wma_convert_int(unsigned char *src) {
/**
* convert a long long wrong-endian format to host-endian
*
* \param src pointer to 64-bit wrong-endian int
* @param src pointer to 64-bit wrong-endian int
*/
unsigned long long wma_convert_ll(unsigned char *src) {
@ -700,8 +700,8 @@ unsigned long long wma_convert_ll(unsigned char *src) {
/**
* get metainfo about a wma file
*
* \param filename full path to file to scan
* \param pmp3 MP3FILE struct to be filled with with metainfo
* @param filename full path to file to scan
* @param pmp3 MP3FILE struct to be filled with with metainfo
*/
int scan_get_wmainfo(char *filename, MP3FILE *pmp3) {
int wma_fd;
@ -711,27 +711,27 @@ int scan_get_wmainfo(char *filename, MP3FILE *pmp3) {
long offset=0;
int item;
int err;
int res=0;
int res=TRUE;
wma_fd = r_open2(filename,O_RDONLY);
if(wma_fd == -1) {
DPRINTF(E_INF,L_SCAN,"Error opening WMA file (%s): %s\n",filename,
strerror(errno));
return -1;
return FALSE;
}
if(read(wma_fd,(void*)&hdr,sizeof(hdr)) != sizeof(hdr)) {
DPRINTF(E_INF,L_SCAN,"Error reading from %s: %s\n",filename,
strerror(errno));
r_close(wma_fd);
return -1;
return FALSE;
}
pguid = wma_find_guid(hdr.objectid);
if(!pguid) {
DPRINTF(E_INF,L_SCAN,"Could not find header in %s\n",filename);
r_close(wma_fd);
return -1;
return FALSE;
}
hdr.objects=wma_convert_int((unsigned char *)&hdr.objects);
@ -751,7 +751,7 @@ int scan_get_wmainfo(char *filename, MP3FILE *pmp3) {
if(lseek(wma_fd,offset,SEEK_SET) == (off_t)-1) {
DPRINTF(E_INF,L_SCAN,"Error seeking in %s\n",filename);
r_close(wma_fd);
return -1;
return FALSE;
}
if(r_read(wma_fd,(void*)&subhdr,sizeof(subhdr)) != sizeof(subhdr)) {
@ -759,7 +759,7 @@ int scan_get_wmainfo(char *filename, MP3FILE *pmp3) {
DPRINTF(E_INF,L_SCAN,"Error reading from %s: %s\n",filename,
strerror(err));
r_close(wma_fd);
return -1;
return FALSE;
}
subhdr.size=wma_convert_ll((unsigned char *)&subhdr.size);
@ -768,11 +768,11 @@ int scan_get_wmainfo(char *filename, MP3FILE *pmp3) {
if(pguid) {
DPRINTF(E_DBG,L_SCAN,"Found subheader: %s\n",pguid->name);
if(strcmp(pguid->name,"ASF_Content_Description_Object")==0) {
res |= wma_parse_content_description(wma_fd,subhdr.size,pmp3);
res &= wma_parse_content_description(wma_fd,subhdr.size,pmp3);
} else if (strcmp(pguid->name,"ASF_Extended_Content_Description_Object")==0) {
res |= wma_parse_extended_content_description(wma_fd,subhdr.size,pmp3);
res &= wma_parse_extended_content_description(wma_fd,subhdr.size,pmp3);
} else if (strcmp(pguid->name,"ASF_File_Properties_Object")==0) {
res |= wma_parse_file_properties(wma_fd,subhdr.size,pmp3);
res &= wma_parse_file_properties(wma_fd,subhdr.size,pmp3);
}
} else {
DPRINTF(E_DBG,L_SCAN,"Unknown subheader: %02hhx%02hhx%02hhx%02hhx-"
@ -792,7 +792,7 @@ int scan_get_wmainfo(char *filename, MP3FILE *pmp3) {
}
if(res) {
if(!res) {
DPRINTF(E_INF,L_SCAN,"Error reading meta info for file %s\n",
filename);
} else {

View File

@ -255,10 +255,14 @@ char *scan_xml_urldecode(char *string, int space_as_plus) {
/**
* scan an iTunes xml music database file, augmenting
* the metainfo with that found in the xml file
*
* @param filename xml file to parse
* @returns TRUE if playlist parsed successfully, FALSE otherwise
*/
int scan_xml_playlist(char *filename) {
char *working_base;
const void *val;
int retval=TRUE;
SCAN_XML_RB *lookup_ptr;
SCAN_XML_RB lookup_val;
@ -274,7 +278,7 @@ int scan_xml_playlist(char *filename) {
/* initialize the redblack tree */
if((scan_xml_db = rbinit(scan_xml_rb_compare,NULL)) == NULL) {
DPRINTF(E_LOG,L_SCAN,"Could not initialize red/black tree\n");
return 0;
return FALSE;
}
/* find the base dir of the itunes playlist itself */
@ -294,6 +298,7 @@ int scan_xml_playlist(char *filename) {
filename,rxml_errorstring(xml_handle));
} else {
if(!rxml_parse(xml_handle)) {
retval=FALSE;
DPRINTF(E_LOG,L_SCAN,"Error parsing xml file %s: %s\n",
filename,rxml_errorstring(xml_handle));
}
@ -312,7 +317,7 @@ int scan_xml_playlist(char *filename) {
}
rbdestroy(scan_xml_db);
return 0;
return retval;
}