gint sort(FmFileInfo *fi1, FmFileInfo *fi2){ char *filename1, *filename2; int year1 = 0, year2 = 0; TagLib_File *TL_file1, *TL_file2; filename1 = fm_path_to_str( fm_file_info_get_path(fi1) ); filename2 = fm_path_to_str( fm_file_info_get_path(fi2) ); TL_file1 = taglib_file_new( filename1 ); TL_file2 = taglib_file_new( filename2 ); free( filename1 ); free( filename2 ); if (TL_file1 != NULL) { if(taglib_file_is_valid(TL_file1)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file1 ); year1 = taglib_tag_year( TL_tag ); taglib_tag_free_strings(); taglib_file_free( TL_file1 ); } } if (TL_file2 != NULL) { if(taglib_file_is_valid(TL_file2)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file2 ); year2 = taglib_tag_year( TL_tag ); taglib_tag_free_strings(); taglib_file_free( TL_file2 ); } } return year1 - year2; }
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; }
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; }
void get_value(FmFileInfo *fi, GValue *value){ char* filename; int year; char year_string[10]; TagLib_File *TL_file; TagLib_Tag *TL_tag; filename = fm_path_to_str( fm_file_info_get_path(fi) ); TL_file = taglib_file_new( filename ); free( filename ); if (TL_file != NULL) { if(taglib_file_is_valid(TL_file)){ TL_tag = taglib_file_tag( TL_file ); year = taglib_tag_year( TL_tag ); if( year !=0 ){ sprintf( year_string, "%d", year ); g_value_set_string( value, year_string ); } taglib_tag_free_strings(); taglib_file_free( TL_file ); } } };
/** * Open a file via taglib and add file type information * * Open files, that taglib supports but taggit doesn't have specific support * for using TagLibs generic interface only. That will stop us from working * with multi-artist files for those types, but it's better than nothing. * * @param file file name to open * * @return copy of the generated struct taggit_file; *NOT* a pointer * to it! Destroy using taggit_file_destroy(). * @sideeffects none */ struct taggit_file taggit_file_open(const char *file) { struct taggit_file rc; char *ext; ext = (char *)strrchr(file, (int)'.'); if (ext == NULL || *(ext + 1) == '\0') goto err; ext++; if (strcaseeq(ext, (char *)"mp3")) { rc.data = reinterpret_cast<TagLib_File *> (new TagLib::MPEG::File(file)); rc.type = FT_MPEG; } else if (strcaseeq(ext, (char *)"ogg")) { rc.data = reinterpret_cast<TagLib_File *> (new TagLib::Ogg::Vorbis::File(file)); rc.type = FT_OGGVORBIS; } else if (strcaseeq(ext, (char *)"oga")) { TagLib::File *f; f = new TagLib::Ogg::FLAC::File(file); if (f->isValid()) { rc.data = reinterpret_cast<TagLib_File *>(f); rc.type = FT_OGGFLAC; } else { delete f; rc.data = reinterpret_cast<TagLib_File *> (new TagLib::Ogg::Vorbis::File(file)); rc.type = FT_OGGVORBIS; } } else if (strcaseeq(ext, (char *)"flac")) { rc.data = reinterpret_cast<TagLib_File *> (new TagLib::FLAC::File(file)); rc.type = FT_FLAC; } else { TagLib_File *f; f = taglib_file_new(file); if (!taglib_file_is_valid(f)) { taglib_file_free(f); goto err; } else { rc.data = f; rc.type = FT_UNKNOWN; } } return rc; err: fprintf(stderr, "Cannot handle file: \"%s\" - skipping.\n", file); rc.data = NULL; rc.type = FT_INVALID; return rc; }
/* 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); }
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; }
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; }
gint sort(FmFileInfo *fi1, FmFileInfo *fi2){ int result; char *filename1, *filename2; char *genre1=NULL, *genre2=NULL; TagLib_File *TL_file1, *TL_file2; filename1 = fm_path_to_str( fm_file_info_get_path(fi1) ); filename2 = fm_path_to_str( fm_file_info_get_path(fi2) ); TL_file1 = taglib_file_new( filename1 ); TL_file2 = taglib_file_new( filename2 ); free( filename1 ); free( filename2 ); if (TL_file1 != NULL) { if(taglib_file_is_valid(TL_file1)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file1 ); genre1 = taglib_tag_genre( TL_tag ); taglib_file_free( TL_file1 ); } } if (TL_file2 != NULL) { if(taglib_file_is_valid(TL_file2)){ TagLib_Tag *TL_tag = taglib_file_tag( TL_file2 ); genre2 = taglib_tag_genre( TL_tag ); taglib_file_free( TL_file2 ); } } result = strcasecmp(genre1, genre2); if (TL_file1 != NULL || TL_file2 != NULL) { taglib_tag_free_strings(); } return result; }
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; }
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); } }
/* 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; }
char * CalculateDiscId(const char * directory) { char * * files = GetFilesFromDirectory(directory); char * * file_ptr = files; char offsets[1500], temp_arr[1500]; char * str_ptr = offsets; int total_time = 0; int total_ofset = 2; int som_of_digits = 0; int number_of_tracks = 0; while(*file_ptr != 0) { TagLib_File * file = taglib_file_new(*file_ptr); const TagLib_AudioProperties * audio = taglib_file_audioproperties(file); int length = taglib_audioproperties_length(audio); //printf("Song length: %i -- offset %i \n", length, total_ofset * 75); int chars_printed = sprintf(str_ptr, "%i ", total_ofset * 75); str_ptr = str_ptr + chars_printed; som_of_digits = (SumOfDigits(total_ofset) + som_of_digits) % 255; total_time += length; total_ofset += length; taglib_file_free(file); file_ptr++; number_of_tracks++; } FreeFileList(files); /*printf("Som of digits is: %i\n", som_of_digits); printf("Total time: %i\n", total_time); printf("Number of tracks: %i\n", number_of_tracks); printf("offsets: %s\n", offsets); printf("Total disc length: %i\n", total_time + 2);*/ int total_string_length = sprintf(temp_arr, "%02x%04x%02x %i %s%i\n", som_of_digits, total_time, number_of_tracks, number_of_tracks, offsets, total_time + 2) + 1; char * ret = (char *) malloc (sizeof(char) * total_string_length); strcpy(ret, temp_arr); return ret; }
//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); }
// 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; }
/* 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; }
void get_value(FmFileInfo *fi, GValue *value){ char* filename; char* genre; TagLib_File *TL_file; TagLib_Tag *TL_tag; filename = fm_path_to_str( fm_file_info_get_path(fi) ); TL_file = taglib_file_new( filename ); free( filename ); if( TL_file != NULL ) { if(taglib_file_is_valid(TL_file)){ TL_tag = taglib_file_tag( TL_file ); genre = taglib_tag_genre( TL_tag ); g_value_set_string( value, genre ); taglib_tag_free_strings(); taglib_file_free( TL_file ); } } };
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; }
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; }
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; }
int main(int argc, char *argv[]) { float *data; float *out; char *mp3_file; unsigned int srate; unsigned int len = 0; unsigned int num_octaves; unsigned int out_len; char *cmd; TagLib_File *f; if(argc <= 1) { printf("USAGE: %s <MP3 File>\n", argv[0]); return 0; } mp3_file = argv[1]; f = taglib_file_new(mp3_file); if(f == NULL) { printf("Cannot open %s\n",mp3_file); exit(-1); } srate = taglib_audioproperties_samplerate(taglib_file_audioproperties(f)); taglib_file_free(f); if(srate == 0) { printf("Sample rate in tag == 0, cannot proceed\n"); exit(-1); } printf("Sampling rate = %d\n",srate); cmd = calloc(512, sizeof(char)); sprintf(cmd, "spectgen -r -o ./tmp.raw \"%s\"",mp3_file); if(system(cmd) != 0) { printf("spectgen failed!\n"); printf("Cmd = %s\n",cmd); exit(-1); } free(cmd); cmd = NULL; if(get_file(&data, &len, "./tmp.raw")) { printf("Getting file failed!\n"); printf("Len = %d\n",len); exit(-1); } if(len < srate) { printf("File too short!\n"); exit(-1); } printf("Number of samples = %d\n", len); printf("Doing gabor!\n"); if(cwt_gabor(&num_octaves, &out_len, &out, data, len, srate, 1.0/16.0)) { printf("Cwt failed!\n"); exit(-1); } free(data); unlink("./tmp.raw"); #if 0 { int i,j; for(i = 0; i < out_len; i++) { for(j = 0; j < 12 * (num_octaves - 1); j++) { printf("%.3f ", out[(j * (num_octaves - 1)) + i]); } printf("\n"); } } exit(-1); #endif pgm("test.pgm", out, out_len, 12 * (num_octaves - 2), BACKGROUND_WHITE, GREYSCALE, COL_NORMALIZATION); free(out); 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) ); }
// Hier geht die Post ab void import_file (const gchar *import_path) { TagLib_File *file; TagLib_Tag *tag; gchar *export_path; gchar *filename; gchar *artist; gchar *album; // Prüfen ob die Datei gültig ist file = taglib_file_new (import_path); if (file == NULL) { return; } // Prüfen ob wir Tags haben tag = taglib_file_tag (file); if (tag == NULL) { return; } // Falls Tags unvollständig sind -> Nicht importieren if (!check_tags (tag)) { gchar *text; text = g_strdup_printf ("Nicht importieren! (Tags unvollstaendig) -> %s", import_path); settings_import_messages_add (text); return; } // Dateiname holen filename = g_path_get_basename (import_path); // Die einzelnen Tags holen artist = taglib_tag_artist(tag); album = taglib_tag_album (tag); // Artist & Album Ordner erstellen create_artist_dir (artist); create_album_dir (album, artist); // Export Pfad bestimmen export_path = get_song_path (tag, get_file_extension (filename)); // Prüfen, ob schon vorhanden if (exist_target (export_path, import_path)) { gchar *text; text = g_strdup_printf ("Überspringe: %s", filename); settings_import_messages_add (text); return; } // Datei kopieren if (!copy_file (import_path, export_path)) { gchar *text; text = g_strdup_printf ("Import fehlgeschlagen! -> %s", filename); settings_import_messages_add (text); return; } // File in Datenbank eintragen if (!register_file (export_path)) { gchar *text; text = g_strdup_printf ("Datei '%s' konnte nicht in der Datenbank registriert werden!", filename); settings_import_messages_add (text); return; } // Speicher wieder freigeben taglib_tag_free_strings (); taglib_file_free (file); }
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); }
int playback(FILE * streamfd, int pipefd) { killed = 0; signal(SIGUSR1, sighand); #ifndef EXTERN_ONLY if(!haskey(& rc, "extern")) { const char * freetrack = NULL; struct stream data; struct mad_decoder dec; #ifdef LIBAO static int ao_initialized = 0; if(!ao_initialized) { ao_initialize(); ao_initialized = !0; } #else unsigned arg; int fd; #endif memset(& data, 0, sizeof(struct stream)); /* Check if there's a stream timeout configured and set it up for timed reads later. */ data.timeout = -1; if(haskey(& rc, "stream-timeout")) { const char * timeout = value(& rc, "stream-timeout"); data.timeout = atoi(timeout); if(data.timeout <= 0) { if(data.timeout < 0) fputs("Invalid stream-timeout.\n", stderr); data.timeout = -1; } } data.streamfd = streamfd; data.parent = getppid(); data.pipefd = pipefd; fcntl(pipefd, F_SETFL, O_NONBLOCK); #ifdef LIBAO data.driver_id = ao_default_driver_id(); if(-1 == data.driver_id) { fputs("Unable to find any usable output device!\n", stderr); return 0; } data.fmt.bits = 16; data.fmt.rate = 44100; data.fmt.channels = 2; data.fmt.byte_format = AO_FMT_NATIVE; data.device = ao_open_live(data.driver_id,&data.fmt,NULL); if(NULL == data.device) { fprintf(stderr, "Unable to open device. %s.\n", strerror(errno)); return 0; } #else data.audiofd = fd = open(value(& rc, "device"), O_WRONLY); if(-1 == data.audiofd) { fprintf( stderr, "Couldn't open %s! %s.\n", value(& rc, "device"), strerror(errno) ); return 0; } arg = 16; /* 16 bits */ ioctl(data.audiofd, SOUND_PCM_WRITE_BITS, & arg); #endif freetrack = value(& track, "freeTrackURL"); if(freetrack && strlen(freetrack) > 0 && haskey(& rc, "download")) { char * dnam; int rv; data.finpath = strdup(meta(value(& rc, "download"), M_RELAXPATH, & track)); assert(data.finpath != NULL); data.tmppath = strjoin("", data.finpath, ".streaming", NULL); assert(data.tmppath != NULL); dnam = strdup(data.tmppath); rv = dnam ? mkpath(dirname(dnam)) : -1; free(dnam); if(access(data.tmppath, R_OK) == -1) { data.dump = (rv == 0) ? fopen(data.tmppath, "w") : NULL; if(!data.dump) fprintf(stderr, "Can't write download to %s.\n", data.tmppath); } else { data.dump = NULL; } } mad_decoder_init(& dec, & data, input, NULL, NULL, output, NULL, NULL); mad_decoder_run(& dec, MAD_DECODER_MODE_SYNC); #ifndef LIBAO close(fd); #endif mad_decoder_finish(& dec); if(data.dump) { fclose(data.dump); if(killed) { unlink(data.tmppath); } else { int rv; #ifdef TAGLIB TagLib_File *tagme = taglib_file_new(data.tmppath); if(tagme != NULL) { TagLib_Tag *tag = taglib_file_tag(tagme); taglib_tag_set_title(tag, value(&track, "title")); taglib_tag_set_artist(tag, value(&track, "creator")); taglib_tag_set_album(tag, value(&track, "album")); taglib_file_save(tagme); taglib_file_free(tagme); } #endif if(haskey(& rc, "pp-cmd")) { const char *ppcmd = value(& rc, "pp-cmd"); size_t ppcmdlen = strlen(ppcmd); char *path = shellescape(data.tmppath); assert(path != NULL); size_t pathlen = strlen(path); char *command = malloc(ppcmdlen + pathlen + 2); assert(command != NULL); memcpy(command, ppcmd, ppcmdlen); command[ppcmdlen] = ' '; memcpy(command + ppcmdlen + 1, path, pathlen); command[ppcmdlen + 1 + pathlen] = 0; run(command); free(path); free(command); } rv = rename(data.tmppath, data.finpath); if (rv == -1) fprintf(stderr, "Can't rename %s to %s\n", data.tmppath, data.finpath); } free(data.tmppath); free(data.finpath); } } else #endif { pid_t ppid = getppid(), cpid = 0; const char * cmd = meta(value(& rc, "extern"), M_SHELLESC, & track); FILE * ext = openpipe(cmd, & cpid); unsigned char * buf; if(!ext) { fprintf(stderr, "Failed to execute external player (%s). %s.\n", cmd, strerror(errno)); return 0; } if(!(buf = calloc(BUFSIZE + 1, sizeof(unsigned char)))) { fputs("Couldn't allocate enough memory for input buffer.\n", stderr); fclose(ext); return 0; } while(!feof(streamfd)) { signed nbyte = fread(buf, sizeof(unsigned char), BUFSIZE, streamfd); if(nbyte > 0) { fwrite(buf, sizeof(unsigned char), nbyte, ext); fflush(ext); } if(kill(ppid, 0) == -1 && errno == ESRCH) break; if(killed) break; } free(buf); fclose(ext); waitpid(cpid, NULL, 0); } return !0; }
/* 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; }