Exemple #1
0
static gboolean
get_disc_ids (const gchar *device, gchar **disc_id,
              gchar **cddb_id, track_t *tracks)
{
	DiscId *disc = discid_new ();
	g_return_val_if_fail (disc, FALSE);

	if (discid_read_sparse (disc, device, 0) == 0) {
		xmms_log_error ("Could not read disc: %s", discid_get_error_msg (disc));
		discid_free (disc);
		return FALSE;
	}

	*disc_id = g_strdup (discid_get_id (disc));
	if (tracks) {
		*tracks = discid_get_last_track_num (disc);
	}

	if (cddb_id) {
		*cddb_id = g_strdup (discid_get_freedb_id (disc));
	}

	discid_free (disc);

	return TRUE;
}
Exemple #2
0
int main(int argc, char *argv[]) {
	int i, first_track, last_track;
	char *device = NULL;
	char time_str[14];
	int sectors;
	DiscId *disc;

	disc = discid_new();

	/* If we have an argument, use it as the device name */
	if (argc > 1) {
		device = argv[1];
	} else {
		/* this will use discid_get_default_device() internally */
		device = NULL;
	}

	if (discid_read_sparse(disc, device, 0) == 0) {
		fprintf(stderr, "Error: %s\n", discid_get_error_msg(disc));
		discid_free(disc);
		return 1;
	}

	printf("DiscID        : %s\n", discid_get_id(disc));
	printf("FreeDB DiscID : %s\n", discid_get_freedb_id(disc));

	first_track = discid_get_first_track_num(disc);
	last_track = discid_get_last_track_num(disc);
	printf("First track   : %d\n", first_track);
	printf("Last track    : %d\n", last_track);

	sectors = discid_get_sectors(disc);
	sectors_to_time(sectors, ROUND_SECONDS, time_str, sizeof time_str);
	printf("Length        : %d sectors (%s)\n", sectors, time_str);

	for ( i = first_track; i <= last_track; i++ ) {
		sectors = discid_get_track_length(disc, i);
		sectors_to_time(sectors, ROUND_SECONDS,
				time_str, sizeof time_str);
		printf("Track %-2d      : %8d %8d (%s)\n",
				i, discid_get_track_offset(disc, i),
				sectors, time_str);
	}

	printf("Submit via    : %s\n", discid_get_submission_url(disc));

	discid_free(disc);

	return 0;
}
Exemple #3
0
/**
 * call-seq:
 *  MusicBrainz::DiscID.new(device=nil) -> obj
 *
 * Construct a new DiscID object.
 * 
 * As an optional argument the name of the device to read the ID from
 * may be given. If you don't specify a device here you can later read
 * the ID with the read method.
 *
 * Raises:: ArgumentError, TypeError, Exception
 */
VALUE mb_discid_new(int argc, VALUE *argv, VALUE class)
{
	DiscId *disc = discid_new();
	VALUE tdata = Data_Wrap_Struct(class, 0, discid_free, disc);
	VALUE device = Qnil;
	rb_obj_call_init(tdata, 0, 0);
	rb_iv_set(tdata, "@read", Qfalse);
	
	/* Check the number of arguments */
	rb_scan_args(argc, argv, "01", &device);
	
	if (device != Qnil)
		rb_funcall(tdata, rb_intern("read"), 1, device);
	
	return tdata;
}

/**
/*
 * Virtual methods
 */
static GList *
mb4_list_albums (SjMetadata *metadata, char **url, GError **error)
{
  SjMetadataMusicbrainz4Private *priv;
  GList *albums = NULL;
  Mb4ReleaseList releases;
  Mb4Release release;
  const char *discid = NULL;
  char buffer[1024];
  int i;
  g_return_val_if_fail (SJ_IS_METADATA_MUSICBRAINZ4 (metadata), NULL);

  priv = GET_PRIVATE (metadata);

  if (sj_metadata_helper_check_media (priv->cdrom, error) == FALSE) {
    return NULL;
  }

  priv->disc = discid_new ();
  if (priv->disc == NULL)
    return NULL;
  if (discid_read (priv->disc, priv->cdrom) == 0)
    return NULL;

  if (url != NULL)
    *url = g_strdup (discid_get_submission_url (priv->disc));

  if (g_getenv("MUSICBRAINZ_FORCE_DISC_ID")) {
    discid = g_getenv("MUSICBRAINZ_FORCE_DISC_ID");
  } else {
    discid = discid_get_id (priv->disc);
  }

  releases = mb4_query_lookup_discid(priv->mb, discid);

  if (releases == NULL) {
    return NULL;
  }

  if (mb4_release_list_size (releases) == 0) {
    return NULL;
  }

  for (i = 0; i < mb4_release_list_size (releases); i++) {
    AlbumDetails *album;

    release = mb4_release_list_item (releases, i);
    if (release) {
      char *releaseid = NULL;
      Mb4Release full_release;

      releaseid = NULL;
      GET(releaseid, mb4_release_get_id, release);

      full_release = mb4_query_lookup_release (priv->mb, releaseid);
      g_free (releaseid);
      if (full_release) {
        Mb4MediumList media;
        Mb4Metadata metadata = NULL;
        Mb4ReleaseGroup group;
        unsigned int j;

        group = mb4_release_get_releasegroup (full_release);
        if (group) {
          /* The release-group information we can extract from the
           * lookup_release query doesn't have the url relations for the
           * release-group, so run a separate query to get these urls
           */
          char *releasegroupid = NULL;
          char *params_names[] = { "inc" };
          char *params_values[] = { "artists url-rels" };

          GET (releasegroupid, mb4_releasegroup_get_id, group);
          metadata = mb4_query_query (priv->mb, "release-group", releasegroupid, "",
                                      1, params_names, params_values);
          g_free (releasegroupid);
        }

        if (metadata && mb4_metadata_get_releasegroup (metadata))
          group = mb4_metadata_get_releasegroup (metadata);

        media = mb4_release_media_matching_discid (full_release, discid);
        for (j = 0; j < mb4_medium_list_size (media); j++) {
          Mb4Medium medium;
          medium = mb4_medium_list_item (media, j);
          if (medium) {
            album = make_album_from_release (group, full_release, medium);
            album->metadata_source = SOURCE_MUSICBRAINZ;
            albums = g_list_append (albums, album);
          }
        }
        mb4_metadata_delete (metadata);
        mb4_medium_list_delete (media);
        mb4_release_delete (full_release);
      }
    }
  }
  mb4_release_list_delete (releases);
  return albums;
}
Exemple #5
0
int main(int argc, char *argv[]) {
	DiscId *d;
	char *tmp, *expected;
	int ret;
	int ntests = 0, nok = 0;
	int offsets[] = {
		303602,
		150, 9700, 25887, 39297, 53795, 63735, 77517, 94877, 107270,
		123552, 135522, 148422, 161197, 174790, 192022, 205545,
		218010, 228700, 239590, 255470, 266932, 288750,
	};

	d = discid_new();

	/* Setting TOC */
	printf("Testing discid_put ... ");
	ret = discid_put(d, 1, 22, offsets);
	if ( ret ) {
		printf("OK\n");
		nok++;
	}
	else
		printf("Failed\n");
	ntests++;

	/* MusicBrainz DiscID */
	printf("Testing discid_get_id ... ");
	tmp = discid_get_id(d);
	expected = "xUp1F2NkfP8s8jaeFn_Av3jNEI4-";
	if ( strcmp(tmp, expected) == 0 ) {
		printf("OK\n");
		nok++;
	}
	else {
		printf("Failed\n");
		printf("  Expected : %s\n", expected);
		printf("  Actual   : %s\n", tmp);
	}
	ntests++;

	/* FreeDB DiscID */
	printf("Testing discid_get_freedb_id ... ");
	tmp = discid_get_freedb_id(d);
	expected = "370fce16";
	if ( strcmp(tmp, expected) == 0 ) {
		printf("OK\n");
		nok++;
	}
	else {
		printf("Failed\n");
		printf("  Expected : %s\n", expected);
		printf("  Actual   : %s\n", tmp);
	}
	ntests++;

	/* MusicBrainz web submit URL */
	printf("Testing discid_get_submission_url ... ");
	tmp = discid_get_submission_url(d);
	expected = "http://mm.musicbrainz.org/bare/cdlookup.html?id=xUp1F2NkfP8s8jaeFn_Av3jNEI4-&tracks=22&toc=1+22+303602+150+9700+25887+39297+53795+63735+77517+94877+107270+123552+135522+148422+161197+174790+192022+205545+218010+228700+239590+255470+266932+288750";
	if ( strcmp(tmp, expected) == 0 ) {
		printf("OK\n");
		nok++;
	}
	else {
		printf("Failed\n");
		printf("  Expected : %s\n", expected);
		printf("  Actual   : %s\n", tmp);
	}
	ntests++;

	printf("\n%d tests, %d passed, %d failed\n", ntests, nok, ntests - nok);
	
	discid_free(d);
	
	return ntests != nok;
}
Exemple #6
0
int main(int argc, char *argv[]) {
	DiscId *d;
	char *features[DISCID_FEATURE_LENGTH];
	char *feature;
	int i, found_features, invalid;
	int result;

	announce("discid_get_version_string");
	evaluate(strlen(discid_get_version_string()) > 0);

	announce("discid_get_feature_list");
	discid_get_feature_list(features);
	found_features = 0;
	invalid = 0;
	for (i = 0; i < DISCID_FEATURE_LENGTH; i++) {
		feature = features[i];
		if (feature) {
			found_features++;
			if (!feature_consistent(feature)) {
				invalid++;
			}
		}
	}
	evaluate(!invalid && found_features ==
			discid_has_feature(DISCID_FEATURE_READ)
			+ discid_has_feature(DISCID_FEATURE_MCN)
			+ discid_has_feature(DISCID_FEATURE_ISRC));

	announce("discid_get_default_device");
	/* this doesn't test much, but shouldn't fail completely
	 * TODO: make sure there is always something > 0 returned
	 */
	evaluate(strlen(discid_get_default_device()) >= 0);

	/* TODO
	 * test access with/without initialization doesn't fail
	 */

	announce("discid_new");
	d = discid_new();
	evaluate(d != NULL);

	announce("giving invalid device");
	result = discid_read(d, "invalid_device_name");
	evaluate(!result);
	announce("discid_get_error_msg");
	/* depending on result from invalid read
	 * If that fails, it still is only one failure.*/
	if (result) {
		evaluate(strlen(discid_get_error_msg(d)) == 0);
	} else {
		evaluate(strlen(discid_get_error_msg(d)) > 0);
	}

	/*
	announce("empty values");
	evaluate(discid_get_id(d) == NULL);
	*/
	/* TODO
	 * This needs implementation.
	 * Right now we get segmentation faults in debug builds (assert)
	 * and have to test for NULL in release builds.
	announce("empty values");
	evaluate(strlen(discid_get_id(d)) == 0
			&& strlen(discid_get_freedb_id(d)) == 0
			&& strlen(discid_get_submission_url(d)) == 0
			&& strlen(discid_get_mcn(d)) == 0
			&& discid_get_first_track_num(d) == 0
			&& discid_get_last_track_num(d) == 0
			&& discid_get_sectors(d) == 0);
			*/

	announce("discid_free");
	discid_free(d);
	evaluate(1); /* only segfaults etc. would "show" */
	
	return !test_result();
}