// Gibt den Dateiname für einen Song zurück gchar *get_song_path (TagLib_Tag *tag, gchar *extension) { GString *path; gchar *artist, *title, *album; gint track; // Tags holen artist = g_strdelimit(taglib_tag_artist (tag), "/", '-'); title = g_strdelimit(taglib_tag_title (tag), "/", '-'); album = taglib_tag_album (tag); track = taglib_tag_track (tag); // Gibt Track-Nr oder 0 zurück // Starte mit Album Pfad path = g_string_new (get_album_dir (album, artist)); // Dateiname entsprechend den vorhanden Infos formatieren if (track > 0) { // Mit Track -> "01 Judas Priest - Painkiller" g_string_append_printf (path, "%.2d %s - %s%s", track, artist, title, extension); } else { // Ohne Track -> "Judas Priest - Painkiller" g_string_append_printf (path, "%s - %s%s", artist, title, extension); } // Gesamten Dateinamen zurückgeben return path->str; }
int print_metadata(const char *fbuf, char *basename) { filetype_t *cursor = filetypes; char *title, *artist; TagLib_File *tfile; TagLib_Tag *tag; do { if( !regexec(cursor->regex, fbuf, 0, NULL, 0) ) { if( !(tfile = taglib_file_new(fbuf)) ) return 1; tag = taglib_file_tag(tfile); artist = taglib_tag_artist(tag); title = taglib_tag_title(tag); if( !*title ) title = basename; printf("%s\t%s\t%s\n", fbuf, artist, title); taglib_tag_free_strings(); taglib_file_free(tfile); return 0; } } while( (++cursor)->extension ); return 1; }
struct Tags get_tags(char * file) { TagLib_File * file_tag; TagLib_Tag * tag_from; struct Tags tags; file_tag = taglib_file_new(file); tag_from = taglib_file_tag(file_tag); tags.artist = taglib_tag_artist(tag_from); escape(tags.artist); tags.title = taglib_tag_title (tag_from); escape(tags.title ); tags.album = taglib_tag_album (tag_from); escape(tags.album ); tags.genre = taglib_tag_genre (tag_from); escape(tags.genre ); tags.year = taglib_tag_year (tag_from); tags.id = taglib_tag_track (tag_from); return tags; }
/* Load the tag editor */ gboolean gimmix_tag_editor_populate (const gchar *song) { GtkTreeModel *genre_model; gchar *info; gint min; gint sec; gint n; const TagLib_AudioProperties *properties; if (!song) return FALSE; if (!g_file_test (song, G_FILE_TEST_EXISTS)) return FALSE; file = taglib_file_new (song); if (file == NULL) return FALSE; taglib_set_strings_unicode (FALSE); tag = taglib_file_tag (file); properties = taglib_file_audioproperties (file); gtk_spin_button_set_value (GTK_SPIN_BUTTON(tag_year_spin), taglib_tag_year(tag)); gtk_spin_button_set_value (GTK_SPIN_BUTTON(tag_track_spin), taglib_tag_track(tag)); gtk_label_set_text (GTK_LABEL(tag_file), song); gtk_entry_set_text (GTK_ENTRY(tag_title), g_strstrip(taglib_tag_title(tag))); gtk_entry_set_text (GTK_ENTRY(tag_artist), g_strstrip(taglib_tag_artist(tag))); gtk_entry_set_text (GTK_ENTRY(tag_album), g_strstrip(taglib_tag_album(tag))); gtk_entry_set_text (GTK_ENTRY(tag_comment), g_strstrip(taglib_tag_comment(tag))); gtk_combo_box_append_text (GTK_COMBO_BOX(tag_genre), taglib_tag_genre(tag)); genre_model = gtk_combo_box_get_model (GTK_COMBO_BOX(tag_genre)); n = gtk_tree_model_iter_n_children (genre_model, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX(tag_genre), n-1); /* Audio Information */ sec = taglib_audioproperties_length(properties) % 60; min = (taglib_audioproperties_length(properties) - sec) / 60; info = g_strdup_printf ("%02i:%02i", min, sec); gtk_label_set_text (GTK_LABEL(tag_info_length), info); g_free (info); info = g_strdup_printf ("%i Kbps", taglib_audioproperties_bitrate(properties)); gtk_label_set_text (GTK_LABEL(tag_info_bitrate), info); g_free (info); info = g_strdup_printf ("%i", taglib_audioproperties_channels(properties)); gtk_label_set_text (GTK_LABEL(tag_info_channels), info); g_free (info); taglib_tag_free_strings (); return TRUE; }
void metadata_use_taglib(metadata_t *md, FILE **filep) #ifdef HAVE_TAGLIB { TagLib_File *tf; TagLib_Tag *tt; const TagLib_AudioProperties *ta; char *str; if (md == NULL || md->filename == NULL) { printf("%s: metadata_use_taglib(): Internal error: Bad arguments\n", __progname); abort(); } if (filep != NULL) fclose(*filep); metadata_clean_md(md); taglib_set_string_management_enabled(0); taglib_set_strings_unicode(1); if (md->string != NULL) { xfree(md->string); md->string = NULL; } if ((tf = taglib_file_new(md->filename)) == NULL) { md->string = metadata_get_name(md->filename); return; } tt = taglib_file_tag(tf); ta = taglib_file_audioproperties(tf); str = taglib_tag_artist(tt); if (str != NULL) { if (strlen(str) > 0) md->artist = xstrdup(str); free(str); } str = taglib_tag_title(tt); if (str != NULL) { if (strlen(str) > 0) md->title = xstrdup(str); free(str); } md->songLen = taglib_audioproperties_length(ta); taglib_file_free(tf); }
int main() { int i; int seconds; int minutes; TagLib_File *file; TagLib_Tag *tag; const TagLib_AudioProperties *properties; //taglib_set_strings_unicode(FALSE); //file = taglib_file_new("/home/milo/Downloads/State_Of_My_Head.mp3"); if(file == NULL) { printf("Err: Can't opne new tab file\n"); exit(1); } tag = taglib_file_tag(file); if(tag != NULL) { printf("-- TAG --\n"); printf("title - \"%s\"\n", taglib_tag_title(tag)); printf("artist - \"%s\"\n", taglib_tag_artist(tag)); printf("album - \"%s\"\n", taglib_tag_album(tag)); printf("year - \"%i\"\n", taglib_tag_year(tag)); printf("comment - \"%s\"\n", taglib_tag_comment(tag)); printf("track - \"%i\"\n", taglib_tag_track(tag)); printf("genre - \"%s\"\n", taglib_tag_genre(tag)); } #if 0 if(properties != NULL) { seconds = taglib_audioproperties_length(properties) % 60; minutes = (taglib_audioproperties_length(properties) - seconds) / 60; printf("-- AUDIO --\n"); printf("bitrate - %i\n", taglib_audioproperties_bitrate(properties)); printf("sample rate - %i\n", taglib_audioproperties_samplerate(properties)); printf("channels - %i\n", taglib_audioproperties_channels(properties)); printf("length - %i:%02i\n", minutes, seconds); } #endif taglib_tag_free_strings(); taglib_file_free(file); return 0; }
int main(int argc, char *argv[]) { int i; int seconds; int minutes; TagLib_File *file; TagLib_Tag *tag; const TagLib_AudioProperties *properties; taglib_set_strings_unicode(FALSE); for(i = 1; i < argc; i++) { printf("******************** \"%s\" ********************\n", argv[i]); file = taglib_file_new(argv[i]); if(file == NULL) break; tag = taglib_file_tag(file); properties = taglib_file_audioproperties(file); if(tag != NULL) { printf("-- TAG --\n"); printf("title - \"%s\"\n", taglib_tag_title(tag)); printf("artist - \"%s\"\n", taglib_tag_artist(tag)); printf("album - \"%s\"\n", taglib_tag_album(tag)); printf("year - \"%i\"\n", taglib_tag_year(tag)); printf("comment - \"%s\"\n", taglib_tag_comment(tag)); printf("track - \"%i\"\n", taglib_tag_track(tag)); printf("genre - \"%s\"\n", taglib_tag_genre(tag)); } if(properties != NULL) { seconds = taglib_audioproperties_length(properties) % 60; minutes = (taglib_audioproperties_length(properties) - seconds) / 60; printf("-- AUDIO --\n"); printf("bitrate - %i\n", taglib_audioproperties_bitrate(properties)); printf("sample rate - %i\n", taglib_audioproperties_samplerate(properties)); printf("channels - %i\n", taglib_audioproperties_channels(properties)); printf("length - %i:%02i\n", minutes, seconds); } taglib_tag_free_strings(); taglib_file_free(file); } return 0; }
int main (int argc, char **argv) { TagLib_File *file; TagLib_Tag *tag; const TagLib_AudioProperties *properties; if (argc != 2) { fprintf (stderr, "usage: emms-print-metadata file.{mp3,ogg,flac}\nother formats may work as well.\n"); exit (1); } file = taglib_file_new (argv[1]); if (!file) { fprintf (stderr, "%s: File does not exist or is of an unknown type\n", argv[1]); exit (1); } tag = taglib_file_tag (file); /* Apparently, if the file is named foo.mp3 or similar, the library still can open it, for whatever reason. */ if (!tag) { fprintf (stderr, "%s: File does not exist or is of an unknown type\n", argv[1]); exit (1); } printf ("info-artist=%s\n", taglib_tag_artist (tag)); printf ("info-title=%s\n", taglib_tag_title (tag)); printf ("info-album=%s\n", taglib_tag_album (tag)); printf ("info-tracknumber=%d\n", taglib_tag_track (tag)); printf ("info-year=%d\n", taglib_tag_year (tag)); printf ("info-genre=%s\n", taglib_tag_genre (tag)); printf ("info-note=%s\n", taglib_tag_comment (tag)); properties = taglib_file_audioproperties (file); printf ("info-playing-time=%d\n", properties ? taglib_audioproperties_length (properties) : 0); taglib_tag_free_strings (); taglib_file_free (file); return 0; }
/* get an Itdb_Track from the given file */ Itdb_Track *track_parse(char *path, Itdb_iTunesDB *db) { TagLib_File *file = NULL; TagLib_Tag *tag = NULL; const TagLib_AudioProperties *audio = NULL; Itdb_Track *track = itdb_track_new(); FILE *track_file = fopen(path, "r"); fseek(track_file, 0, SEEK_END); track->size = ftell(track_file); fclose(track_file); /* we are storing our filename in userdata */ track->userdata = g_strdup(path); track->userdata_duplicate = (gpointer (*)(gpointer))g_strdup; track->userdata_destroy = g_free; track->transferred = FALSE; itdb_track_add(db, track, -1); file = taglib_file_new(path); if (file == NULL) { /* should this be an error? */ cpod_error("error reading metadata from \"%s\"\n", path); return track; } tag = taglib_file_tag(file); audio = taglib_file_audioproperties(file); /* g_strdup() string fields so that taglib_tag_free_strings() works */ track->title = g_strdup(taglib_tag_title(tag)); track->album = g_strdup(taglib_tag_album(tag)); track->artist = g_strdup(taglib_tag_artist(tag)); track->genre = g_strdup(taglib_tag_genre(tag)); track->comment = g_strdup(taglib_tag_comment(tag)); track->track_nr = taglib_tag_track(tag); track->year = taglib_tag_year(tag); /* audioproperties_length is in seconds and track->tracklen is in ms */ track->tracklen = taglib_audioproperties_length(audio) * 1000; track->samplerate = taglib_audioproperties_samplerate(audio); taglib_tag_free_strings(); /* taglib_file_free() frees TagLib_{Tag,AudioProperties} too */ taglib_file_free(file); return track; }
static gboolean get_info_taglib(gchar *file, struct tags *tags) { gboolean ret = FALSE; TagLib_File *tfile; TagLib_Tag *tag; const TagLib_AudioProperties *audio_prop; tfile = taglib_file_new(file); if (!tfile) { g_warning("Unable to open file using taglib : %s", file); ret = FALSE; goto exit; } tag = taglib_file_tag(tfile); if (!tag) { g_warning("Unable to locate tag"); ret = FALSE; goto exit; } audio_prop = taglib_file_audioproperties(tfile); if (!audio_prop) { g_warning("Unable to locate audio properties"); ret = FALSE; goto exit; } tags->title = g_strdup(taglib_tag_title(tag)); tags->artist = g_strdup(taglib_tag_artist(tag)); tags->album = g_strdup(taglib_tag_album(tag)); tags->genre = g_strdup(taglib_tag_genre(tag)); tags->comment = g_strdup(taglib_tag_comment(tag)); tags->track_no = taglib_tag_track(tag); tags->year = taglib_tag_year(tag); tags->bitrate = taglib_audioproperties_bitrate(audio_prop); tags->length = taglib_audioproperties_length(audio_prop); tags->channels = taglib_audioproperties_channels(audio_prop); tags->samplerate = taglib_audioproperties_samplerate(audio_prop); ret = TRUE; exit: taglib_tag_free_strings(); taglib_file_free(tfile); return ret; }
// Datei in Datenbank eintragen gboolean register_file (gchar *file) { TagLib_File *tagfile; TagLib_Tag *tag; gint id_track; gchar *line; TrackDetails *track; // Prüfen ob die Datei gültig ist tagfile = taglib_file_new (file); if (tagfile == NULL) { return FALSE; } // Prüfen ob wir Tags haben tag = taglib_file_tag (tagfile); if (tagfile == NULL) { return FALSE; } // Track hinzufügen track = track_new (); track->number = taglib_tag_track (tag); track->path = g_strdup (file); track->title = g_strdup (taglib_tag_title (tag)); track->artist->name = g_strdup (taglib_tag_artist (tag)); track->album->title = g_strdup (taglib_tag_album (tag)); track->album->genre = g_strdup (taglib_tag_genre (tag)); id_track = db_track_add (track); line = g_strdup_printf ("Importiert: %s - %s (%s)", track->artist->name, track->title, track->album->title); settings_import_messages_add (line); g_free (line); // Speicher freigeben track_free (track); taglib_file_free (tagfile); return TRUE; }
//Read the meta tags of media_file and update eclair with the new data void eclair_meta_tag_read(Eclair *eclair, Eclair_Media_File *media_file) { TagLib_File *tag_file; TagLib_Tag *tag; const TagLib_AudioProperties *tag_audio_props; Evas_Bool need_to_update = 0; if (!eclair || !media_file || !media_file->path) return; if (!eclair_database_get_meta_infos(&eclair->database, media_file, &need_to_update) || need_to_update) { if (!(tag_file = taglib_file_new(media_file->path))) return; if ((tag = taglib_file_tag(tag_file))) { eclair_media_file_set_field_string(&media_file->artist, taglib_tag_artist(tag)); eclair_media_file_set_field_string(&media_file->title, taglib_tag_title(tag)); eclair_media_file_set_field_string(&media_file->album, taglib_tag_album(tag)); eclair_media_file_set_field_string(&media_file->genre, taglib_tag_genre(tag)); eclair_media_file_set_field_string(&media_file->comment, taglib_tag_comment(tag)); media_file->year = taglib_tag_year(tag); media_file->track = taglib_tag_track(tag); } if ((tag_audio_props = taglib_file_audioproperties(tag_file))) { media_file->length = taglib_audioproperties_length(tag_audio_props); media_file->bitrate = taglib_audioproperties_bitrate(tag_audio_props); media_file->samplerate = taglib_audioproperties_samplerate(tag_audio_props); } taglib_tag_free_strings(); taglib_file_free(tag_file); //Insert the new tag infos in the database eclair_database_insert_media_file(&eclair->database, media_file); } //Try to load the cover if (!media_file->cover_path && !(media_file->cover_path = eclair_cover_file_get_from_local(&eclair->cover_manager, media_file->artist, media_file->album, media_file->path))) eclair_cover_add_file_to_treat(&eclair->cover_manager, media_file); }
/* TODO: Create alist to represent various slots in a Tag */ static emacs_value Ftaglib_core_tag_title (emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data) { emacs_value lisp_str = args[0]; ptrdiff_t size = 0; char * buf = NULL; env->copy_string_contents (env, lisp_str, buf, &size); buf = malloc (size); env->copy_string_contents (env, lisp_str, buf, &size); TagLib_File * file = taglib_file_new (buf); TagLib_Tag * tag = taglib_file_tag (file); char * title = taglib_tag_title (tag); emacs_value rtv = env->make_string (env, title, strlen (title) - 1); taglib_file_free (file); return rtv; }
// Prüft ob alle Tags gesetzt sind für den Import gboolean check_tags (TagLib_Tag *tag) { gboolean correct = TRUE; gchar *artist, *title, *album; artist = taglib_tag_artist (tag); title = taglib_tag_title (tag); album = taglib_tag_album (tag); if (artist == NULL || strcmp(artist, "") == 0) { correct = FALSE; } if (title == NULL || strcmp(title, "") == 0) { correct = FALSE; } if (album == NULL || strcmp(album, "") == 0) { correct = FALSE; } return correct; }
void read_file(const char *fn, const struct stat *status) { TagLib_File *file; TagLib_Tag *tlib_tag; tag_t tag; file = taglib_file_new(fn); if (file == NULL) { perror(fn); return; } tlib_tag = taglib_file_tag(file); if (tlib_tag != NULL) { tag.fn = (char *) fn; tag.artist = taglib_tag_artist(tlib_tag); tag.album = taglib_tag_album(tlib_tag); tag.title = taglib_tag_title(tlib_tag); tag.year = taglib_tag_year(tlib_tag); tag.genre = taglib_tag_genre(tlib_tag); tag.track = taglib_tag_track(tlib_tag); tag.lastupdate = status->st_mtime; if (strcmp(fn + strlen(fn) - 4, ".mp3") == 0) tag.type = "mp3"; else if (strcmp(fn + strlen(fn) - 4, ".ogg") == 0) tag.type = "ogg"; else if (strcmp(fn + strlen(fn) - 5, ".flac") == 0) tag.type = "flac"; insert_song(tag); } else { printf("No tag in file: %s\n", fn); } taglib_tag_free_strings(); taglib_file_free(file); }
/** funzione di callback applicata da init_db() (usabile anche esternamente, ovvio, ma aggiunge al db solo file locali!) prende un percorso (si assume che punti ad un file valido). Se questo è un file supportato da taglib, ne analizza i tag e inserisce i dati nel database \attention le query *non* sono generiche, nè usano il file constants.h! inoltre, poiché questi dati saranno usati per generare i percorsi virtuali, non sono ammessi metadati col carattere '/': in tal caso saranno sostituiti col carattere '_' \param db database (di tipo sqlite*, ma castato a void* per questioni di compatibilità) \param path percorso del file da analizzare e, se supportato, aggiungere al database \return 0 se non ci sono errori, -1 altrimenti \sa init_db(), esegui_query(), preprocessing() */ int add_local_file_in_db(void* db, const char* path) { warn("[add_local_file_in_db] path = `%s'\n", path); TagLib_File* tlf = taglib_file_new(path); if (!tlf) return -1; TagLib_Tag* tlt = taglib_file_tag(tlf); // automaticamente free`d char* titolo = preprocessing(taglib_tag_title(tlt)); char* artista = preprocessing(taglib_tag_artist(tlt)); char* album = preprocessing(taglib_tag_album(tlt)); char* genere = preprocessing(taglib_tag_genre(tlt)); unsigned int anno = taglib_tag_year(tlt); unsigned int traccia = taglib_tag_track(tlt); char* anno_s = calloc(5, 1); // andrà bene fino all'anno 9999 char* traccia_s = calloc(3, 1); // andrà bene fino alla traccia 99 snprintf(anno_s, 5, "%04d", anno); snprintf(traccia_s, 3, "%02d", traccia); if (esegui_query(db, "INSERT OR REPLACE INTO artista(nome_artista) values " "(%Q)", artista) == -1) return -1; if (esegui_query(db, "INSERT OR REPLACE INTO musica(titolo, nome_album," " traccia, genere, artista_nome_artista, lavoro_anno) values " "(%Q, %Q, %Q, %Q, %Q, %Q)", titolo, album, traccia_s, genere, artista, anno_s) == -1) return -1; if (esegui_query(db, "INSERT OR REPLACE INTO file(host, path, permessi," " formato, dimensioni, data_ultimo_aggiornamento, musica_titolo" ", musica_nome_album, musica_traccia, basename) values (" "'127.0.0.1', %Q, %d, %Q, %d, NULL, %Q, %Q, %Q, %Q)", path, 6, extract_extension(path), extract_size(path), titolo, album, traccia_s, extract_basename(path)) == -1) return -1; taglib_tag_free_strings(); taglib_file_free(tlf); return 0; }
gchar * _get_formatted_song ( gchar *filename ) { TagLib_File *file; TagLib_Tag *tag; const TagLib_AudioProperties *properties; gchar *title = NULL; gchar *artist = NULL; int minutes, seconds; gchar *row = NULL; file = taglib_file_new ( filename ); if ( file == NULL ) { return ( NULL ); } tag = taglib_file_tag ( file ); properties = taglib_file_audioproperties ( file ); title = taglib_tag_title ( tag ); artist = taglib_tag_artist ( tag ); seconds = taglib_audioproperties_length(properties) % 60; minutes = (taglib_audioproperties_length(properties) - seconds) / 60; if ( strlen ( title ) == 0 ) { gchar **tokens = NULL; int i = 0; tokens = g_strsplit ( filename, "/", 0 ); if ( tokens != NULL ) { while ( tokens[i] != NULL ) i++; title = g_strdup ( tokens[i-1] ); } g_strfreev ( tokens ); } if ( strlen ( artist ) == 0 ) artist = "Unknown"; /* track duration */ gchar duration[25]; snprintf( duration, 24, "%i:%02i", minutes, seconds); /* row constructor */ row = g_strconcat ( "<span variant='smallcaps'>", g_markup_escape_text ( title, -1 ), "</span> - <small><i>", g_markup_escape_text ( artist, -1 ), "</i> : ", duration, "</small>", NULL ); /*g_free ( title ); g_free ( artist );*/ taglib_tag_free_strings ( ); taglib_file_free ( file ); return ( g_strdup (row) ); }
/* Load the tag editor */ gboolean gimmix_tag_editor_populate (const void *song) { GtkTreeModel *genre_model; gchar *info; gint n; guint year = 0; guint track = 0; gchar *title = NULL; gchar *artist = NULL; gchar *album = NULL; gchar *genre = NULL; gchar *comment = NULL; if (!song) return FALSE; #ifdef HAVE_TAGEDITOR const TagLib_AudioProperties *properties; if (!g_file_test(song,G_FILE_TEST_EXISTS)) return FALSE; file = taglib_file_new (song); if (file == NULL) return FALSE; taglib_set_strings_unicode (FALSE); tag = taglib_file_tag (file); properties = taglib_file_audioproperties (file); #else mpd_Song *foo = (mpd_Song*) g_malloc0 (sizeof(mpd_Song)); memcpy (foo, song, sizeof(mpd_Song)); #endif #ifdef HAVE_TAGEDITOR year = taglib_tag_year (tag); track = taglib_tag_track (tag); title = g_strstrip (taglib_tag_title(tag)); artist = g_strstrip (taglib_tag_artist(tag)); album = g_strstrip (taglib_tag_album(tag)); comment = g_strstrip (taglib_tag_comment(tag)); genre = taglib_tag_genre (tag); #else if (foo->date) { year = atoi (foo->date); } if (foo->track) { track = atoi (foo->track); } title = foo->title; artist = foo->artist; album = foo->album; comment = foo->comment; genre = foo->genre; #endif gtk_spin_button_set_value (GTK_SPIN_BUTTON(tag_year_spin), year); gtk_spin_button_set_value (GTK_SPIN_BUTTON(tag_track_spin), track); gtk_entry_set_text (GTK_ENTRY(tag_file), #ifdef HAVE_TAGEDITOR song #else foo->file #endif ); if (title) { gtk_entry_set_text (GTK_ENTRY(tag_title), title); } if (artist) { gtk_entry_set_text (GTK_ENTRY(tag_artist), artist); } if (album) { gtk_entry_set_text (GTK_ENTRY(tag_album), album); } if (comment) { gtk_entry_set_text (GTK_ENTRY(tag_comment), comment); } if (genre) { gtk_combo_box_append_text (GTK_COMBO_BOX(tag_genre), genre); } genre_model = gtk_combo_box_get_model (GTK_COMBO_BOX(tag_genre)); n = gtk_tree_model_iter_n_children (genre_model, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX(tag_genre), n-1); /* Audio Information */ #ifdef HAVE_TAGEDITOR guint sec = taglib_audioproperties_length(properties) % 60; guint min = (taglib_audioproperties_length(properties) - sec) / 60; info = g_strdup_printf ("%02i:%02i", min, sec); gtk_label_set_text (GTK_LABEL(tag_info_length), info); #else char *tok = NULL; info = (char*) g_malloc0 (sizeof(char)*32); gimmix_get_progress_status (gmo, NULL, info); tok = strtok (info, "/"); tok = strtok (NULL, "/"); g_strstrip (tok); gtk_label_set_text (GTK_LABEL(tag_info_length), tok); #endif g_free (info); #ifdef HAVE_TAGEDITOR info = g_strdup_printf ("%i Kbps", taglib_audioproperties_bitrate(properties)); #else info = g_strdup_printf ("%i Kbps", mpd_status_get_bitrate(gmo)); #endif gtk_label_set_text (GTK_LABEL(tag_info_bitrate), info); g_free (info); #ifdef HAVE_TAGEDITOR info = g_strdup_printf ("%i", taglib_audioproperties_channels(properties)); #else info = g_strdup_printf ("%i", mpd_status_get_channels(gmo)); #endif gtk_label_set_text (GTK_LABEL(tag_info_channels), info); g_free (info); #ifdef HAVE_TAGEDITOR taglib_tag_free_strings (); #else free (foo); #endif return TRUE; }
static int get_track_info(char *fullPath, mps_library_track_info_t *track_info) { int rv = MPS_LIBRARYDBD_SUCCESS; TagLib_File *tagLibFile; TagLib_Tag *tagLibTag; TagLib_File_Type tagLibType; mps_library_element_type_t mpsFileType; const TagLib_AudioProperties *tagLibProp; char *tmpString; MPS_DBG_PRINT("Entering %s(0x%08x)\n", __func__, (unsigned int) track_info); taglib_set_strings_unicode(true); mpsFileType = track_info->file_type; tagLibType = (mpsFileType==MPS_LIBRARY_MP3_FILE?TagLib_File_MPEG: mpsFileType==MPS_LIBRARY_FLAC_FILE?TagLib_File_FLAC: mpsFileType==MPS_LIBRARY_OGG_FILE?TagLib_File_OggVorbis: mpsFileType==MPS_LIBRARY_AAC_FILE?TagLib_File_MP4: mpsFileType==MPS_LIBRARY_APPLE_LOSSLESS_FILE?TagLib_File_MP4: mpsFileType==MPS_LIBRARY_WMA_FILE?TagLib_File_ASF: mpsFileType==MPS_LIBRARY_AIF_FILE?TagLib_File_AIFF: mpsFileType==MPS_LIBRARY_WAV_FILE?TagLib_File_WAV: 0); tagLibFile = taglib_file_new_type(fullPath, tagLibType); if(tagLibFile == NULL) { MPS_DBG_PRINT("Call to taglib_file_new(%s) failed.\n", fullPath); rv = MPS_LIBRARYDBD_FAILURE; goto ERR_OUT; } tagLibTag = taglib_file_tag(tagLibFile); tagLibProp = taglib_file_audioproperties(tagLibFile); /* TODO: need to go one step further to determine whether a file with an "m4a", etc. header is actually an apple lossless */ track_info->file_type = mpsFileType; tmpString = taglib_tag_title(tagLibTag); if (tmpString != NULL) { copy_string_without_edge_whitespace(track_info->title, tmpString, MPS_MAX_TRACK_INFO_FIELD_LENGTH); MPS_DBG_PRINT("Copied \"%s\" into track_title->title\n", track_info->title); } tmpString = taglib_tag_album(tagLibTag); if (tmpString != NULL) { copy_string_without_edge_whitespace(track_info->album, tmpString, MPS_MAX_TRACK_INFO_FIELD_LENGTH); MPS_DBG_PRINT("Copied \"%s\" into track_title->album\n", track_info->album); } tmpString = taglib_tag_artist(tagLibTag); if (tmpString != NULL) { copy_string_without_edge_whitespace(track_info->artist, tmpString, MPS_MAX_TRACK_INFO_FIELD_LENGTH); MPS_DBG_PRINT("Copied \"%s\" into track_title->artist\n", track_info->artist); } track_info->year = taglib_tag_year(tagLibTag); MPS_DBG_PRINT("Copied \"%d\" into track_title->year\n", track_info->year); tmpString = taglib_tag_genre(tagLibTag); if (tmpString != NULL) { copy_string_without_edge_whitespace(track_info->genre, tmpString, MPS_MAX_TRACK_INFO_FIELD_LENGTH); MPS_DBG_PRINT("Copied \"%s\" into track_title->genre\n", track_info->genre); } track_info->ordinal_track_number = taglib_tag_track(tagLibTag); MPS_DBG_PRINT("Copied \"%d\" into track_title->ordinal_track_number\n", track_info->ordinal_track_number); if (tagLibProp != NULL) { MPS_DBG_PRINT("Setting bitrate, etc.\n"); track_info->bitrate = taglib_audioproperties_bitrate(tagLibProp); track_info->sampling_rate = taglib_audioproperties_samplerate(tagLibProp); track_info->channel_mode = (taglib_audioproperties_channels(tagLibProp) < 2 ? MPS_CHANNEL_MODE_MONO: MPS_CHANNEL_MODE_STEREO); track_info->vbr_mode = MPS_VBR_MODE_UNKNOWN; track_info->time_length = taglib_audioproperties_length(tagLibProp); #if 0 track_info->channel_mode = ((finfo.mode==MPG123_M_STEREO)?MPS_CHANNEL_MODE_STEREO: ((finfo.mode==MPG123_M_JOINT)?MPS_CHANNEL_MODE_JOINT_STEREO: ((finfo.mode==MPG123_M_DUAL)?MPS_CHANNEL_MODE_DUAL_CHANNEL: ((finfo.mode==MPG123_M_MONO)?MPS_CHANNEL_MODE_MONO: MPS_CHANNEL_MODE_UNKNOWN)))); track_info->vbr_mode = ((finfo.vbr==MPG123_CBR)?MPS_VBR_MODE_CONSTANT: ((finfo.vbr==MPG123_VBR)?MPS_VBR_MODE_VARIABLE: ((finfo.vbr==MPG123_ABR)?MPS_VBR_MODE_AVERAGE: MPS_VBR_MODE_UNKNOWN))); if (track_info->sampling_rate > 0) { total_samples = mpg123_length_64(m); track_info->time_length = total_samples/track_info->sampling_rate; } #endif } else { MPS_LOG("taglib_file_audioproperties() returned NULL"); } ERR_OUT: taglib_tag_free_strings(); taglib_file_free(tagLibFile); MPS_DBG_PRINT("Leaving %s() - return value %d\n", __func__, rv); return rv; }
/** * scan a musepack 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_mpcinfo(char *filename, MP3FILE *pmp3) { TagLib_File *file; TagLib_Tag *tag; const TagLib_AudioProperties *properties; 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); taglib_tag_free_strings(); } if ((val = taglib_tag_artist(tag)) != NULL) { len = strlen(val); if ((pmp3->artist = calloc(len + 1, 1)) != NULL) strncpy(pmp3->artist, val, len); taglib_tag_free_strings(); } if ((val = taglib_tag_album(tag)) != NULL) { len = strlen(val); if ((pmp3->album = calloc(len + 1, 1)) != NULL) strncpy(pmp3->album, val, len); taglib_tag_free_strings(); } if ((val = taglib_tag_comment(tag)) != NULL) { len = strlen(val); if ((pmp3->comment = calloc(len + 1, 1)) != NULL) strncpy(pmp3->comment, val, len); taglib_tag_free_strings(); } if ((val = taglib_tag_genre(tag)) != NULL) { len = strlen(val); if ((pmp3->genre = calloc(len + 1, 1)) != NULL) strncpy(pmp3->genre, val, len); taglib_tag_free_strings(); } 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); taglib_file_free(file); return TRUE; }
int hgd_get_tag_metadata(char *filename, struct hgd_media_tag *meta) { #ifdef HAVE_TAGLIB TagLib_File *file; TagLib_Tag *tag; const TagLib_AudioProperties *ap; #endif DPRINTF(HGD_D_DEBUG, "Attempting to read tags for '%s'", filename); meta->artist = xstrdup(""); meta->title = xstrdup(""); meta->album = xstrdup(""); meta->genre = xstrdup(""); meta->year = 0; meta->duration = 0; meta->samplerate = 0; meta->channels = 0; meta->bitrate = 0; #ifdef HAVE_TAGLIB file = taglib_file_new(filename); if (file == NULL) { DPRINTF(HGD_D_DEBUG, "taglib could not open '%s'", filename); return (HGD_FAIL); } if (!taglib_file_is_valid(file)) { DPRINTF(HGD_D_WARN, "invalid tag in '%s'", filename); return (HGD_FAIL); } tag = taglib_file_tag(file); if (tag == NULL) { DPRINTF(HGD_D_WARN, "failed to get tag of '%s'", filename); return (HGD_FAIL); } free(meta->artist); free(meta->title); free(meta->album); free(meta->genre); meta->artist = xstrdup(taglib_tag_artist(tag)); meta->title = xstrdup(taglib_tag_title(tag)); meta->album = xstrdup(taglib_tag_album(tag)); meta->genre = xstrdup(taglib_tag_genre(tag)); meta->year = taglib_tag_year(tag); /* now audio properties: i dont consider this failing fatal */ ap = taglib_file_audioproperties(file); if (ap != NULL) { meta->duration = taglib_audioproperties_length(ap); meta->samplerate = taglib_audioproperties_samplerate(ap); meta->channels = taglib_audioproperties_channels(ap); meta->bitrate = taglib_audioproperties_bitrate(ap); } else { DPRINTF(HGD_D_WARN, "failed to get audio properties: %s", filename); } DPRINTF(HGD_D_INFO, "Got tag from '%s': '%s' by '%s' from the album '%s' from the year" "'%u' of genre '%s' [%d secs, %d chans, %d Hz, %d bps]\n", filename, meta->title, meta->artist, meta->album, meta->year, meta->genre, meta->duration, meta->channels, meta->samplerate, meta->bitrate); taglib_tag_free_strings(); #else DPRINTF(HGD_D_DEBUG, "No taglib support, skipping tag retrieval"); #endif return (HGD_OK); }
static int build_path_from_tag(const char *filepath, struct filename *fn) { TagLib_File *file; TagLib_Tag *tag; int ret = -1; char *p = FMT; file = taglib_file_new(filepath); if (!file) { fprintf(stderr, "'%s' type cannot be determined" " or file cannot be opened.\n", filepath); goto free_taglib; } if (!taglib_file_is_valid(file)) { fprintf(stderr, "The file %s is not valid\n", filepath); goto free_taglib; } tag = taglib_file_tag(file); if (!tag) { fprintf(stderr, "The file %s is not valid.\n", filepath); goto free_taglib; } while (*p) { if (*p != '%') { ret = append(fn, "%c", *p++); } else { switch (*++p) { case 'a': ret = append_esc(fn, "%s", taglib_tag_artist(tag)); break; case 'A': ret = append_esc(fn, "%s", taglib_tag_album(tag)); break; case 't': ret = append_esc(fn, "%02d", taglib_tag_track(tag)); break; case 'T': ret = append_esc(fn, "%s", taglib_tag_title(tag)); break; case 'y': ret = append_esc(fn, "%d", taglib_tag_year(tag)); break; default: break; } ++p; } if (ret) goto free_taglib; } free_taglib: taglib_tag_free_strings(); taglib_file_free(file); return ret; }
/* * Mp4_Tag_Read_File_Tag: * * Read tag data into an Mp4 file. * * Note: * - for string fields, //if field is found but contains no info (strlen(str)==0), we don't read it * - for track numbers, if they are zero, then we don't read it */ gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag) { FILE *file; TagLib_File *mp4file; TagLib_Tag *tag; guint track; if (!filename || !FileTag) return FALSE; if ( (file=fopen(filename,"r"))==NULL ) { gchar *filename_utf8 = filename_to_display(filename); Log_Print(LOG_ERROR,_("ERROR while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno)); g_free(filename_utf8); return FALSE; } fclose(file); // We close it cause mp4 opens/closes file itself /* Get data from tag */ mp4file = taglib_file_new_type(filename,TagLib_File_MP4); if (mp4file == NULL) { gchar *filename_utf8 = filename_to_display(filename); Log_Print(LOG_ERROR,_("ERROR while opening file: '%s' (%s)."),filename_utf8,_("MP4 format invalid")); g_free(filename_utf8); return FALSE; } /* TODO Add error detection */ tag = taglib_file_tag(mp4file); /********* * Title * *********/ FileTag->title = g_strdup(taglib_tag_title(tag)); /********** * Artist * **********/ FileTag->artist = g_strdup(taglib_tag_artist(tag)); /********* * Album * *********/ FileTag->album = g_strdup(taglib_tag_album(tag)); /**************** * Album Artist * ****************/ /* TODO: No album artist or disc number support in the TagLib C API! */ /******** * Year * ********/ FileTag->year = g_strdup_printf("%u", taglib_tag_year(tag)); /************************* * Track and Total Track * *************************/ track = taglib_tag_track(tag); if (track != 0) FileTag->track = NUMBER_TRACK_FORMATED ? g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,(gint)track) : g_strdup_printf("%d",(gint)track); /* TODO: No total track support in the TagLib C API! */ /********* * Genre * *********/ FileTag->genre = g_strdup(taglib_tag_genre(tag)); /*********** * Comment * ***********/ FileTag->comment = g_strdup(taglib_tag_comment(tag)); /********************** * Composer or Writer * **********************/ /* TODO: No composer support in the TagLib C API! */ /***************** * Encoding Tool * *****************/ /* TODO: No encode_by support in the TagLib C API! */ /*********** * Picture * ***********/ /* TODO: No encode_by support in the TagLib C API! */ /* Free allocated data */ taglib_tag_free_strings(); taglib_file_free(mp4file); return TRUE; }