/* 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 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; }
static void ecmd_tag_exec(int argc, char **argv) { TagLib_File *tag_file; TagLib_Tag *tag; int i; /* be verbose, indicate what we're setting... */ printf("Setting the following tags to all files:\n"); if (artist != NULL) printf("%10.10s => '%s'\n", "artist", artist); if (album != NULL) printf("%10.10s => '%s'\n", "album", album); if (title != NULL) printf("%10.10s => '%s'\n", "title", title); if (genre != NULL ) printf("%10.10s => '%s'\n", "genre", genre); if (track) printf("%10.10s => %u\n", "track", track); if (year) printf("%10.10s => %u\n", "year", year); if (comment != NULL) printf("%10.10s => '%s'\n", "comment", comment); /* tag files ... */ taglib_set_strings_unicode(false); for (i = 0; i < argc; i++) { printf("tagging: '%s'\n", argv[i]); /* extract taglib stuff */ if ((tag_file = taglib_file_new(argv[i])) == NULL) { warnx("TagLib: failed to open file '%s': skipping.", argv[i]); warnx(" => Causes: format not supported by TagLib or format doesn't support tags"); continue; } tag = taglib_file_tag(tag_file); /* apply changes */ if (artist != NULL) taglib_tag_set_artist(tag, artist); if (album != NULL) taglib_tag_set_album(tag, album); if (title != NULL) taglib_tag_set_title(tag, title); if (genre != NULL) taglib_tag_set_genre(tag, genre); if (track) taglib_tag_set_track(tag, track); if (year) taglib_tag_set_year(tag, year); if (comment != NULL) taglib_tag_set_comment(tag, comment); /* save changes and cleanup */ taglib_file_save(tag_file); taglib_tag_free_strings(); taglib_file_free(tag_file); } }
int ecmd_tag(int argc, char *argv[]) { TagLib_File *tag_file; TagLib_Tag *tag; bool set_artist = false; bool set_album = false; bool set_title = false; bool set_genre = false; bool set_track = false; bool set_year = false; bool set_comment = false; char *artist = NULL, *album = NULL, *title = NULL, *genre = NULL, *comment = NULL; const char *errstr = NULL; unsigned int track = 0, year = 0; char ch; char **files; int nfiles, f; static struct option longopts[] = { { "artist", required_argument, NULL, 'a' }, { "album", required_argument, NULL, 'A' }, { "title", required_argument, NULL, 't' }, { "genre", required_argument, NULL, 'g' }, { "track", required_argument, NULL, 'T' }, { "year", required_argument, NULL, 'y' }, { "comment", required_argument, NULL, 'c' }, { NULL, 0, NULL, 0 } }; /* parse options and get list of files */ optreset = 1; optind = 0; while ((ch = getopt_long_only(argc, argv, "a:A:t:g:T:y:c:", longopts, NULL)) != -1) { switch (ch) { case 'a': set_artist = true; if ((artist = strdup(optarg)) == NULL) err(1, "%s: strdup ARTIST failed", argv[0]); break; case 'A': set_album = true; if ((album = strdup(optarg)) == NULL) err(1, "%s: strdup ALBUM failed", argv[0]); break; case 't': set_title = true; if ((title = strdup(optarg)) == NULL) err(1, "%s: strdup TITLE failed", argv[0]); break; case 'g': set_genre = true; if ((genre = strdup(optarg)) == NULL) err(1, "%s: strdup GENRE failed", argv[0]); break; case 'T': set_track = true; track = (unsigned int) strtonum(optarg, 0, INT_MAX, &errstr); if (errstr != NULL) errx(1, "%s: invalid track '%s': %s", argv[0], optarg, errstr); break; case 'y': set_year = true; year = (unsigned int) strtonum(optarg, 0, INT_MAX, &errstr); if (errstr != NULL) errx(1, "%s: invalid year '%s': %s", argv[0], optarg, errstr); break; case 'c': set_comment = true; if ((comment = strdup(optarg)) == NULL) err(1, "%s: strdup COMMENT failed", argv[0]); break; case 'h': case '?': default: errx(1, "usage: see 'vitunes -e help tag'"); } } files = argv + optind; nfiles = argc - optind; /* be verbose, indicate what we're setting... */ printf("Setting the following tags to all files:\n"); if (set_artist) printf("%10.10s => '%s'\n", "artist", artist); if (set_album) printf("%10.10s => '%s'\n", "album", album); if (set_title) printf("%10.10s => '%s'\n", "title", title); if (set_genre) printf("%10.10s => '%s'\n", "genre", genre); if (set_track) printf("%10.10s => %i\n", "track", track); if (set_year) printf("%10.10s => %i\n", "year", year); if (set_comment) printf("%10.10s => '%s'\n", "comment", comment); if (!set_artist && !set_album && !set_title && !set_genre && !set_track && !set_year && !set_comment) errx(1, "%s: nothing to set! See 'vitunes -e help tag'", argv[0]); if (nfiles == 0) errx(1, "%s: must provide at least one file to tag.", argv[0]); /* tag files ... */ taglib_set_strings_unicode(false); for (f = 0; f < nfiles; f++) { printf("tagging: '%s'\n", files[f]); /* extract taglib stuff */ if ((tag_file = taglib_file_new(files[f])) == NULL) { warnx("TagLib: failed to open file '%s': skipping.", files[f]); printf(" => Causes: format not supported by TagLib or format doesn't support tags\n"); fflush(stdout); continue; } tag = taglib_file_tag(tag_file); /* apply changes */ if (set_artist) taglib_tag_set_artist(tag, artist); if (set_album) taglib_tag_set_album(tag, album); if (set_title) taglib_tag_set_title(tag, title); if (set_genre) taglib_tag_set_genre(tag, genre); if (set_track) taglib_tag_set_track(tag, track); if (set_year) taglib_tag_set_year(tag, year); if (set_comment) taglib_tag_set_comment(tag, comment); /* save changes and cleanup */ taglib_file_save(tag_file); taglib_tag_free_strings(); taglib_file_free(tag_file); } return 0; }
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; }
/* 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; }