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;
}
Beispiel #2
0
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 );
		}
	}
};
Beispiel #4
0
/**
 * 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;
}
static void
gimmix_tag_editor_close (GtkWidget *widget, gpointer data)
{
	taglib_tag_free_strings ();
    if (file)
    	taglib_file_free (file);
    gtk_widget_hide (tag_editor_window);
    
    return;
}
Beispiel #6
0
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);
}
Beispiel #7
0
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;
}
Beispiel #8
0
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
gimmix_tag_editor_close (GtkWidget *widget, gpointer data)
{
	#ifdef HAVE_TAGEDITOR
	taglib_tag_free_strings ();
	if (file)
    	{
    		taglib_file_free (file);
    	}
	#endif
	gtk_widget_hide (tag_editor_window);

	return;
}
Beispiel #10
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;
}
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;
}
Beispiel #13
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);
   }
}
Beispiel #14
0
Datei: db.c Projekt: mattn/cpod
/* 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;
}
Beispiel #15
0
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;
}
Beispiel #16
0
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;
}
Beispiel #17
0
//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;
}
Beispiel #19
0
/* 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 );
		}
	}
};
Beispiel #21
0
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);
}
Beispiel #22
0
/**
    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;
}
Beispiel #23
0
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;
}
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;
}
Beispiel #25
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;
}
Beispiel #26
0
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;
}
Beispiel #27
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) );
}
Beispiel #28
0
/**
 * 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;
}
Beispiel #29
0
/**
 * Free the allocated information from a taggit_file structure
 *
 * @param   file    pointer to the structure to destroy
 *
 * @return      void
 * @sideeffects none
 */
void
taggit_file_destroy(struct taggit_file *file)
{
    taglib_file_free(file->data);
    file->type = FT_INVALID;
}
Beispiel #30
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;
}