Exemplo n.º 1
0
void ices_metadata_set(const char* artist, const char* title) {
	ices_util_free(Artist);
	Artist = NULL;
	ices_util_free(Title);
	Title = NULL;

	if (artist && *artist)
		Artist = ices_util_strdup(artist);
	if (title && *title)
		Title = ices_util_strdup(title);
}
Exemplo n.º 2
0
static void metadata_update(int delay) {
	ices_stream_t* stream;
	shout_metadata_t* metadata;
	char song[1024];
	char* playlist_metadata;
	char* value;
	int rc;

	if (delay)
		usleep(delay);

	if (!(playlist_metadata = ices_playlist_get_metadata())) {
		if (Title) {
			if (Artist)
				snprintf(song, sizeof(song), "%s - %s", Artist, Title);
			else
				snprintf(song, sizeof(song), "%s", Title);
		} else
			snprintf(song, sizeof(song), "%s", Filename);

		value = song;
	} else
		value = playlist_metadata;

	if (!(metadata = shout_metadata_new())) {
		ices_log_error("Error allocating metadata structure");
		ices_util_free(playlist_metadata);
		return;
	}

	if (shout_metadata_add(metadata, "song", value) != SHOUTERR_SUCCESS) {
		ices_log_error_output("Error adding info to metadata structure");
		ices_util_free(playlist_metadata);
		shout_metadata_free(metadata);
		return;
	}

	for (stream = ices_config.streams; stream; stream = stream->next) {
		rc = shout_set_metadata(stream->conn, metadata);

		if (rc != SHOUTERR_SUCCESS)
			ices_log_error_output("Updating metadata on %s failed.", stream->mount);
		else
			ices_log_debug("Updated metadata on %s to: %s", stream->mount, value);
	}

	ices_util_free(playlist_metadata);
	shout_metadata_free(metadata);
}
Exemplo n.º 3
0
int ices_playlist_perl_initialize(playlist_module_t* pm) {
	char *str;
	int ret = -1;

	pm->get_next = playlist_perl_get_next;
	pm->get_metadata = playlist_perl_get_metadata;
	pm->get_lineno = playlist_perl_get_lineno;
	pm->shutdown = playlist_perl_shutdown;
	pm->reload = playlist_perl_reload;

	if (pl_perl_init_perl() < 0)
		return -1;

	if (!pl_init_hook)
		return 1;

	if ((str = pl_perl_eval(pl_init_hook))) {
		ret = atoi(str);
		ices_util_free(str);
	}

	if (ret <= 0)
		ices_log_error("Execution of 'ices_init' failed");

	return ret;
}
Exemplo n.º 4
0
/* Function to free() all allocated memory when ices shuts down. */
static void
ices_free_all (ices_config_t *ices_config)
{
  ices_stream_t *stream, *next;

  ices_util_free (ices_config->configfile);
  ices_util_free (ices_config->base_directory);

  ices_util_free (ices_config->pm.playlist_file);
  ices_util_free (ices_config->pm.module);

  for (stream = ices_config->streams; stream; stream = next)
  {
    next = stream->next;

    ices_setup_free_stream (stream);
    ices_util_free (stream);
  }
}
Exemplo n.º 5
0
void ices_metadata_set_file(const char* filename) {
	char buf[1024];

	ices_util_free(Filename);
	Filename = NULL;

	if (filename && *filename) {
		metadata_clean_filename(filename, buf, sizeof(buf));
		Filename = ices_util_strdup(buf);
	}
}
Exemplo n.º 6
0
static int playlist_perl_get_lineno(void) {
	char *str;
	int ret = 0;

	if (pl_get_lineno_hook && (str = pl_perl_eval(pl_get_lineno_hook))) {
		ret = atoi(str); /* allocated in perl.c */
		ices_util_free(str);
	}

	return ret;
}
Exemplo n.º 7
0
/* Frees ices_stream_t data (but not the object itself) */
static void
ices_setup_free_stream (ices_stream_t* stream)
{
  ices_util_free (stream->host);
  ices_util_free (stream->password);

  ices_util_free (stream->mount);
  ices_util_free (stream->dumpfile);

  ices_util_free (stream->name);
  ices_util_free (stream->genre);
  ices_util_free (stream->description);
  ices_util_free (stream->url);
}
Exemplo n.º 8
0
static void
metadata_update (input_stream_t* source, int delay)
{
  ices_stream_t* stream;
  char song[1024];
  char* playlist_metadata;
  char* metadata;
  int rc;

  if (delay)
    usleep (delay);

  if (! (playlist_metadata = ices_playlist_get_metadata ())) {
    if (Title) {
      if (Artist)
	snprintf (song, sizeof (song), "%s - %s", Artist, Title);
      else
	snprintf (song, sizeof (song), "%s", Title);
    } else
      metadata_clean_filename (source->path, song, sizeof (song));
    
    metadata = song;
  } else
    metadata = playlist_metadata;

  for (stream = ices_config.streams; stream; stream = stream->next) {
    rc = shout_update_metadata (&stream->conn, metadata);
	
    if (rc != 1)
      ices_log_error ("Updating metadata on %s failed.", stream->mount);
    else
      ices_log_debug ("Updated metadata on %s to: %s", stream->mount, metadata);
  }

  ices_util_free (playlist_metadata);
}
Exemplo n.º 9
0
/* Shutdown the python interpreter */
static void
python_shutdown (void)
{
    Py_Finalize ();
    ices_util_free (python_path);
}
Exemplo n.º 10
0
void
ices_id3v2_parse (input_stream_t* source)
{
  unsigned char buf[1024];
  id3v2_tag tag;
  size_t remaining;
  ssize_t rv;

  if (source->read (source, buf, 10) != 10) {
    ices_log ("Error reading ID3v2");

    return;
  }

  tag.artist = tag.title = NULL;
  tag.pos = 0;
  tag.major_version = *(buf + 3);
  tag.minor_version = *(buf + 4);
  tag.flags = *(buf + 5);
  tag.len = id3v2_decode_synchsafe (buf + 6);
  ices_log_debug ("ID3v2: version %d.%d. Tag size is %d bytes.",
                  tag.major_version, tag.minor_version, tag.len);
  if (tag.major_version > 4) {
    ices_log_debug ("ID3v2: Version greater than maximum supported (4), skipping");
    id3v2_skip_data (source, &tag, tag.len);

    return;
  }

  if ((tag.major_version > 2) &&
      (tag.flags & ID3V2_FLAG_EXTHDR) && id3v2_read_exthdr (source, &tag) < 0) {
    ices_log ("Error reading ID3v2 extended header");

    return;
  }

  remaining = tag.len - tag.pos;
  if ((tag.major_version > 3) && (tag.flags & ID3V2_FLAG_FOOTER))
    remaining -= 10;

  while (remaining > ID3V2_FRAME_LEN(&tag) && (tag.artist == NULL || tag.title == NULL)) {
    if ((rv = id3v2_read_frame (source, &tag)) < 0) {
      ices_log ("Error reading ID3v2 frames, skipping to end of ID3v2 tag");
      break;
    }
    /* found padding */
    if (rv == 0)
      break;

    remaining -= rv;
  }

  /* allow fallback to ID3v1 */
  if (tag.artist || tag.title)
    ices_metadata_set (tag.artist, tag.title);
  ices_util_free (tag.artist);
  ices_util_free (tag.title);

  remaining = tag.len - tag.pos;
  if (remaining)
    id3v2_skip_data (source, &tag, remaining);
}