static void gimmix_tag_editor_save (GtkWidget *button, gpointer data) { gint year; gint track; gchar *genre = NULL; gchar *title = NULL; gchar *artist = NULL; gchar *album = NULL; gchar *comment = NULL; year = gtk_spin_button_get_value (GTK_SPIN_BUTTON(tag_year_spin)); taglib_tag_set_year (tag, year); track = gtk_spin_button_get_value (GTK_SPIN_BUTTON(tag_track_spin)); taglib_tag_set_track (tag, track); title = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_title))); artist = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_artist))); album = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_album))); comment = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_comment))); genre = gtk_combo_box_get_active_text (GTK_COMBO_BOX(tag_genre)); if (title) { taglib_tag_set_title (tag, g_strchomp(title)); } if (artist) { taglib_tag_set_artist (tag, g_strchomp(artist)); } if (album) { taglib_tag_set_album (tag, g_strchomp(album)); } if (comment) { taglib_tag_set_comment (tag, g_strchomp(comment)); } taglib_tag_set_genre (tag, genre); /* update the mpd database */ mpd_database_update_dir (gmo, "/"); /* set the song info a few seconds after update */ mpd_status_update (gmo); /* free the strings */ taglib_tag_free_strings (); taglib_file_save (file); g_free (title); g_free (artist); g_free (album); g_free (comment); return; }
gboolean save_tags_to_file(gchar *file, struct tags *ntag, int changed, struct con_win *cwin) { gboolean ret = TRUE; TagLib_File *tfile; TagLib_Tag *tag; if (!file || !changed) return FALSE; tfile = taglib_file_new(file); if (!tfile) { g_warning("Unable to open file using taglib : %s", file); return FALSE; } tag = taglib_file_tag(tfile); if (!tag) { g_warning("Unable to locate tag"); ret = FALSE; goto exit; } if (changed & TAG_TNO_CHANGED) taglib_tag_set_track(tag, ntag->track_no); if (changed & TAG_TITLE_CHANGED) taglib_tag_set_title(tag, ntag->title); if (changed & TAG_ARTIST_CHANGED) taglib_tag_set_artist(tag, ntag->artist); if (changed & TAG_ALBUM_CHANGED) taglib_tag_set_album(tag, ntag->album); if (changed & TAG_GENRE_CHANGED) taglib_tag_set_genre(tag, ntag->genre); if (changed & TAG_YEAR_CHANGED) taglib_tag_set_year(tag, ntag->year); if (changed & TAG_COMMENT_CHANGED) taglib_tag_set_comment(tag, ntag->comment); CDEBUG(DBG_VERBOSE, "Saving tags for file: %s", file); if (!taglib_file_save(tfile)) { g_warning("Unable to save tags for: %s\n", file); ret = FALSE; } taglib_tag_free_strings(); exit: taglib_file_free(tfile); return ret; }
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); } }
static void gimmix_tag_editor_save (GtkWidget *button, gpointer data) { gint year; gint track; gchar *genre; const gchar *title; const gchar *artist; const gchar *album; const gchar *comment; year = gtk_spin_button_get_value (GTK_SPIN_BUTTON(tag_year_spin)); taglib_tag_set_year (tag, year); track = gtk_spin_button_get_value (GTK_SPIN_BUTTON(tag_track_spin)); taglib_tag_set_track (tag, track); title = gtk_entry_get_text (GTK_ENTRY(tag_title)); artist = gtk_entry_get_text (GTK_ENTRY(tag_artist)); album = gtk_entry_get_text (GTK_ENTRY(tag_album)); comment = gtk_entry_get_text (GTK_ENTRY(tag_comment)); genre = gtk_combo_box_get_active_text (GTK_COMBO_BOX(tag_genre)); taglib_tag_set_title (tag, title); taglib_tag_set_artist (tag, artist); taglib_tag_set_album (tag, album); taglib_tag_set_comment (tag, comment); taglib_tag_set_genre (tag, genre); /* update the mpd database */ mpd_database_update_dir (gmo, "/"); /* set the song info a few seconds after update */ g_timeout_add (300, (GSourceFunc)gimmix_update_song_info, NULL); /* free the strings */ taglib_tag_free_strings (); taglib_file_save (file); return; }
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; }
/* * Mp4_Tag_Write_File_Tag: * * Write tag data into an Mp4 file. * * Note: * - for track numbers, we write 0's if one or the other is blank */ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile) { File_Tag *FileTag; gchar *filename; gchar *filename_utf8; FILE *file; TagLib_File *mp4file = NULL; TagLib_Tag *tag; gint error = 0; if (!ETFile || !ETFile->FileTag) return FALSE; FileTag = (File_Tag *)ETFile->FileTag->data; filename = ((File_Name *)ETFile->FileNameCur->data)->value; filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8; /* Test to know if we can write into the file */ if ( (file=fopen(filename,"r+"))==NULL ) { Log_Print(LOG_ERROR,_("ERROR while opening file: '%s' (%s)."),filename_utf8,g_strerror(errno)); return FALSE; } fclose(file); /* Open file for writing */ mp4file = taglib_file_new_type(filename, TagLib_File_MP4); if (mp4file == NULL) { Log_Print(LOG_ERROR,_("ERROR while opening file: '%s' (%s)."),filename_utf8,_("MP4 format invalid")); return FALSE; } tag = taglib_file_tag(mp4file); /********* * Title * *********/ if (FileTag->title && g_utf8_strlen(FileTag->title, -1) > 0) { taglib_tag_set_title(tag, FileTag->title); }else { taglib_tag_set_title(tag,""); } /********** * Artist * **********/ if (FileTag->artist && g_utf8_strlen(FileTag->artist, -1) > 0) { taglib_tag_set_artist(tag,FileTag->artist); }else { taglib_tag_set_artist(tag,""); } /********* * Album * *********/ if (FileTag->album && g_utf8_strlen(FileTag->album, -1) > 0) { taglib_tag_set_album(tag,FileTag->album); }else { taglib_tag_set_album(tag,""); } /******** * Year * ********/ if (FileTag->year && g_utf8_strlen(FileTag->year, -1) > 0) { taglib_tag_set_year(tag,atoi(FileTag->year)); }else { taglib_tag_set_year(tag,0); } /************************* * Track and Total Track * *************************/ if ( FileTag->track && g_utf8_strlen(FileTag->track, -1) > 0 ) { taglib_tag_set_track(tag,atoi(FileTag->track)); }else { taglib_tag_set_track(tag,0); } /********* * Genre * *********/ if (FileTag->genre && g_utf8_strlen(FileTag->genre, -1) > 0 ) { taglib_tag_set_genre(tag,FileTag->genre); }else { taglib_tag_set_genre(tag,""); } /*********** * Comment * ***********/ if (FileTag->comment && g_utf8_strlen(FileTag->comment, -1) > 0) { taglib_tag_set_comment(tag,FileTag->comment); }else { taglib_tag_set_comment(tag,""); } /********************** * Composer or Writer * **********************/ /***************** * Encoding Tool * *****************/ /*********** * Picture * ***********/ taglib_file_save(mp4file); taglib_file_free(mp4file); if (error) return FALSE; else return TRUE; }