2005-11-01 23:45:25 -05:00
|
|
|
/*
|
|
|
|
* Musepack tag parsing routines.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Sebastian Dröge <slomo@ubuntu.com>
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2006-11-14 00:29:32 -05:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
2005-11-01 23:45:25 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <taglib/tag_c.h>
|
|
|
|
|
2009-05-08 11:46:32 -04:00
|
|
|
#include "logger.h"
|
2009-04-20 10:53:47 -04:00
|
|
|
#include "ff-dbstruct.h"
|
2005-11-02 22:46:26 -05:00
|
|
|
|
2009-05-08 11:46:32 -04:00
|
|
|
#define TRUE ((1 == 1))
|
|
|
|
#define FALSE (!TRUE)
|
|
|
|
|
|
|
|
|
2005-11-01 23:45:25 -05:00
|
|
|
/**
|
2006-11-14 00:29:32 -05:00
|
|
|
* scan a musepack file for metainfo.
|
2005-11-01 23:45:25 -05:00
|
|
|
*
|
|
|
|
* @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_mpcinfo(char *filename, MP3FILE *pmp3) {
|
|
|
|
TagLib_File *file;
|
|
|
|
TagLib_Tag *tag;
|
2005-11-02 22:46:26 -05:00
|
|
|
const TagLib_AudioProperties *properties;
|
2005-11-01 23:45:25 -05:00
|
|
|
char *val;
|
|
|
|
int len;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* open file with taglib */
|
|
|
|
if ((file = taglib_file_new_type(filename, TagLib_File_MPC)) == NULL) {
|
|
|
|
DPRINTF(E_WARN,L_SCAN,"Could not open %s with taglib\n", filename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve all tags */
|
|
|
|
if ((tag = taglib_file_tag(file)) == NULL) {
|
|
|
|
DPRINTF(E_WARN,L_SCAN,"Could not retrieve tags of %s\n", filename);
|
|
|
|
taglib_file_free(file);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the MP3FILE structure with the tags */
|
|
|
|
if ((val = taglib_tag_title(tag)) != NULL) {
|
|
|
|
len = strlen(val);
|
|
|
|
if ((pmp3->title = calloc(len + 1, 1)) != NULL)
|
|
|
|
strncpy(pmp3->title, val, len);
|
2009-04-02 06:29:49 -04:00
|
|
|
taglib_tag_free_strings();
|
2005-11-01 23:45:25 -05:00
|
|
|
}
|
|
|
|
if ((val = taglib_tag_artist(tag)) != NULL) {
|
|
|
|
len = strlen(val);
|
|
|
|
if ((pmp3->artist = calloc(len + 1, 1)) != NULL)
|
|
|
|
strncpy(pmp3->artist, val, len);
|
2009-04-02 06:29:49 -04:00
|
|
|
taglib_tag_free_strings();
|
2005-11-01 23:45:25 -05:00
|
|
|
}
|
|
|
|
if ((val = taglib_tag_album(tag)) != NULL) {
|
|
|
|
len = strlen(val);
|
|
|
|
if ((pmp3->album = calloc(len + 1, 1)) != NULL)
|
|
|
|
strncpy(pmp3->album, val, len);
|
2009-04-02 06:29:49 -04:00
|
|
|
taglib_tag_free_strings();
|
2005-11-01 23:45:25 -05:00
|
|
|
}
|
|
|
|
if ((val = taglib_tag_comment(tag)) != NULL) {
|
|
|
|
len = strlen(val);
|
|
|
|
if ((pmp3->comment = calloc(len + 1, 1)) != NULL)
|
|
|
|
strncpy(pmp3->comment, val, len);
|
2009-04-02 06:29:49 -04:00
|
|
|
taglib_tag_free_strings();
|
2005-11-01 23:45:25 -05:00
|
|
|
}
|
|
|
|
if ((val = taglib_tag_genre(tag)) != NULL) {
|
|
|
|
len = strlen(val);
|
|
|
|
if ((pmp3->genre = calloc(len + 1, 1)) != NULL)
|
|
|
|
strncpy(pmp3->genre, val, len);
|
2009-04-02 06:29:49 -04:00
|
|
|
taglib_tag_free_strings();
|
2005-11-01 23:45:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((i = taglib_tag_year(tag)) != 0)
|
|
|
|
pmp3->year = i;
|
|
|
|
if ((i = taglib_tag_track(tag)) != 0)
|
|
|
|
pmp3->track = i;
|
|
|
|
|
|
|
|
/* load the properties (like bitrate) from the file */
|
|
|
|
if ((properties = taglib_file_audioproperties(file)) == NULL) {
|
|
|
|
DPRINTF(E_WARN,L_SCAN,"Could not retrieve properties of %s\n", filename);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the properties in the MP3FILE structure */
|
|
|
|
pmp3->song_length = taglib_audioproperties_length(properties) * 1000;
|
|
|
|
pmp3->bitrate = taglib_audioproperties_bitrate(properties);
|
|
|
|
pmp3->samplerate = taglib_audioproperties_samplerate(properties);
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2005-11-01 23:45:25 -05:00
|
|
|
taglib_file_free(file);
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2005-11-01 23:45:25 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|