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;
}
Exemple #2
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;
}
Exemple #3
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);
   }
}
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;
}
Exemple #5
0
/**
 * Save a file back to disc
 *
 * This is a wrapper around a file type's save() method, which
 * also handles file type specific actions.
 *
 * @param   file    pointer to the taggit_file structure describing
 *                  the file in question
 *
 * @return      1 if the save() method returned true; 0 otherwise
 * @sideeffects none
 */
int
taggit_file_save(struct taggit_file *file)
{
    bool rc;
    int mask;

    switch (file->type) {
    case FT_MPEG:
        TagLib::MPEG::File *f;

        f = reinterpret_cast<TagLib::MPEG::File *>(file->data);
        mask = setup_get_write_mask(FT_MPEG);
#ifdef TAGGIT_DEBUG
        fprintf(stderr, "writemask (mp3): %d\n", mask);
#endif
        rc = f->save(mask, 1);
        break;
    default:
        rc = taglib_file_save(file->data);
    }

    return rc ? 1 : 0;
}
Exemple #6
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;
}
Exemple #7
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;
}
Exemple #8
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;
}